5 #include "modes/cmode_k.h"
7 ModeChannelKey::ModeChannelKey() : ModeHandler('k', 1, 1, false, MODETYPE_CHANNEL, false)
11 ModePair ModeChannelKey::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
13 if (channel->modes[CM_KEY])
15 return std::make_pair(true, channel->key);
19 return std::make_pair(false, parameter);
23 bool ModeChannelKey::CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, chanrec* channel)
25 /* When TS is equal, the alphabetically later channel key wins */
26 return (their_param < our_param);
29 ModeAction ModeChannelKey::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
31 if ((channel->modes[CM_KEY] != adding) || (!IS_LOCAL(source)))
33 if (((channel->modes[CM_KEY]) && (strcasecmp(parameter.c_str(),channel->key))) && (IS_LOCAL(source)))
35 /* Key is currently set and the correct key wasnt given */
36 log(DEBUG,"Key Cond 2");
37 return MODEACTION_DENY;
39 else if ((!channel->modes[CM_KEY]) || ((adding) && (!IS_LOCAL(source))))
41 /* Key isnt currently set */
42 strlcpy(channel->key,parameter.c_str(),32);
43 channel->modes[CM_KEY] = adding;
44 return MODEACTION_ALLOW;
46 else if (((channel->modes[CM_KEY]) && (!strcasecmp(parameter.c_str(),channel->key))) || ((!adding) && (!IS_LOCAL(source))))
48 /* Key is currently set, and correct key was given */
50 channel->modes[CM_KEY] = adding;
51 return MODEACTION_ALLOW;
53 log(DEBUG,"Key Cond three");
54 return MODEACTION_DENY;
58 log(DEBUG,"Key Condition one");
59 return MODEACTION_DENY;