]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_l.cpp
10ff3135ac71c29cb83ec33021ca71af346893e6
[user/henk/code/inspircd.git] / src / modes / cmode_l.cpp
1 #include "inspircd.h"
2 #include "mode.h"
3 #include "channels.h"
4 #include "users.h"
5 #include "modes/cmode_l.h"
6
7 ModeChannelLimit::ModeChannelLimit() : ModeHandler('l', 1, 0, false, MODETYPE_CHANNEL, false)
8 {
9 }
10
11 ModeAction ModeChannelLimit::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
12 {
13         if (adding)
14         {
15                 /* Setting a new limit, sanity check */
16                 long limit = atoi(parameter.c_str());
17
18                 /* Wrap low values at 32768 */
19                 if (limit < 0)
20                         limit = 0x7FFF;
21
22                 /* If the new limit is the same as the old limit,
23                  * and the old limit isnt 0, disallow */
24                 if ((limit == channel->limit) && (channel->limit > 0))
25                 {
26                         parameter = "";
27                         return MODEACTION_DENY;
28                 }
29
30                 /* They must have specified an invalid number.
31                  * Dont allow +l 0.
32                  */
33                 if (!limit)
34                 {
35                         parameter = "";
36                         return MODEACTION_DENY;
37                 }
38
39                 parameter = ConvToStr(limit);
40
41                 /* Set new limit */
42                 channel->limit = limit;
43                 channel->modes[CM_LIMIT] = 1;
44
45                 return MODEACTION_ALLOW;
46         }
47         else
48         {
49                 /* Check if theres a limit here to remove.
50                  * If there isnt, dont allow the -l
51                  */
52                 if (!channel->limit)
53                 {
54                         parameter = "";
55                         return MODEACTION_DENY;
56                 }
57
58                 /* Removing old limit, no checks here */
59                 channel->limit = 0;
60                 channel->modes[CM_LIMIT] = 0;
61
62                 return MODEACTION_ALLOW;
63         }
64
65         return MODEACTION_DENY;
66 }