]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_b.cpp
toomanyexclamation and toomanyat are no longer required here
[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
39         if ((!user) || (!chan))
40         {
41                 log(DEFAULT,"*** BUG *** AddBan was given an invalid parameter");
42                 dest = "";
43                 return dest;
44         }
45
46         /* Attempt to tidy the mask */
47         ModeParser::CleanMask(dest);
48         /* If the mask was invalid, we exit */
49         if (dest == "")
50                 return dest;
51
52         long maxbans = GetMaxBans(chan->name);
53         if ((unsigned)chan->bans.size() > (unsigned)maxbans)
54         {
55                 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);
56                 dest = "";
57                 return dest;
58         }
59
60         int MOD_RESULT = 0;
61         FOREACH_RESULT(I_OnAddBan,OnAddBan(user,chan,dest));
62         if (MOD_RESULT)
63         {
64                 dest = "";
65                 return dest;
66         }
67
68         for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
69         {
70                 if (!strcasecmp(i->data,dest.c_str()))
71                 {
72                         /* dont allow a user to set the same ban twice */
73                         dest = "";
74                         return dest;
75                 }
76         }
77
78         b.set_time = TIME;
79         strlcpy(b.data,dest.c_str(),MAXBUF);
80         if (*user->nick)
81         {
82                 strlcpy(b.set_by,user->nick,NICKMAX-1);
83         }
84         else
85         {
86                 strlcpy(b.set_by,Config->ServerName,NICKMAX-1);
87         }
88         chan->bans.push_back(b);
89         return dest;
90 }
91
92 std::string& ModeChannelBan::DelBan(userrec *user,std::string& dest,chanrec *chan,int status)
93 {
94         if ((!user) || (!chan))
95         {
96                 log(DEFAULT,"*** BUG *** TakeBan was given an invalid parameter");
97                 dest = "";
98                 return dest;
99         }
100
101         for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
102         {
103                 if (!strcasecmp(i->data,dest.c_str()))
104                 {
105                         int MOD_RESULT = 0;
106                         FOREACH_RESULT(I_OnDelBan,OnDelBan(user,chan,dest));
107                         if (MOD_RESULT)
108                         {
109                                 dest = "";
110                                 return dest;
111                         }
112                         chan->bans.erase(i);
113                         return dest;
114                 }
115         }
116         dest = "";
117         return dest;
118 }
119