]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_b.cpp
Make +b use CleanMask()
[user/henk/code/inspircd.git] / src / modes / cmode_b.cpp
1 #include <string>
2 #include <vector>
3 #include "inspircd_config.h"
4 #include "configreader.h"
5 #include "hash_map.h"
6 #include "inspircd.h"
7 #include "mode.h"
8 #include "channels.h"
9 #include "users.h"
10 #include "helperfuncs.h"
11 #include "message.h"
12 #include "modules.h"
13 #include "inspstring.h"
14 #include "hashcomp.h"
15 #include "modes/cmode_b.h"
16
17 extern InspIRCd* ServerInstance;
18 extern ServerConfig* Config;
19 extern std::vector<Module*> modules;
20 extern std::vector<ircd_module*> factory;
21 extern int MODCOUNT;
22 extern time_t TIME;
23
24 ModeChannelBan::ModeChannelBan() : ModeHandler('b', 1, 1, true, MODETYPE_CHANNEL, false)
25 {
26 }
27
28 ModeAction ModeChannelBan::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
29 {
30         int status = cstatus(source, channel);
31         adding ? parameter = this->AddBan(source, parameter, channel, status) : parameter = this->DelBan(source, parameter, channel, status);
32         return MODEACTION_ALLOW;
33 }
34
35 std::string& ModeChannelBan::AddBan(userrec *user,std::string &dest,chanrec *chan,int status)
36 {
37         BanItem b;
38         int toomanyexclamation = 0;
39         int toomanyat = 0;
40
41         if ((!user) || (!chan))
42         {
43                 log(DEFAULT,"*** BUG *** AddBan was given an invalid parameter");
44                 dest = "";
45                 return dest;
46         }
47
48         /* Attempt to tidy the mask */
49         ModeParser::CleanMask(dest);
50         /* If the mask was invalid, we exit */
51         if (dest == "")
52                 return dest;
53
54         long maxbans = GetMaxBans(chan->name);
55         if ((unsigned)chan->bans.size() > (unsigned)maxbans)
56         {
57                 WriteServ(user->fd,"478 %s %s :Channel ban list for %s is full (maximum entries for this channel is %d)",user->nick, chan->name,chan->name,maxbans);
58                 dest = "";
59                 return dest;
60         }
61
62         int MOD_RESULT = 0;
63         FOREACH_RESULT(I_OnAddBan,OnAddBan(user,chan,dest));
64         if (MOD_RESULT)
65         {
66                 dest = "";
67                 return dest;
68         }
69
70         for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
71         {
72                 if (!strcasecmp(i->data,dest.c_str()))
73                 {
74                         /* dont allow a user to set the same ban twice */
75                         dest = "";
76                         return dest;
77                 }
78         }
79
80         b.set_time = TIME;
81         strlcpy(b.data,dest.c_str(),MAXBUF);
82         if (*user->nick)
83         {
84                 strlcpy(b.set_by,user->nick,NICKMAX-1);
85         }
86         else
87         {
88                 strlcpy(b.set_by,Config->ServerName,NICKMAX-1);
89         }
90         chan->bans.push_back(b);
91         return dest;
92 }
93
94 std::string& ModeChannelBan::DelBan(userrec *user,std::string& dest,chanrec *chan,int status)
95 {
96         if ((!user) || (!chan))
97         {
98                 log(DEFAULT,"*** BUG *** TakeBan was given an invalid parameter");
99                 dest = "";
100                 return dest;
101         }
102
103         for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
104         {
105                 if (!strcasecmp(i->data,dest.c_str()))
106                 {
107                         int MOD_RESULT = 0;
108                         FOREACH_RESULT(I_OnDelBan,OnDelBan(user,chan,dest));
109                         if (MOD_RESULT)
110                         {
111                                 dest = "";
112                                 return dest;
113                         }
114                         chan->bans.erase(i);
115                         return dest;
116                 }
117         }
118         dest = "";
119         return dest;
120 }
121