1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 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 return std::make_pair(true, channel->key);
32 return std::make_pair(false, parameter);
36 void ModeChannelKey::RemoveMode(Channel* channel, irc::modestacker* stack)
38 /** +k needs a parameter when being removed,
39 * so we have a special-case RemoveMode here for it
42 if (channel->IsModeSet(this->GetModeChar()))
45 stack->Push(this->GetModeChar(), channel->key);
48 std::vector<std::string> parameters; parameters.push_back(channel->name); parameters.push_back("-k"); parameters.push_back(channel->key);
49 ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
54 void ModeChannelKey::RemoveMode(User*, irc::modestacker* stack)
58 bool ModeChannelKey::CheckTimeStamp(time_t, time_t, const std::string &their_param, const std::string &our_param, Channel*)
60 /* When TS is equal, the alphabetically later channel key wins */
61 return (their_param < our_param);
64 ModeAction ModeChannelKey::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding, bool servermode)
66 if ((channel->modes[CM_KEY] != adding) || (!IS_LOCAL(source)))
68 if (((channel->modes[CM_KEY]) && (strcasecmp(parameter.c_str(),channel->key))) && (IS_LOCAL(source)))
70 /* Key is currently set and the correct key wasnt given */
71 return MODEACTION_DENY;
73 else if ((!channel->modes[CM_KEY]) || ((adding) && (!IS_LOCAL(source))))
75 /* Key isnt currently set */
76 if ((parameter.length()) && (parameter.rfind(' ') == std::string::npos))
78 strlcpy(channel->key,parameter.c_str(),32);
79 channel->modes[CM_KEY] = adding;
80 parameter = channel->key;
81 return MODEACTION_ALLOW;
84 return MODEACTION_DENY;
86 else if (((channel->modes[CM_KEY]) && (!strcasecmp(parameter.c_str(),channel->key))) || ((!adding) && (!IS_LOCAL(source))))
88 /* Key is currently set, and correct key was given */
90 channel->modes[CM_KEY] = adding;
91 return MODEACTION_ALLOW;
93 return MODEACTION_DENY;
97 return MODEACTION_DENY;