Parcourir la source

Proper kick-reasons (#8)

Mark il y a 15 ans
Parent
commit
16db0cc418
2 fichiers modifiés avec 30 ajouts et 20 suppressions
  1. 2 5
      src/mod/irc.mod/chan.c
  2. 28 15
      src/mod/irc.mod/irc.c

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

@@ -3250,11 +3250,8 @@ static int gotmsg(char *from, char *msg)
     int botmatch = 0;
     char *my_msg = NULL, *my_ptr = NULL, *fword = NULL;
 
-    if (me_op(chan) && doflood(chan)) {
-      if (detect_offense(m, chan, msg)) {
-        dprintf(DP_MODE, "KICK %s %s :%s (capsflood)\n", chan->name, nick, response(RES_FLOOD));
-      }
-    }
+    if (me_op(chan) && doflood(chan))
+      detect_offense(m, chan, msg);
 
     /* Check even if we're ignoring the host. (modified by Eule 17.7.99) */
     detect_chan_flood(nick, uhost, from, chan, FLOOD_PRIVMSG, NULL);

+ 28 - 15
src/mod/irc.mod/irc.c

@@ -134,23 +134,36 @@ detect_offense(memberlist* m, struct chanset_t *chan, char *msg)
   int tot = (int)strlen(msg);
   int caps_count = 0;
   int color_count = 0;
+  int hit_check = 0;
+  int hit_count = 0;
 
-  /* caps control. */
-  if (tot > 5 && (chan->capslimit || chan->colorlimit)) { /* the caller checks for doflood so no need to check again here */
-    while (msg && *msg) {
-      if (egg_isupper(*msg))
-        caps_count++;
-      else if (*msg == 3)
-        color_count++;
-      msg++;
+  if (tot >= 30) hit_check = tot/5; //check in-between for hits to save waste of cpu
+
+  while (msg && *msg) {
+    if (egg_isupper(*msg))
+      caps_count++;
+    else if (*msg == 3)
+      color_count++;
+
+    if (hit_check && !(hit_count%hit_check)) {
+      if (chan->capslimit && ((((float)caps_count)/((float)tot))*100 >= chan->capslimit)) break;
+      else if (chan->colorlimit && color_count >= chan->colorlimit) break;
+      hit_count++;
+    }
+    msg++;
+  }
+  if (chan->capslimit && caps_count) {
+    int cap_p = (((float)caps_count)/((float)tot))*100;
+    if (cap_p >= chan->capslimit) {
+      dprintf(DP_SERVER, "KICK %s %s :%s%s\n", chan->name, m->nick, kickprefix, response(RES_FLOOD));
+      m->flags |= SENTKICK;
+      return 0;
     }
-    if (chan->capslimit && caps_count) {
-      int cap_p = (((float)caps_count)/((float)tot))*100;
-      if (cap_p >= chan->capslimit)
-        return 1;
-    } else if (chan->colorlimit && color_count) {
-      if (color_count >= chan->colorlimit)
-        return 1;
+  } else if (chan->colorlimit && color_count) {
+    if (color_count >= chan->colorlimit) {
+      dprintf(DP_SERVER, "KICK %s %s :%s%s\n", chan->name, m->nick, kickprefix, response(RES_FLOOD));
+      m->flags |= SENTKICK;
+      return 0;
     }
   }
   return 0;