]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_blockcolor.cpp
Review and optimize
[user/henk/code/inspircd.git] / src / modules / m_blockcolor.cpp
index f63caf6c5e95e45881d32ab09826262719a30418..1e7f213535e8e0f6d475644e6cc0e22d59e1edac 100644 (file)
@@ -63,13 +63,26 @@ class ModuleBlockColor : public Module
                {
                        chanrec* c = (chanrec*)dest;
                        char ctext[MAXBUF];
+                       char *ctptr = ctext;
                        snprintf(ctext,MAXBUF,"%s",text.c_str());
+
+
                        if (c->IsCustomModeSet('c'))
                        {
-                               if ((strchr(ctext,'\2')) || (strchr(ctext,'\3')) || (strchr(ctext,31)))
+                               /* Instead of using strchr() here, do our own loop. Hopefully faster. --w00t */
+                               while (ctptr && *ctptr)
                                {
-                                       WriteServ(user->fd,"404 %s %s :Can't send colors to channel (+c set)",user->nick, c->name);
-                                       return 1;
+                                       switch (*ctptr)
+                                       {
+                                               case 2:
+                                               case 3:
+                                               case 31:
+                                                       WriteServ(user->fd,"404 %s %s :Can't send colors to channel (+c set)",user->nick, c->name);
+                                                       return 1;
+                                                       break;
+                                       }
+
+                                       *ctptr++;
                                }
                        }
                }
@@ -82,13 +95,26 @@ class ModuleBlockColor : public Module
                {
                        chanrec* c = (chanrec*)dest;
                        char ctext[MAXBUF];
+                       char *ctptr = ctext;
                        snprintf(ctext,MAXBUF,"%s",text.c_str());
+
+
                        if (c->IsCustomModeSet('c'))
                        {
-                               if ((strchr(ctext,'\2')) || (strchr(ctext,'\3')) || (strchr(ctext,31)))
+                               /* Instead of using strchr() here, do our own loop. Hopefully faster. --w00t */
+                               while (ctptr && *ctptr)
                                {
-                                       WriteServ(user->fd,"404 %s %s :Can't send colors to channel (+c set)",user->nick, c->name);
-                                       return 1;
+                                       switch (*ctptr)
+                                       {
+                                               case 2:
+                                               case 3:
+                                               case 31:
+                                                       WriteServ(user->fd,"404 %s %s :Can't send colors to channel (+c set)",user->nick, c->name);
+                                                       return 1;
+                                                       break;
+                                       }
+
+                                       ctptr++;
                                }
                        }
                }