summaryrefslogtreecommitdiff
path: root/src/modes/cmode_k.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modes/cmode_k.cpp')
-rw-r--r--src/modes/cmode_k.cpp54
1 files changed, 6 insertions, 48 deletions
diff --git a/src/modes/cmode_k.cpp b/src/modes/cmode_k.cpp
index 400333fce..e56b26ff1 100644
--- a/src/modes/cmode_k.cpp
+++ b/src/modes/cmode_k.cpp
@@ -24,76 +24,34 @@
#include "mode.h"
#include "channels.h"
#include "users.h"
-#include "modes/cmode_k.h"
+#include "builtinmodes.h"
ModeChannelKey::ModeChannelKey() : ModeHandler(NULL, "key", 'k', PARAM_ALWAYS, MODETYPE_CHANNEL)
{
}
-void ModeChannelKey::RemoveMode(Channel* channel, irc::modestacker* stack)
-{
- /** +k needs a parameter when being removed,
- * so we have a special-case RemoveMode here for it
- */
-
- if (channel->IsModeSet('k'))
- {
- if (stack)
- {
- stack->Push('k', channel->GetModeParameter('k'));
- }
- else
- {
- std::vector<std::string> parameters;
- parameters.push_back(channel->name);
- parameters.push_back("-k");
- parameters.push_back(channel->GetModeParameter('k'));
- ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
- }
- }
-}
-
-void ModeChannelKey::RemoveMode(User*, irc::modestacker* stack)
-{
-}
-
ModeAction ModeChannelKey::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding)
{
- bool exists = channel->IsModeSet('k');
+ bool exists = channel->IsModeSet(this);
if (IS_LOCAL(source))
{
if (exists == adding)
return MODEACTION_DENY;
- if (exists && (parameter != channel->GetModeParameter('k')))
+ if (exists && (parameter != channel->GetModeParameter(this)))
{
/* Key is currently set and the correct key wasnt given */
return MODEACTION_DENY;
}
} else {
- if (exists && adding && parameter == channel->GetModeParameter('k'))
+ if (exists && adding && parameter == channel->GetModeParameter(this))
{
/* no-op, don't show */
return MODEACTION_DENY;
}
}
- /* invalid keys */
- if (!parameter.length())
- return MODEACTION_DENY;
-
- if (parameter.rfind(' ') != std::string::npos)
- return MODEACTION_DENY;
-
if (adding)
- {
- std::string ckey;
- ckey.assign(parameter, 0, 32);
- parameter = ckey;
- channel->SetModeParam('k', parameter);
- }
- else
- {
- channel->SetModeParam('k', "");
- }
+ parameter = parameter.substr(0, 32);
+
return MODEACTION_ALLOW;
}