1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/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(this->GetModeChar()))
47 stack->Push(this->GetModeChar(), channel->GetModeParameter('k'));
51 std::vector<std::string> parameters; parameters.push_back(channel->name); parameters.push_back("-k"); parameters.push_back(channel->GetModeParameter('k'));
52 ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
57 void ModeChannelKey::RemoveMode(User*, irc::modestacker* stack)
61 bool ModeChannelKey::CheckTimeStamp(time_t, time_t, const std::string &their_param, const std::string &our_param, Channel*)
63 /* When TS is equal, the alphabetically later channel key wins */
64 return (their_param < our_param);
67 ModeAction ModeChannelKey::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding, bool servermode)
69 if ((channel->IsModeSet('k') != adding) || (!IS_LOCAL(source)))
71 if (((channel->IsModeSet('k')) && (parameter != channel->GetModeParameter('k'))) && (IS_LOCAL(source)))
73 /* Key is currently set and the correct key wasnt given */
74 return MODEACTION_DENY;
76 else if ((!channel->IsModeSet('k')) || ((adding) && (!IS_LOCAL(source))))
78 /* Key isnt currently set */
79 if ((parameter.length()) && (parameter.rfind(' ') == std::string::npos))
82 ckey.assign(parameter, 0, 32);
83 channel->SetModeParam('k', ckey.c_str(), adding);
84 channel->SetMode('k', adding);
86 return MODEACTION_ALLOW;
89 return MODEACTION_DENY;
91 else if (((channel->IsModeSet('k')) && (parameter == channel->GetModeParameter('k'))) || ((!adding) && (!IS_LOCAL(source))))
93 /* Key is currently set, and correct key was given */
94 channel->SetMode('k', adding);
95 return MODEACTION_ALLOW;
97 return MODEACTION_DENY;
101 return MODEACTION_DENY;