]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_k.cpp
5e55ce972fe751af9d3d2cf8d445548b462bdb56
[user/henk/code/inspircd.git] / src / modes / cmode_k.cpp
1 #include "inspircd.h"
2 #include "mode.h"
3 #include "channels.h"
4 #include "users.h"
5 #include "modes/cmode_k.h"
6
7 ModeChannelKey::ModeChannelKey() : ModeHandler('k', 1, 1, false, MODETYPE_CHANNEL, false)
8 {
9 }
10
11 std::pair<bool,std::string> ModeChannelKey::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter)
12 {       
13         if (channel->modes[CM_KEY])
14         {
15                 return std::make_pair(true, channel->key);
16         }
17         else
18         {
19                 return std::make_pair(false, parameter);
20         }
21 }       
22
23
24 ModeAction ModeChannelKey::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
25 {
26         if ((channel->modes[CM_KEY] != adding) || (!IS_LOCAL(source)))
27         {
28                 if (((channel->modes[CM_KEY]) && (strcasecmp(parameter.c_str(),channel->key))) && (IS_LOCAL(source)))
29                 {
30                         /* Key is currently set and the correct key wasnt given */
31                         log(DEBUG,"Key Cond 2");
32                         return MODEACTION_DENY;
33                 }
34                 else if ((!channel->modes[CM_KEY]) || ((adding) && (!IS_LOCAL(source))))
35                 {
36                         /* Key isnt currently set */
37                         strlcpy(channel->key,parameter.c_str(),32);
38                         channel->modes[CM_KEY] = adding;
39                         return MODEACTION_ALLOW;
40                 }
41                 else if (((channel->modes[CM_KEY]) && (!strcasecmp(parameter.c_str(),channel->key))) || ((!adding) && (!IS_LOCAL(source))))
42                 {
43                         /* Key is currently set, and correct key was given */
44                         *channel->key = 0;
45                         channel->modes[CM_KEY] = adding;
46                         return MODEACTION_ALLOW;
47                 }
48                 log(DEBUG,"Key Cond three");
49                 return MODEACTION_DENY;
50         }
51         else
52         {
53                 log(DEBUG,"Key Condition one");
54                 return MODEACTION_DENY;
55         }
56 }