diff options
-rw-r--r-- | include/channels.h | 10 | ||||
-rw-r--r-- | src/channels.cpp | 21 | ||||
-rw-r--r-- | src/modes/cmode_k.cpp | 14 | ||||
-rw-r--r-- | src/modes/cmode_l.cpp | 7 | ||||
-rw-r--r-- | src/modules/m_joinflood.cpp | 8 | ||||
-rw-r--r-- | src/modules/m_kicknorejoin.cpp | 9 | ||||
-rw-r--r-- | src/modules/m_messageflood.cpp | 8 | ||||
-rw-r--r-- | src/modules/m_nickflood.cpp | 8 | ||||
-rw-r--r-- | src/modules/m_redirect.cpp | 5 |
9 files changed, 34 insertions, 56 deletions
diff --git a/include/channels.h b/include/channels.h index afcdee41f..3bbcf0672 100644 --- a/include/channels.h +++ b/include/channels.h @@ -74,7 +74,7 @@ typedef CUList::const_iterator CUListConstIter; /** 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 @@ -202,12 +202,12 @@ class CoreExport Channel : public Extensible */ 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 diff --git a/src/channels.cpp b/src/channels.cpp index 19899d300..99b118d0d 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -34,27 +34,22 @@ Channel::Channel(InspIRCd* Instance, const std::string &cname, time_t ts) : Serv 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; } } diff --git a/src/modes/cmode_k.cpp b/src/modes/cmode_k.cpp index f2afb9ac0..a7c491aa5 100644 --- a/src/modes/cmode_k.cpp +++ b/src/modes/cmode_k.cpp @@ -94,20 +94,16 @@ ModeAction ModeChannelKey::OnModeChange(User* source, User*, Channel* channel, s 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; } diff --git a/src/modes/cmode_l.cpp b/src/modes/cmode_l.cpp index e87a524b2..3d37fc900 100644 --- a/src/modes/cmode_l.cpp +++ b/src/modes/cmode_l.cpp @@ -54,8 +54,7 @@ ModeAction ModeChannelLimit::OnModeChange(User*, User*, Channel* channel, std::s 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; } @@ -71,9 +70,7 @@ ModeAction ModeChannelLimit::OnModeChange(User*, User*, Channel* channel, std::s } /* Removing old limit, no checks here */ - channel->SetModeParam('l', "", false); - channel->modes[CM_LIMIT] = 0; - + channel->SetMode('l', ""); return MODEACTION_ALLOW; } } diff --git a/src/modules/m_joinflood.cpp b/src/modules/m_joinflood.cpp index ae173bdb3..7e4a05d2b 100644 --- a/src/modules/m_joinflood.cpp +++ b/src/modules/m_joinflood.cpp @@ -144,8 +144,7 @@ class JoinFlood : public ModeHandler 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 @@ -168,8 +167,7 @@ class JoinFlood : public ModeHandler 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 @@ -194,7 +192,7 @@ class JoinFlood : public ModeHandler channel->GetExt("joinflood", f); delete f; channel->Shrink("joinflood"); - channel->SetMode('j', false); + channel->SetMode('j', ""); return MODEACTION_ALLOW; } } diff --git a/src/modules/m_kicknorejoin.cpp b/src/modules/m_kicknorejoin.cpp index 527022c11..c5abc80c2 100644 --- a/src/modules/m_kicknorejoin.cpp +++ b/src/modules/m_kicknorejoin.cpp @@ -65,7 +65,7 @@ class KickRejoin : public ModeHandler } else { - channel->SetMode('J', false); + channel->SetMode('J', ""); return MODEACTION_ALLOW; } } @@ -74,8 +74,7 @@ class KickRejoin : public ModeHandler 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 @@ -90,11 +89,9 @@ class KickRejoin : public ModeHandler { // 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 diff --git a/src/modules/m_messageflood.cpp b/src/modules/m_messageflood.cpp index ed40fca5b..f2082da33 100644 --- a/src/modules/m_messageflood.cpp +++ b/src/modules/m_messageflood.cpp @@ -143,8 +143,7 @@ class MsgFlood : public ModeHandler 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 @@ -164,8 +163,7 @@ class MsgFlood : public ModeHandler 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 @@ -189,7 +187,7 @@ class MsgFlood : public ModeHandler { delete f; channel->Shrink("flood"); - channel->SetMode('f', false); + channel->SetMode('f', ""); return MODEACTION_ALLOW; } } diff --git a/src/modules/m_nickflood.cpp b/src/modules/m_nickflood.cpp index f91694625..0a8e9a31d 100644 --- a/src/modules/m_nickflood.cpp +++ b/src/modules/m_nickflood.cpp @@ -144,8 +144,7 @@ class NickFlood : public ModeHandler 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 @@ -168,8 +167,7 @@ class NickFlood : public ModeHandler 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 @@ -194,7 +192,7 @@ class NickFlood : public ModeHandler channel->GetExt("nickflood", f); delete f; channel->Shrink("nickflood"); - channel->SetMode('F', false); + channel->SetMode('F', ""); return MODEACTION_ALLOW; } } diff --git a/src/modules/m_redirect.cpp b/src/modules/m_redirect.cpp index 9aa0dcf8b..00c191d26 100644 --- a/src/modules/m_redirect.cpp +++ b/src/modules/m_redirect.cpp @@ -68,15 +68,14 @@ class Redirect : public ModeHandler * 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; } } |