]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_l.cpp
1aea53a612c84a48cad423d5de399e727270aeee
[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(InspIRCd* Instance) : ModeHandler(NULL, 'l', PARAM_SETONLY, MODETYPE_CHANNEL)
21 {
22 }
23
24 ModePair ModeChannelLimit::ModeSet(User*, User*, Channel* channel, const std::string &parameter)
25 {
26         std::string climit = channel->GetModeParameter('l');
27         if (!climit.empty())
28         {
29                 return std::make_pair(true, climit);
30         }
31         else
32         {
33                 return std::make_pair(false, parameter);
34         }
35 }
36
37 bool ModeChannelLimit::CheckTimeStamp(std::string &their_param, const std::string &our_param, Channel*)
38 {
39         /* When TS is equal, the higher channel limit wins */
40         return (atoi(their_param.c_str()) < atoi(our_param.c_str()));
41 }
42
43 ModeAction ModeChannelLimit::OnModeChange(User*, User*, Channel* channel, std::string &parameter, bool adding)
44 {
45         if (adding)
46         {
47                 /* Setting a new limit, sanity check */
48                 long limit = atoi(parameter.c_str());
49
50                 /* Wrap low values at 32768 */
51                 if (limit < 0)
52                         limit = 0x7FFF;
53
54                 parameter = ConvToStr(limit);
55
56                 /* Set new limit */
57                 channel->SetModeParam('l', parameter);
58
59                 return MODEACTION_ALLOW;
60         }
61         else
62         {
63                 /* Check if theres a limit here to remove.
64                  * If there isnt, dont allow the -l
65                  */
66                 if (channel->GetModeParameter('l').empty())
67                 {
68                         parameter = "";
69                         return MODEACTION_DENY;
70                 }
71
72                 /* Removing old limit, no checks here */
73                 channel->SetModeParam('l', "");
74                 return MODEACTION_ALLOW;
75         }
76 }