Explorar el Código

Merge branch 'improve_bitch'

* improve_bitch:
  * Speedup mop/mdop kicks
  * Speedup cookie flushing
  * Better +bitch/+botbitch/+closed handling when in floodless mode.
  * Fix +botbitch being very slow and inefficient
  * Cleanup priority_do code
Bryan Drewery hace 16 años
padre
commit
38a82f46f3
Se han modificado 3 ficheros con 55 adiciones y 88 borrados
  1. 2 0
      doc/UPDATES
  2. 50 85
      src/mod/irc.mod/chan.c
  3. 3 3
      src/mod/irc.mod/mode.c

+ 2 - 0
doc/UPDATES

@@ -64,6 +64,8 @@
   * Fix restart causing bot to change nick (this was a regression in jupenick)
   * Fix cmd_slowjoin not working on backup bots correctly.
   * Fix a crash from long hubnicks.
+  * Fix +botbitch being very slow and inefficient
+  * Better +bitch/+botbitch/+closed handling when in floodless mode.
 * Misc changes
   * Added pseudo-channel 'default' which can be modified with 'chanset' and 'chaninfo'.
     This is used to modify what the default channel options will be for new channels.

+ 50 - 85
src/mod/irc.mod/chan.c

@@ -348,8 +348,8 @@ void priority_do(struct chanset_t * chan, bool opsonly, int action)
     }
 
     if (m->user && m->user->bot && (m->user->flags & USER_OP)) {
-      ops++;
-      if (!strcmp(m->nick, botname))
+      ++ops;
+      if (match_my_nick(m->nick))
         bpos = (ops - 1);
 
     } else if (!opsonly || chan_hasop(m)) {
@@ -357,101 +357,66 @@ void priority_do(struct chanset_t * chan, bool opsonly, int action)
         if (m->user)
           get_user_flagrec(m->user, &fr, chan->dname, chan);
 
-        if (((glob_deop(fr) && !chan_op(fr)) || chan_deop(fr)) || /* +d */
-           ((!channel_privchan(chan) && !chan_op(fr) && !glob_op(fr)) || /* simply no +o flag. */
-           (channel_privchan(chan) && !glob_bot(fr) && !glob_owner(fr) && !chan_op(fr)))) { /* private? */
-          targets++;
-        }
+        if (!chk_op(fr, chan))
+          ++targets;
     }
   }
 
   if (!targets || !ops)
     return;
 
-  ft = (bpos * targets) / ops;
-  ct = ((bpos + 2) * targets + (ops - 1)) / ops;
-  ct = (ct - ft + 1);
-  if (ct > 20)
-    ct = 20;
-  while (ft >= targets)
-    ft -= targets;
-  actions = 0;
-  sent = 0;
-  for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
-    if (!opsonly || chan_hasop(m)) {
-      struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
-
-      if (m->user)
-        get_user_flagrec(m->user, &fr, chan->dname, chan);
- 
-      if (((glob_deop(fr) && !chan_op(fr)) || chan_deop(fr)) ||
-          ((!channel_privchan(chan) && !chan_op(fr) && !glob_op(fr)) ||
-           (channel_privchan(chan) && !glob_bot(fr) && !glob_owner(fr) && !chan_op(fr)))) {
-
-        if (tpos >= ft) {
-          if ((action == PRIO_DEOP) && !chan_sentdeop(m)) {
-            actions++;
-            sent++;
-            add_mode(chan, '-', 'o', m->nick);
-            if (actions >= ct) {
-              flush_mode(chan, QUICK);
-              return;
-            }
-          } else if ((action == PRIO_KICK) && !chan_sentkick(m)) {
-            actions++;
-            sent++;
-            if (chan->closed_ban)
-              do_closed_kick(chan, m);
-            dprintf(DP_MODE, "KICK %s %s :%s%s\n", chan->name, m->nick, kickprefix, response(RES_CLOSED));
-            m->flags |= SENTKICK;
-            if (actions >= ct)
-              return;
-          }
-        }
-        tpos++;
-      
-      }
+  for (int n = 0; n < 2; ++n) {
+    // First pass - Handle my priority targets
+    if (n == 0) {
+      ft = (bpos * targets) / ops;
+      ct = ((bpos + 2) * targets + (ops - 1)) / ops;
+      ct = (ct - ft + 1);
+      if (ct > 20)
+        ct = 20;
+      while (ft >= targets)
+        ft -= targets;
+      actions = 0;
+      sent = 0;
+    } else {
+      // Second pass - Handle all remaining if I am able to
+      ct = ct - actions;
+      if (ct > ft)
+        ct = ft;
+      ft = 0;
+      actions = 0;
+      tpos = 0;
     }
-  }
-
-  ct = ct - actions;
-  if (ct > ft)
-    ct = ft;
-  ft = 0;
-  actions = 0;
-  tpos = 0;
-  for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
-    if (!opsonly || chan_hasop(m)) {
-      struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
+    for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
+      if (!opsonly || chan_hasop(m)) {
+        struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
 
-      if (m->user)
-        get_user_flagrec(m->user, &fr, chan->dname, chan);
+        if (m->user)
+          get_user_flagrec(m->user, &fr, chan->dname, chan);
 
-      if (((glob_deop(fr) && !chan_op(fr)) || chan_deop(fr)) ||
-          ((!channel_privchan(chan) && !chan_op(fr) && !glob_op(fr)) || 
-           (channel_privchan(chan) && !glob_bot(fr) && !glob_owner(fr) && !chan_op(fr)))) {
-
-        if (tpos >= ft) {
-          if ((action == PRIO_DEOP) && !chan_sentdeop(m)) {
-            actions++;
-            sent++;
-            add_mode(chan, '-', 'o', m->nick);
-            if ((actions >= ct) || (sent > 20)) {
-              flush_mode(chan, QUICK);
-              return;
+        if (!chk_op(fr, chan)) {
+          if (tpos >= ft) {
+            if ((action == PRIO_DEOP) && !chan_sentdeop(m)) {
+              ++actions;
+              ++sent;
+              add_mode(chan, '-', 'o', m->nick);
+              if (!floodless && (actions >= ct || (n == 1 && sent > 20))) {
+                flush_mode(chan, QUICK);
+                return;
+              }
+            } else if ((action == PRIO_KICK) && !chan_sentkick(m)) {
+              ++actions;
+              ++sent;
+              if (chan->closed_ban)
+                do_closed_kick(chan, m);
+              dprintf(DP_MODE, "KICK %s %s :%s%s\n", chan->name, m->nick, kickprefix, response(RES_CLOSED));
+              m->flags |= SENTKICK;
+              if (!floodless && (actions >= ct || (n == 1 && sent > 5)))
+                return;
             }
-          } else if ((action == PRIO_KICK) && !chan_sentkick(m)) {
-            actions++;
-            if (chan->closed_ban)
-              do_closed_kick(chan, m);
-            dprintf(DP_MODE, "KICK %s %s :%s%s\n", chan->name, m->nick, kickprefix, response(RES_CLOSED));
-            m->flags |= SENTKICK;
-            if ((actions >= ct) || (sent > 5))
-              return;
           }
-        }
-        tpos++;
+          ++tpos;
         
+        }
       }
     }
   }

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

@@ -186,7 +186,7 @@ flush_cookies(struct chanset_t *chan, int pri)
       tputs(serv, outbuf, len);
       /* dprintf(DP_MODE, "MODE %s %s\n", chan->name, out); */
     } else
-      dprintf(DP_SERVER, "MODE %s %s\n", chan->name, out);
+      dprintf(DP_MODE, "MODE %s %s\n", chan->name, out);
   }
 }
 
@@ -1092,7 +1092,7 @@ gotmode(char *from, char *msg)
               if (role <= 2)
                 tputs(serv, tmp, len);
               else
-                dprintf(DP_SERVER, "%s", tmp);
+                dprintf(DP_MODE, "%s", tmp);
             } else {
               if (u) {
                 simple_snprintf(tmp, sizeof(tmp), "Mass deop on %s by %s", chan->dname, m->nick);
@@ -1111,7 +1111,7 @@ gotmode(char *from, char *msg)
                   if (role <= 2)
                     tputs(serv, tmp, len);
                   else
-                    dprintf(DP_SERVER, "%s", tmp);
+                    dprintf(DP_MODE, "%s", tmp);
                 } else { 
                   if (u) {
                     simple_snprintf(tmp, sizeof(tmp), "Mass op on %s by %s", chan->dname, m->nick);