1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 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(InspIRCd* Instance) : ModeHandler(Instance, 'k', 1, 1, false, MODETYPE_CHANNEL, false)
24 ModePair ModeChannelKey::ModeSet(User*, User*, Channel* channel, const std::string ¶meter)
26 if (channel->modes[CM_KEY])
28 std::string ckey = channel->GetModeParameter('k');
29 return std::make_pair(true, ckey);
33 return std::make_pair(false, parameter);
37 void ModeChannelKey::RemoveMode(Channel* channel, irc::modestacker* stack)
39 /** +k needs a parameter when being removed,
40 * so we have a special-case RemoveMode here for it
43 if (channel->IsModeSet('k'))
47 stack->Push('k', channel->GetModeParameter('k'));
51 std::vector<std::string> parameters;
52 parameters.push_back(channel->name);
53 parameters.push_back("-k");
54 parameters.push_back(channel->GetModeParameter('k'));
55 ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
60 void ModeChannelKey::RemoveMode(User*, irc::modestacker* stack)
64 bool ModeChannelKey::CheckTimeStamp(time_t, time_t, const std::string &their_param, const std::string &our_param, Channel*)
66 /* When TS is equal, the alphabetically later channel key wins */
67 return (their_param < our_param);
70 ModeAction ModeChannelKey::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding, bool servermode)
72 bool exists = channel->IsModeSet('k');
76 return MODEACTION_DENY;
77 if (exists && (parameter != channel->GetModeParameter('k')))
79 /* Key is currently set and the correct key wasnt given */
80 return MODEACTION_DENY;
83 if (exists && adding && parameter == channel->GetModeParameter('k'))
85 /* no-op, don't show */
86 return MODEACTION_DENY;
91 if (!parameter.length())
92 return MODEACTION_DENY;
94 if (parameter.rfind(' ') != std::string::npos)
95 return MODEACTION_DENY;
100 ckey.assign(parameter, 0, 32);
102 channel->SetModeParam('k', parameter);
106 channel->SetModeParam('k', "");
108 return MODEACTION_ALLOW;