1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
18 #include "modes/cmode_k.h"
20 ModeChannelKey::ModeChannelKey() : ModeHandler(NULL, "key", 'k', PARAM_ALWAYS, MODETYPE_CHANNEL)
24 void ModeChannelKey::RemoveMode(Channel* channel, irc::modestacker* stack)
26 /** +k needs a parameter when being removed,
27 * so we have a special-case RemoveMode here for it
30 if (channel->IsModeSet('k'))
34 stack->Push('k', channel->GetModeParameter('k'));
38 std::vector<std::string> parameters;
39 parameters.push_back(channel->name);
40 parameters.push_back("-k");
41 parameters.push_back(channel->GetModeParameter('k'));
42 ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
47 void ModeChannelKey::RemoveMode(User*, irc::modestacker* stack)
51 ModeAction ModeChannelKey::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding)
53 bool exists = channel->IsModeSet('k');
57 return MODEACTION_DENY;
58 if (exists && (parameter != channel->GetModeParameter('k')))
60 /* Key is currently set and the correct key wasnt given */
61 return MODEACTION_DENY;
64 if (exists && adding && parameter == channel->GetModeParameter('k'))
66 /* no-op, don't show */
67 return MODEACTION_DENY;
72 if (!parameter.length())
73 return MODEACTION_DENY;
75 if (parameter.rfind(' ') != std::string::npos)
76 return MODEACTION_DENY;
81 ckey.assign(parameter, 0, 32);
83 channel->SetModeParam('k', parameter);
87 channel->SetModeParam('k', "");
89 return MODEACTION_ALLOW;