5 #include "modes/cmode_k.h"
7 ModeChannelKey::ModeChannelKey() : ModeHandler('k', 1, 1, false, MODETYPE_CHANNEL, false)
11 std::pair<bool,std::string> 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);
24 ModeAction ModeChannelKey::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
26 if ((channel->modes[CM_KEY] != adding) || (!IS_LOCAL(source)))
28 if (((channel->modes[CM_KEY]) && (strcasecmp(parameter.c_str(),channel->key))) && (IS_LOCAL(source)))
30 /* Key is currently set and the correct key wasnt given */
31 log(DEBUG,"Key Cond 2");
32 return MODEACTION_DENY;
34 else if ((!channel->modes[CM_KEY]) || ((adding) && (!IS_LOCAL(source))))
36 /* Key isnt currently set */
37 strlcpy(channel->key,parameter.c_str(),32);
38 channel->modes[CM_KEY] = adding;
39 return MODEACTION_ALLOW;
41 else if (((channel->modes[CM_KEY]) && (!strcasecmp(parameter.c_str(),channel->key))) || ((!adding) && (!IS_LOCAL(source))))
43 /* Key is currently set, and correct key was given */
45 channel->modes[CM_KEY] = adding;
46 return MODEACTION_ALLOW;
48 log(DEBUG,"Key Cond three");
49 return MODEACTION_DENY;
53 log(DEBUG,"Key Condition one");
54 return MODEACTION_DENY;