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)
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()))
46 sprintf(moderemove,"-%c",this->GetModeChar());
47 ServerInstance->SendMode(parameters, 3, ServerInstance->FakeClient);
51 void ModeChannelKey::RemoveMode(User*)
55 bool ModeChannelKey::CheckTimeStamp(time_t, time_t, const std::string &their_param, const std::string &our_param, Channel*)
57 /* When TS is equal, the alphabetically later channel key wins */
58 return (their_param < our_param);
61 ModeAction ModeChannelKey::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding, bool servermode)
63 if ((channel->modes[CM_KEY] != adding) || (!IS_LOCAL(source)))
65 if (((channel->modes[CM_KEY]) && (strcasecmp(parameter.c_str(),channel->key))) && (IS_LOCAL(source)))
67 /* Key is currently set and the correct key wasnt given */
68 return MODEACTION_DENY;
70 else if ((!channel->modes[CM_KEY]) || ((adding) && (!IS_LOCAL(source))))
72 /* Key isnt currently set */
73 if ((parameter.length()) && (parameter.rfind(' ') == std::string::npos))
75 strlcpy(channel->key,parameter.c_str(),32);
76 channel->modes[CM_KEY] = adding;
77 parameter = channel->key;
78 return MODEACTION_ALLOW;
81 return MODEACTION_DENY;
83 else if (((channel->modes[CM_KEY]) && (!strcasecmp(parameter.c_str(),channel->key))) || ((!adding) && (!IS_LOCAL(source))))
85 /* Key is currently set, and correct key was given */
87 channel->modes[CM_KEY] = adding;
88 return MODEACTION_ALLOW;
90 return MODEACTION_DENY;
94 return MODEACTION_DENY;