using namespace std;
-std::vector<ModeParameter> custom_mode_params;
+//std::vector<ModeParameter> custom_mode_params;
chanrec* ForceChan(chanrec* Ptr,ucrec &a,userrec* user, int created);
{
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);
+ }
}
}
}
}
}
- log(DEBUG,"*** BUG *** Attempt to remove non-existent mode parameter!");
}
}
return (strchr(this->custom_modes,mode));
}
-/* XXX - would it not be better to store a vector for each channel, rather than one huge list? -- w00t */
std::string chanrec::GetModeParameter(char mode)
{
if (custom_mode_params.size())
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);
user->chans.push_back(a);
return c;
}
- else if (strchr(user->modes,'o'))
+ else if (*user->oper)
{
/* Oper allows extension up to the OPERMAXCHANS value */
if (user->chans.size() < OPERMAXCHANS)
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;
}