]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_l.cpp
Allow freaky stuff with +k when coming from a server or remote user (allow +k when...
[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 std::pair<bool,std::string> ModeChannelLimit::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter)
12 {
13         if (channel->limit)
14         {
15                 return std::make_pair(true, ConvToStr(channel->limit));
16         }
17         else
18         {
19                 return std::make_pair(false, parameter);
20         }
21 }
22
23 ModeAction ModeChannelLimit::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
24 {
25         if (adding)
26         {
27                 /* Setting a new limit, sanity check */
28                 long limit = atoi(parameter.c_str());
29
30                 /* Wrap low values at 32768 */
31                 if (limit < 0)
32                         limit = 0x7FFF;
33
34                 /* If the new limit is the same as the old limit,
35                  * and the old limit isnt 0, disallow */
36                 if ((limit == channel->limit) && (channel->limit > 0))
37                 {
38                         parameter = "";
39                         return MODEACTION_DENY;
40                 }
41
42                 /* They must have specified an invalid number.
43                  * Dont allow +l 0.
44                  */
45                 if (!limit)
46                 {
47                         parameter = "";
48                         return MODEACTION_DENY;
49                 }
50
51                 parameter = ConvToStr(limit);
52
53                 /* Set new limit */
54                 channel->limit = limit;
55                 channel->modes[CM_LIMIT] = 1;
56
57                 return MODEACTION_ALLOW;
58         }
59         else
60         {
61                 /* Check if theres a limit here to remove.
62                  * If there isnt, dont allow the -l
63                  */
64                 if (!channel->limit)
65                 {
66                         parameter = "";
67                         return MODEACTION_DENY;
68                 }
69
70                 /* Removing old limit, no checks here */
71                 channel->limit = 0;
72                 channel->modes[CM_LIMIT] = 0;
73
74                 return MODEACTION_ALLOW;
75         }
76
77         return MODEACTION_DENY;
78 }