Created
March 12, 2020 12:03
-
-
Save Estella/aa3284f6ade07201bb44cfb8f530664e to your computer and use it in GitHub Desktop.
shuffle_roles.diff for wraith v1.4.8-5375-g9d8fbc9b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- devel/wraith_20200311/src/mod/irc.mod/irc.cc 2020-03-11 18:09:31.812212890 -0600 | |
+++ rainbow_20200311/src/mod/irc.mod/irc.cc 2020-03-12 05:48:10.294738359 -0600 | |
@@ -1764,10 +1837,16 @@ static void bot_release_nick (char *botn | |
release_nick(par); | |
} | |
+static time_t lastshuffle = 0; | |
+static u_int32_t prng_x, prng_y, prng_z, prng_w; | |
+static u_int32_t xyz_shuffle(size_t n) { u_int32_t t = prng_x; t ^= t << 11; t ^= t >> 8; prng_x = prng_y; prng_y = prng_z; prng_z = prng_w; prng_w ^= prng_w >> 19; prng_w ^= t; return (prng_w % n); } | |
+ | |
static void rebalance_roles_chan(struct chanset_t* chan) | |
{ | |
+ | |
+ time_t temp_x; temp_x = time(NULL); temp_x = (temp_x & 0xFFFFFF00); | |
/* Compare to tand_updates which ensures a trigger on unlink/link. */ | |
- if (chan->role_rebalance_cookie == tand_updates) { | |
+ if ((chan->role_rebalance_cookie == tand_updates) && (temp_x == lastshuffle)) { | |
return; | |
} | |
@@ -1810,9 +1889,20 @@ static void rebalance_roles_chan(struct | |
bots << m->user->handle; | |
} | |
+ | |
botcount = bots.length(); | |
if (botcount == 0) | |
return; | |
+ | |
+ prng_x = temp_x; prng_y = 0x243f6a88; prng_z = 0x93c467e3; prng_w = 0x9e3779b9; lastshuffle = temp_x; | |
+ | |
+ for (size_t i = 0; i < botcount; i++) { | |
+ const size_t j = xyz_shuffle(botcount); | |
+ bd::String randombot = bots[j]; | |
+ bots[j] = bots[i]; | |
+ bots[i] = randombot; | |
+ } | |
+ | |
bot_bits = (int*)calloc(botcount, sizeof(bot_bits[0])); | |
for (roleidx = 0; role_counts[roleidx].name; roleidx++) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment