/** A list of custom modes parameters on a channel
*/
-typedef std::map<char,char*> CustomModeList;
+typedef std::map<char,std::string> CustomModeList;
/** used to hold a channel and a users modes on that channel, e.g. +v, +h, +o
*/
void SetMode(char mode,bool mode_on);
- /** Sets or unsets the parameters for a custom mode in a channels info
+ /** Sets or unsets a custom mode in the channels info
* @param mode The mode character to set or unset
- * @param parameter The parameter string to associate with this mode character
- * @param mode_on True if you want to set the mode or false if you want to remove it
+ * @param parameter The parameter string to associate with this mode character.
+ * If it is empty, the mode is unset; if it is nonempty, the mode is set.
*/
- void SetModeParam(char mode,const char* parameter,bool mode_on);
+ void SetMode(char mode, std::string parameter);
/** Returns true if a mode is set on a channel
* @param mode The mode character you wish to query
void Channel::SetMode(char mode,bool mode_on)
{
modes[mode-65] = mode_on;
- if (!mode_on)
- this->SetModeParam(mode,"",false);
}
-
-void Channel::SetModeParam(char mode,const char* parameter,bool mode_on)
+void Channel::SetMode(char mode, std::string parameter)
{
CustomModeList::iterator n = custom_mode_params.find(mode);
-
- if (mode_on)
+ // always erase, even if changing, so that the map gets the new value
+ if (n != custom_mode_params.end())
+ custom_mode_params.erase(n);
+ if (parameter.empty())
{
- if (n == custom_mode_params.end())
- custom_mode_params[mode] = strdup(parameter);
+ modes[mode-65] = false;
}
else
{
- if (n != custom_mode_params.end())
- {
- free(n->second);
- custom_mode_params.erase(n);
- }
+ custom_mode_params[mode] = parameter;
+ modes[mode-65] = true;
}
}
if (parameter.rfind(' ') != std::string::npos)
return MODEACTION_DENY;
- /* must first unset if we are changing the key, otherwise it will be ignored */
- if (exists && adding)
- channel->SetMode('k', false);
-
- /* must run setmode always, to process the change */
- channel->SetMode('k', adding);
-
if (adding)
{
std::string ckey;
ckey.assign(parameter, 0, 32);
parameter = ckey;
- /* running this does not run setmode, despite the third parameter */
- channel->SetModeParam('k', parameter.c_str(), true);
+ channel->SetMode('k', parameter);
+ }
+ else
+ {
+ channel->SetMode('k', "");
}
return MODEACTION_ALLOW;
}
parameter = ConvToStr(limit);
/* Set new limit */
- channel->SetModeParam('l', parameter.c_str(), true);
- channel->modes[CM_LIMIT] = 1;
+ channel->SetMode('l', parameter);
return MODEACTION_ALLOW;
}
}
/* Removing old limit, no checks here */
- channel->SetModeParam('l', "", false);
- channel->modes[CM_LIMIT] = 0;
-
+ channel->SetMode('l', "");
return MODEACTION_ALLOW;
}
}
parameter = ConvToStr(njoins) + ":" +ConvToStr(nsecs);
joinfloodsettings *f = new joinfloodsettings(ServerInstance, nsecs, njoins);
channel->Extend("joinflood", f);
- channel->SetMode('j', true);
- channel->SetModeParam('j', parameter.c_str(), true);
+ channel->SetMode('j', parameter);
return MODEACTION_ALLOW;
}
else
f = new joinfloodsettings(ServerInstance, nsecs, njoins);
channel->Shrink("joinflood");
channel->Extend("joinflood", f);
- channel->SetModeParam('j', cur_param.c_str(), false);
- channel->SetModeParam('j', parameter.c_str(), true);
+ channel->SetMode('j', parameter);
return MODEACTION_ALLOW;
}
else
channel->GetExt("joinflood", f);
delete f;
channel->Shrink("joinflood");
- channel->SetMode('j', false);
+ channel->SetMode('j', "");
return MODEACTION_ALLOW;
}
}
}
else
{
- channel->SetMode('J', false);
+ channel->SetMode('J', "");
return MODEACTION_ALLOW;
}
}
if (!channel->IsModeSet('J'))
{
parameter = ConvToStr(atoi(parameter.c_str()));
- channel->SetModeParam('J', parameter.c_str(), adding);
- channel->SetMode('J', adding);
+ channel->SetMode('J', parameter);
return MODEACTION_ALLOW;
}
else
{
// new mode param, replace old with new
parameter = ConvToStr(atoi(parameter.c_str()));
- cur_param = ConvToStr(atoi(cur_param.c_str()));
if (parameter != "0")
{
- channel->SetModeParam('J', cur_param.c_str(), false);
- channel->SetModeParam('J', parameter.c_str(), adding);
+ channel->SetMode('J', parameter);
return MODEACTION_ALLOW;
}
else
parameter = std::string(ban ? "*" : "") + ConvToStr(nlines) + ":" +ConvToStr(nsecs);
floodsettings *fs = new floodsettings(ServerInstance,ban,nsecs,nlines);
channel->Extend("flood",fs);
- channel->SetMode('f', true);
- channel->SetModeParam('f', parameter.c_str(), true);
+ channel->SetMode('f', parameter);
return MODEACTION_ALLOW;
}
else
floodsettings *fs = new floodsettings(ServerInstance,ban,nsecs,nlines);
channel->Shrink("flood");
channel->Extend("flood",fs);
- channel->SetModeParam('f', cur_param.c_str(), false);
- channel->SetModeParam('f', parameter.c_str(), true);
+ channel->SetMode('f', parameter);
return MODEACTION_ALLOW;
}
else
{
delete f;
channel->Shrink("flood");
- channel->SetMode('f', false);
+ channel->SetMode('f', "");
return MODEACTION_ALLOW;
}
}
parameter = ConvToStr(nnicks) + ":" +ConvToStr(nsecs);
nickfloodsettings *f = new nickfloodsettings(ServerInstance, nsecs, nnicks);
channel->Extend("nickflood", f);
- channel->SetMode('F', true);
- channel->SetModeParam('F', parameter.c_str(), true);
+ channel->SetMode('F', parameter);
return MODEACTION_ALLOW;
}
else
f = new nickfloodsettings(ServerInstance, nsecs, nnicks);
channel->Shrink("nickflood");
channel->Extend("nickflood", f);
- channel->SetModeParam('F', cur_param.c_str(), false);
- channel->SetModeParam('F', parameter.c_str(), true);
+ channel->SetMode('F', parameter);
return MODEACTION_ALLOW;
}
else
channel->GetExt("nickflood", f);
delete f;
channel->Shrink("nickflood");
- channel->SetMode('F', false);
+ channel->SetMode('F', "");
return MODEACTION_ALLOW;
}
}
* We used to do some checking for circular +L here, but there is no real need for this any more especially as we
* now catch +L looping in PreJoin. Remove it, since O(n) logic makes me sad, and we catch it anyway. :) -- w00t
*/
- channel->SetMode('L', true);
- channel->SetModeParam('L', parameter.c_str(), true);
+ channel->SetMode('L', parameter);
return MODEACTION_ALLOW;
}
else
{
if (channel->IsModeSet('L'))
{
- channel->SetMode('L', false);
+ channel->SetMode('L', "");
return MODEACTION_ALLOW;
}
}