]> 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 9335fe25134281179bfbb5359e839a1d8f543b66..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!");
        }
 }
 
@@ -290,7 +304,7 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri
                chanlist[cname]->binarymodes = CM_TOPICLOCK | CM_NOEXTERNAL;
                chanlist[cname]->created = TIME;
                *chanlist[cname]->topic = 0;
-               strlcpy(chanlist[cname]->setby, user->nick,NICKMAX);
+               strlcpy(chanlist[cname]->setby, user->nick,NICKMAX-1);
                chanlist[cname]->topicset = 0;
                Ptr = chanlist[cname];
                log(DEBUG,"add_channel: created: %s",cname);
@@ -440,6 +454,27 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri
 
        log(DEBUG,"add_channel: user channel max exceeded: %s %s",user->nick,cname);
        WriteServ(user->fd,"405 %s %s :You are on too many channels",user->nick, cname);
+
+       if (created == 2)
+       {
+               log(DEBUG,"BLAMMO, Whacking channel.");
+               /* Things went seriously pear shaped, so take this away. bwahaha. */
+               chan_hash::iterator n = chanlist.find(cname);
+               if (n != chanlist.end())
+               {
+                       Ptr->DelUser((char*)user);
+                       delete Ptr;
+                       chanlist.erase(n);
+                       for (unsigned int index =0; index < user->chans.size(); index++)
+                       {
+                               if (user->chans[index].channel == Ptr)
+                               {
+                                       user->chans[index].channel = NULL;
+                                       user->chans[index].uc_modes = 0;        
+                               }
+                       }
+               }
+       }
        return NULL;
 }