summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/channels.cpp21
-rw-r--r--src/modes/cmode_k.cpp14
-rw-r--r--src/modes/cmode_l.cpp7
-rw-r--r--src/modules/m_joinflood.cpp8
-rw-r--r--src/modules/m_kicknorejoin.cpp9
-rw-r--r--src/modules/m_messageflood.cpp8
-rw-r--r--src/modules/m_nickflood.cpp8
-rw-r--r--src/modules/m_redirect.cpp5
8 files changed, 29 insertions, 51 deletions
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;
}
}