1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
#include <string>
#include <vector>
#include "inspircd_config.h"
#include "configreader.h"
#include "hash_map.h"
#include "inspircd.h"
#include "mode.h"
#include "channels.h"
#include "users.h"
#include "helperfuncs.h"
#include "message.h"
#include "modules.h"
#include "inspstring.h"
#include "hashcomp.h"
#include "modes/cmode_b.h"
extern InspIRCd* ServerInstance;
extern ServerConfig* Config;
extern std::vector<Module*> modules;
extern std::vector<ircd_module*> factory;
extern int MODCOUNT;
extern time_t TIME;
ModeChannelBan::ModeChannelBan() : ModeHandler('b', 1, 1, true, MODETYPE_CHANNEL, false)
{
}
ModeAction ModeChannelBan::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
{
int status = cstatus(source, channel);
/* Call the correct method depending on wether we're adding or removing the mode */
if (adding)
{
parameter = this->AddBan(source, parameter, channel, status);
}
else
{
parameter = this->DelBan(source, parameter, channel, status);
}
/* If the method above 'ate' the parameter by reducing it to an empty string, then
* it won't matter wether we return ALLOW or DENY here, as an empty string overrides
* the return value and is always MODEACTION_DENY if the mode is supposed to have
* a parameter.
*/
return MODEACTION_ALLOW;
}
void ModeChannelBan::DisplayList(userrec* user, chanrec* channel)
{
/* Display the channel banlist */
for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
{
WriteServ(user->fd,"367 %s %s %s %s %d",user->nick, channel->name, i->data, i->set_by, i->set_time);
}
WriteServ(user->fd,"368 %s %s :End of channel ban list",user->nick, channel->name);
return;
}
std::string& ModeChannelBan::AddBan(userrec *user,std::string &dest,chanrec *chan,int status)
{
if ((!user) || (!chan))
{
log(DEFAULT,"*** BUG *** AddBan was given an invalid parameter");
dest = "";
return dest;
}
/* Attempt to tidy the mask */
ModeParser::CleanMask(dest);
/* If the mask was invalid, we exit */
if (dest == "")
return dest;
long maxbans = GetMaxBans(chan->name);
if ((unsigned)chan->bans.size() > (unsigned)maxbans)
{
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);
dest = "";
return dest;
}
int MOD_RESULT = 0;
FOREACH_RESULT(I_OnAddBan,OnAddBan(user,chan,dest));
if (MOD_RESULT)
{
dest = "";
return dest;
}
for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
{
if (!strcasecmp(i->data,dest.c_str()))
{
/* dont allow a user to set the same ban twice */
dest = "";
return dest;
}
}
b.set_time = TIME;
strlcpy(b.data,dest.c_str(),MAXBUF);
if (*user->nick)
{
strlcpy(b.set_by,user->nick,NICKMAX-1);
}
else
{
strlcpy(b.set_by,Config->ServerName,NICKMAX-1);
}
chan->bans.push_back(b);
return dest;
}
std::string& ModeChannelBan::DelBan(userrec *user,std::string& dest,chanrec *chan,int status)
{
if ((!user) || (!chan))
{
log(DEFAULT,"*** BUG *** TakeBan was given an invalid parameter");
dest = "";
return dest;
}
/* 'Clean' the mask, e.g. nick -> nick!*@* */
ModeParser::CleanMask(dest);
for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
{
if (!strcasecmp(i->data,dest.c_str()))
{
int MOD_RESULT = 0;
FOREACH_RESULT(I_OnDelBan,OnDelBan(user,chan,dest));
if (MOD_RESULT)
{
dest = "";
return dest;
}
chan->bans.erase(i);
return dest;
}
}
dest = "";
return dest;
}
|