]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_l.cpp
1a57a440d30cb0cd3ba97cc097cd72a80a94f115
[user/henk/code/inspircd.git] / src / modes / cmode_l.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 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_l.h"
19
20 ModeChannelLimit::ModeChannelLimit(InspIRCd* Instance) : ModeHandler(Instance, 'l', 1, 0, false, MODETYPE_CHANNEL, false)
21 {
22 }
23
24 ModePair ModeChannelLimit::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter)
25 {
26         if (channel->limit)
27         {
28                 return std::make_pair(true, ConvToStr(channel->limit));
29         }
30         else
31         {
32                 return std::make_pair(false, parameter);
33         }
34 }
35
36 bool ModeChannelLimit::CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, chanrec* channel)
37 {
38         /* When TS is equal, the higher channel limit wins */
39         return (atoi(their_param.c_str()) < atoi(our_param.c_str()));
40 }
41
42 ModeAction ModeChannelLimit::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
43 {
44         if (adding)
45         {
46                 /* Setting a new limit, sanity check */
47                 long limit = atoi(parameter.c_str());
48
49                 /* Wrap low values at 32768 */
50                 if (limit < 0)
51                         limit = 0x7FFF;
52
53                 /* If the new limit is the same as the old limit,
54                  * and the old limit isnt 0, disallow */
55                 if ((limit == channel->limit) && (channel->limit > 0))
56                 {
57                         parameter = "";
58                         return MODEACTION_DENY;
59                 }
60
61                 /* They must have specified an invalid number.
62                  * Dont allow +l 0.
63                  */
64                 if (!limit)
65                 {
66                         parameter = "";
67                         return MODEACTION_DENY;
68                 }
69
70                 parameter = ConvToStr(limit);
71
72                 /* Set new limit */
73                 channel->limit = limit;
74                 channel->modes[CM_LIMIT] = 1;
75
76                 return MODEACTION_ALLOW;
77         }
78         else
79         {
80                 /* Check if theres a limit here to remove.
81                  * If there isnt, dont allow the -l
82                  */
83                 if (!channel->limit)
84                 {
85                         parameter = "";
86                         return MODEACTION_DENY;
87                 }
88
89                 /* Removing old limit, no checks here */
90                 channel->limit = 0;
91                 channel->modes[CM_LIMIT] = 0;
92
93                 return MODEACTION_ALLOW;
94         }
95
96         return MODEACTION_DENY;
97 }