]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_k.cpp
Fix <disabled:umodes> interfering with /unloadmodule m_implementing_a_umode, aquanigh...
[user/henk/code/inspircd.git] / src / modes / cmode_k.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "mode.h"
16 #include "channels.h"
17 #include "users.h"
18 #include "modes/cmode_k.h"
19
20 ModeChannelKey::ModeChannelKey(InspIRCd* Instance) : ModeHandler(Instance, 'k', 1, 1, false, MODETYPE_CHANNEL, false)
21 {
22 }
23
24 ModePair ModeChannelKey::ModeSet(User*, User*, Channel* channel, const std::string &parameter)
25 {       
26     if (channel->modes[CM_KEY])
27     {
28                 std::string ckey = channel->GetModeParameter('k');
29                 return std::make_pair(true, ckey);
30     }
31     else
32     {
33                 return std::make_pair(false, parameter);
34     }
35 }
36
37 void ModeChannelKey::RemoveMode(Channel* channel, irc::modestacker* stack)
38 {
39         /** +k needs a parameter when being removed,
40          * so we have a special-case RemoveMode here for it
41          */
42
43         if (channel->IsModeSet(this->GetModeChar()))
44         {
45                 if (stack)
46                 {
47                         stack->Push(this->GetModeChar(), channel->GetModeParameter('k'));
48                 }
49                 else
50                 {
51                         std::vector<std::string> parameters; parameters.push_back(channel->name); parameters.push_back("-k"); parameters.push_back(channel->GetModeParameter('k'));
52                         ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
53                 }
54         }
55 }
56
57 void ModeChannelKey::RemoveMode(User*, irc::modestacker* stack)
58 {
59 }
60
61 bool ModeChannelKey::CheckTimeStamp(time_t, time_t, const std::string &their_param, const std::string &our_param, Channel*)
62 {
63         /* When TS is equal, the alphabetically later channel key wins */
64         return (their_param < our_param);
65 }
66
67 ModeAction ModeChannelKey::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding, bool servermode)
68 {
69         if ((channel->IsModeSet('k') != adding) || (!IS_LOCAL(source)))
70         {
71                 if (((channel->IsModeSet('k')) && (parameter != channel->GetModeParameter('k'))) && (IS_LOCAL(source)))
72                 {
73                         /* Key is currently set and the correct key wasnt given */
74                         return MODEACTION_DENY;
75                 }
76                 else if ((!channel->IsModeSet('k')) || ((adding) && (!IS_LOCAL(source))))
77                 {
78                         /* Key isnt currently set */
79                         if ((parameter.length()) && (parameter.rfind(' ') == std::string::npos))
80                         {
81                                 std::string ckey;
82                                 ckey.assign(parameter, 0, 32);
83                                 channel->SetModeParam('k', ckey.c_str(), adding);
84                                 channel->SetMode('k', adding);
85                                 parameter = ckey;
86                                 return MODEACTION_ALLOW;
87                         }
88                         else
89                                 return MODEACTION_DENY;
90                 }
91                 else if (((channel->IsModeSet('k')) && (parameter == channel->GetModeParameter('k'))) || ((!adding) && (!IS_LOCAL(source))))
92                 {
93                         /* Key is currently set, and correct key was given */
94                         channel->SetMode('k', adding);
95                         return MODEACTION_ALLOW;
96                 }
97                 return MODEACTION_DENY;
98         }
99         else
100         {
101                 return MODEACTION_DENY;
102         }
103 }
104