فهرست منبع

Don't count spaces for caps percentage (#8)

Bryan Drewery 14 سال پیش
والد
کامیت
dff9c7e01d
1فایلهای تغییر یافته به همراه20 افزوده شده و 1 حذف شده
  1. 20 1
      src/mod/irc.mod/irc.c

+ 20 - 1
src/mod/irc.mod/irc.c

@@ -131,16 +131,35 @@ detect_offense(memberlist* m, struct chanset_t *chan, char *msg)
       (m && chan->flood_exempt_mode == CHAN_FLAG_VOICE && (chan_hasvoice(m) || chan_hasop(m))))
       (m && chan->flood_exempt_mode == CHAN_FLAG_VOICE && (chan_hasvoice(m) || chan_hasop(m))))
     return 0;
     return 0;
 
 
-  const size_t tot = strlen(msg);
   int color_count = 0, hit_check = 0, hit_count = 0;
   int color_count = 0, hit_check = 0, hit_count = 0;
   double caps_percentage = 0, caps_count = 0;
   double caps_percentage = 0, caps_count = 0;
   const double caps_limit = chan->capslimit ? double(chan->capslimit) / 100.0 : double(0);
   const double caps_limit = chan->capslimit ? double(chan->capslimit) / 100.0 : double(0);
 
 
+  // Need to know how long the message is, and want to ignore spaces, so avoid a strlen() and just loop to count
+  size_t tot = 0;
+  char *msg_check = msg;
+  while (msg_check && *msg_check) {
+    if (!egg_isspace(*msg_check)) {
+      ++tot;
+    }
+    ++msg_check;
+  }
+
+  if (!tot) {
+    return 0;
+  }
+
   if (tot >= 30) {
   if (tot >= 30) {
     hit_check = tot/5; //check in-between for hits to save waste of cpu
     hit_check = tot/5; //check in-between for hits to save waste of cpu
   }
   }
 
 
   while (msg && *msg) {
   while (msg && *msg) {
+    // Skip spaces
+    if (egg_isspace(*msg)) {
+      ++msg;
+      continue;
+    }
+
     if (egg_isupper(*msg)) {
     if (egg_isupper(*msg)) {
       ++caps_count;
       ++caps_count;
     } else if (*msg == 3 || *msg == 2) {
     } else if (*msg == 3 || *msg == 2) {