]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_l.cpp
Allow static build of inspircd without module support
[user/henk/code/inspircd.git] / src / modes / cmode_l.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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_l.h"
19
20 ModeChannelLimit::ModeChannelLimit() : ModeHandler(NULL, "limit", 'l', PARAM_SETONLY, MODETYPE_CHANNEL)
21 {
22 }
23
24 bool ModeChannelLimit::ResolveModeConflict(std::string &their_param, const std::string &our_param, Channel*)
25 {
26         /* When TS is equal, the higher channel limit wins */
27         return (atoi(their_param.c_str()) < atoi(our_param.c_str()));
28 }
29
30 ModeAction ModeChannelLimit::OnModeChange(User*, User*, Channel* channel, std::string &parameter, bool adding)
31 {
32         if (adding)
33         {
34                 /* Setting a new limit, sanity check */
35                 long limit = atoi(parameter.c_str());
36
37                 /* Wrap low values at 32768 */
38                 if (limit < 0)
39                         limit = 0x7FFF;
40
41                 parameter = ConvToStr(limit);
42
43                 /* Set new limit */
44                 channel->SetModeParam('l', parameter);
45
46                 return MODEACTION_ALLOW;
47         }
48         else
49         {
50                 /* Check if theres a limit here to remove.
51                  * If there isnt, dont allow the -l
52                  */
53                 if (channel->GetModeParameter('l').empty())
54                 {
55                         parameter = "";
56                         return MODEACTION_DENY;
57                 }
58
59                 /* Removing old limit, no checks here */
60                 channel->SetModeParam('l', "");
61                 return MODEACTION_ALLOW;
62         }
63 }