]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_l.cpp
Mode merging during FJOIN with ourts==theirts. Only +k and +l have CheckTimestamp...
[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 bool ModeChannelLimit::CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, chanrec* channel)
24 {
25         /* When TS is equal, the higher channel limit wins */
26         return (atoi(their_param.c_str()) < atoi(our_param.c_str()));
27 }
28
29 ModeAction ModeChannelLimit::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
30 {
31         if (adding)
32         {
33                 /* Setting a new limit, sanity check */
34                 long limit = atoi(parameter.c_str());
35
36                 /* Wrap low values at 32768 */
37                 if (limit < 0)
38                         limit = 0x7FFF;
39
40                 /* If the new limit is the same as the old limit,
41                  * and the old limit isnt 0, disallow */
42                 if ((limit == channel->limit) && (channel->limit > 0))
43                 {
44                         parameter = "";
45                         return MODEACTION_DENY;
46                 }
47
48                 /* They must have specified an invalid number.
49                  * Dont allow +l 0.
50                  */
51                 if (!limit)
52                 {
53                         parameter = "";
54                         return MODEACTION_DENY;
55                 }
56
57                 parameter = ConvToStr(limit);
58
59                 /* Set new limit */
60                 channel->limit = limit;
61                 channel->modes[CM_LIMIT] = 1;
62
63                 return MODEACTION_ALLOW;
64         }
65         else
66         {
67                 /* Check if theres a limit here to remove.
68                  * If there isnt, dont allow the -l
69                  */
70                 if (!channel->limit)
71                 {
72                         parameter = "";
73                         return MODEACTION_DENY;
74                 }
75
76                 /* Removing old limit, no checks here */
77                 channel->limit = 0;
78                 channel->modes[CM_LIMIT] = 0;
79
80                 return MODEACTION_ALLOW;
81         }
82
83         return MODEACTION_DENY;
84 }