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
41 char moderemove[MAXBUF];
42 const char* parameters[] = { channel->name, moderemove, channel->key };
44 if (channel->IsModeSet(this->GetModeChar()))
47 stack->Push(this->GetModeChar(), channel->key);
50 sprintf(moderemove,"-%c",this->GetModeChar());
51 ServerInstance->SendMode(parameters, 3, ServerInstance->FakeClient);
56 void ModeChannelKey::RemoveMode(User*, irc::modestacker* stack)
60 bool ModeChannelKey::CheckTimeStamp(time_t, time_t, const std::string &their_param, const std::string &our_param, Channel*)
62 /* When TS is equal, the alphabetically later channel key wins */
63 return (their_param < our_param);
66 ModeAction ModeChannelKey::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding, bool servermode)
68 if ((channel->modes[CM_KEY] != adding) || (!IS_LOCAL(source)))
70 if (((channel->modes[CM_KEY]) && (strcasecmp(parameter.c_str(),channel->key))) && (IS_LOCAL(source)))
72 /* Key is currently set and the correct key wasnt given */
73 return MODEACTION_DENY;
75 else if ((!channel->modes[CM_KEY]) || ((adding) && (!IS_LOCAL(source))))
77 /* Key isnt currently set */
78 if ((parameter.length()) && (parameter.rfind(' ') == std::string::npos))
80 strlcpy(channel->key,parameter.c_str(),32);
81 channel->modes[CM_KEY] = adding;
82 parameter = channel->key;
83 return MODEACTION_ALLOW;
86 return MODEACTION_DENY;
88 else if (((channel->modes[CM_KEY]) && (!strcasecmp(parameter.c_str(),channel->key))) || ((!adding) && (!IS_LOCAL(source))))
90 /* Key is currently set, and correct key was given */
92 channel->modes[CM_KEY] = adding;
93 return MODEACTION_ALLOW;
95 return MODEACTION_DENY;
99 return MODEACTION_DENY;