Selaa lähdekoodia

Merge branch 'counter-fixes'

* counter-fixes:
  * Graceful cookie counter overflow
  * Reset another bot's count when it quits IRC
  * Persist cookie counter through restart
Bryan Drewery 16 vuotta sitten
vanhempi
commit
776c79f98d
4 muutettua tiedostoa jossa 18 lisäystä ja 3 poistoa
  1. 6 0
      src/misc.c
  2. 2 0
      src/mod/irc.mod/chan.c
  3. 9 3
      src/mod/irc.mod/irc.c
  4. 1 0
      src/mod/irc.mod/irc.h

+ 6 - 0
src/misc.c

@@ -679,6 +679,10 @@ readsocks(const char *fname)
       burst = atoi(str.c_str());
     else if (type == STR("+flood_count"))
       flood_count = atoi(str.c_str());
+    else if (type == STR("+my_cookie_counter")) {
+      my_cookie_counter = strtol(str.c_str(), NULL, 10);
+      my_cookie_counter += 100; // Increase to avoid race conditions
+    }
     else if (type == STR("+ip4"))
       ip4 = str.dup();
     else if (type == STR("+ip6"))
@@ -785,6 +789,8 @@ restart(int idx)
       stream << buf.printf(STR("+burst %d\n"), burst);
     if (flood_count)
       stream << buf.printf(STR("+flood_count %d\n"), flood_count);
+    if (my_cookie_counter)
+      stream << buf.printf(STR("+my_cookie_counter %lu\n"), my_cookie_counter);
     stream << buf.printf(STR("+server_online %li\n"), server_online);
   }
   stream << buf.printf(STR("+online_since %li\n"), online_since);

+ 2 - 0
src/mod/irc.mod/chan.c

@@ -3066,6 +3066,8 @@ static int gotquit(char *from, char *msg)
       member_getuser(m);
       u = m->user;
       if (u) {
+        if (u->bot)
+          counter_clear(u->handle);
         set_handle_laston(chan->dname, u, now); /* If you remove this, the bot will crash when the user record in question
 						   is removed/modified during the tcl binds below, and the users was on more
 						   than one monitored channel */

+ 9 - 3
src/mod/irc.mod/irc.c

@@ -90,7 +90,7 @@ static bool prevent_mixing = 1;  /* To prevent mixing old/new modes */
 bool include_lk = 1;      /* For correct calculation
                                  * in real_add_mode. */
 bd::HashTable<bd::String, unsigned long> bot_counters;
-static unsigned long my_counter = 0;
+unsigned long my_cookie_counter = 0;
 
 static bd::Queue<bd::String> chained_who;
 static int chained_who_idx;
@@ -401,8 +401,10 @@ void makecookie(char *out, size_t len, const char *chname, const memberlist* opp
   char cookie_clear[101] = "";
 
   //Increase my counter
-  ++my_counter;
-  simple_snprintf2(cookie_clear, sizeof(cookie_clear), STR("%s%s%D"), randstring, &ts[3], my_counter);
+  ++my_cookie_counter;
+  if (my_cookie_counter > (unsigned long)(-500))
+    my_cookie_counter = 0;
+  simple_snprintf2(cookie_clear, sizeof(cookie_clear), STR("%s%s%D"), randstring, &ts[3], my_cookie_counter);
 
   char key[150] = "";
   cookie_key(key, sizeof(key), randstring, opper, chname);
@@ -508,6 +510,10 @@ if (indexHint == 0) {
     if (counter <= last_counter)
       return BC_COUNTER;
 
+    // graceful overflow
+    if (counter > (unsigned long)(-1000))
+      counter = 0;
+
     //Update counter for the opper
     bot_counters[handle] = counter;
   }

+ 1 - 0
src/mod/irc.mod/irc.h

@@ -149,5 +149,6 @@ char *getnick(const char *, struct chanset_t *);
 extern int		max_bans, max_exempts, max_invites, max_modes;
 extern bool		use_354, include_lk;
 extern unsigned int	modesperline;
+extern unsigned long my_cookie_counter;
 #endif				/* _EGG_MOD_IRC_IRC_H */