]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/channels.cpp
Optimisation of optimisation :P ty w00tie
[user/henk/code/inspircd.git] / src / channels.cpp
index fc6c90b5d7eeb89e1729a6d6a0b61dedbda504a2..f086b9853ac0b521187ecd8d6d4c9f69fe4b19fb 100644 (file)
@@ -81,24 +81,39 @@ void chanrec::SetCustomMode(char mode,bool mode_on)
 {
        if (mode_on)
        {
-               static char m[3];
-               m[0] = mode;
-               m[1] = '\0';
-               if (!strchr(this->custom_modes,mode))
+               char* mptr = this->custom_modes;
+               int ssize = 0;
+
+               /* Attempt to find the end of the mode string */
+               while (*mptr++)
                {
-                       strlcat(custom_modes,m,MAXMODES);
+                       /* While iterating the mode string, we found that they already have
+                        * this mode in their list. Abort right now. */
+                       if (*mptr == mode)
+                               return;
+                       /* Increment the string size, saves us doing strlen */
+                       ssize++;
                }
-               log(DEBUG,"Custom mode %c set",mode);
-       }
-       else {
 
-               std::string a = this->custom_modes;
-               int pos = a.find(mode);
-               a.erase(pos,1);
-               strlcpy(this->custom_modes,a.c_str(),MAXMODES);
+               log(DEBUG,"ssize=%d",ssize);
+
+               /* Is there room left in the buffer? If there is append the mode */
+               if (ssize < MAXMODES-1)
+               {
+                       *--mptr = mode;
+                       *++mptr = 0;
+               }
 
-               log(DEBUG,"Custom mode %c removed: modelist='%s'",mode,this->custom_modes);
-               this->SetCustomModeParam(mode,"",false);
+               log(DEBUG,"Custom mode %c set, modes='%s'",mode,this->custom_modes);
+       }
+       else
+       {
+               if (charremove(this->custom_modes,mode))
+               {
+                       log(DEBUG,"Custom mode %c removed: modelist='%s'",mode,this->custom_modes);
+                       /* Only call this if we found the mode */
+                       this->SetCustomModeParam(mode,"",false);
+               }
        }
 }
 
@@ -130,7 +145,6 @@ void chanrec::SetCustomModeParam(char mode,char* parameter,bool mode_on)
                                }
                        }
                }
-               log(DEBUG,"*** BUG *** Attempt to remove non-existent mode parameter!");
        }
 }
 
@@ -455,7 +469,7 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri
                        {
                                if (user->chans[index].channel == Ptr)
                                {
-                                       user->chans[index].channel == NULL;
+                                       user->chans[index].channel = NULL;
                                        user->chans[index].uc_modes = 0;        
                                }
                        }