filter out invisible message content on mode +M check
authorpk910 <philipp@zoelle1.de>
Sat, 2 Jul 2011 12:44:24 +0000 (14:44 +0200)
committerpk910 <philipp@zoelle1.de>
Sat, 2 Jul 2011 12:44:24 +0000 (14:44 +0200)
ircd/channel.c

index 1ca8519486edcb0a135583718df110e91a2a78fb..a467750ea39496f483da2cad7b247b18a138e4ae 100644 (file)
@@ -4305,7 +4305,7 @@ void RevealDelayedJoinIfNeeded(struct Client *sptr, struct Channel *chptr)
 int ext_amsg_block(struct Client *cptr, struct Channel *chptr, const char *msg)
 {
   int amsg_time;
 int ext_amsg_block(struct Client *cptr, struct Channel *chptr, const char *msg)
 {
   int amsg_time;
-
+  
   /* First on every message we check whether the mechanism is enabled.
    * If it is enabled, we check:
    *  - whether the channel has MODE_NOAMSGS
   /* First on every message we check whether the mechanism is enabled.
    * If it is enabled, we check:
    *  - whether the channel has MODE_NOAMSGS
@@ -4319,6 +4319,59 @@ int ext_amsg_block(struct Client *cptr, struct Channel *chptr, const char *msg)
    */
   amsg_time = feature_int(FEAT_NOAMSG_TIME);
   if(amsg_time > 0) {
    */
   amsg_time = feature_int(FEAT_NOAMSG_TIME);
   if(amsg_time > 0) {
+    /* first of all strip the message (filter out invisible content) */
+    char *stripped_message = MyMalloc(BUFSIZE + 1);
+    strcpy(stripped_message, msg);
+    char p = stripped_message[0];
+    int p_pos = 0;
+    int is_visible = 1, is_ccode = 0; j = 0;
+    char codes[5];
+    for(int i = 0; p != '\n'; p = stripped_message[++i]) {
+      if(c == 3) {
+        j = 0;
+        is_ccode = 1;
+      } else if(is_ccode) {
+        if((c >= 48 && c <= 57) || c == 44) {
+          if(ccode == 1) {
+            if(c == 44) {
+              ccode = 2;
+              codes[j++] = 0;
+              j = 0;
+            } else
+              codes[j++] = c;
+          } else {
+            //compare
+            if(c != codes[j++]) {
+             ccode = 3;
+            }
+          }
+        } else {
+          //END of color code...
+          is_ccode = 0;
+          if(ccode != 1 && codes[j] != 0) ccode = 3;
+          if(ccode == 1) {
+            codes[j] = 0;
+            for(int k = 0; k < j-1; k++) {
+              if(codes[k] != 48) {
+                is_visible = 1;
+                goto normalchar;
+              }
+            }
+            is_visible = 0;
+          } else if(ccode == 2) {
+            is_visible = 0;
+          } else if(ccode == 3) {
+            is_visible = 1;
+            goto normalchar;
+          }
+        }
+      } else {
+        :normalchar
+        if(is_visible)
+          stripped_message[p_pos++] = p;
+      }
+    }
+    stripped_message[p_pos++] = 0;
     /* Allocate a new buffer if there is none, yet. */
     if(!cli_user(cptr)->lastmsg) {
       cli_user(cptr)->lastmsg = MyMalloc(BUFSIZE + 1);
     /* Allocate a new buffer if there is none, yet. */
     if(!cli_user(cptr)->lastmsg) {
       cli_user(cptr)->lastmsg = MyMalloc(BUFSIZE + 1);
@@ -4326,16 +4379,18 @@ int ext_amsg_block(struct Client *cptr, struct Channel *chptr, const char *msg)
     }
     if((chptr->mode.mode & MODE_NOAMSGS) &&
        ((cli_user(cptr)->lastmsg_time + amsg_time) >= CurrentTime) &&
     }
     if((chptr->mode.mode & MODE_NOAMSGS) &&
        ((cli_user(cptr)->lastmsg_time + amsg_time) >= CurrentTime) &&
-       (strcmp(cli_user(cptr)->lastmsg, msg) == 0)) {
+       (strcmp(cli_user(cptr)->lastmsg, stripped_message) == 0)) {
       cli_user(cptr)->lastmsg_time = CurrentTime;
       cli_user(cptr)->lastmsg_num++;
       cli_user(cptr)->lastmsg_time = CurrentTime;
       cli_user(cptr)->lastmsg_num++;
+      MyFree(stripped_message);
       if(cli_user(cptr)->lastmsg_num >= feature_int(FEAT_NOAMSG_NUM)) return 1;
       else return 0;
     }
     /* Message did not match so update the data. */
     cli_user(cptr)->lastmsg_time = CurrentTime;
     cli_user(cptr)->lastmsg_num = 0;
       if(cli_user(cptr)->lastmsg_num >= feature_int(FEAT_NOAMSG_NUM)) return 1;
       else return 0;
     }
     /* Message did not match so update the data. */
     cli_user(cptr)->lastmsg_time = CurrentTime;
     cli_user(cptr)->lastmsg_num = 0;
-    strcpy(cli_user(cptr)->lastmsg, msg);
+    strcpy(cli_user(cptr)->lastmsg, stripped_message);
+    MyFree(stripped_message);
   }
   return 0;
 }
   }
   return 0;
 }