3 #include "inspircd_config.h"
4 #include "configreader.h"
10 #include "helperfuncs.h"
13 #include "inspstring.h"
15 #include "modes/cmode_b.h"
17 extern InspIRCd* ServerInstance;
18 extern ServerConfig* Config;
19 extern std::vector<Module*> modules;
20 extern std::vector<ircd_module*> factory;
24 ModeChannelBan::ModeChannelBan() : ModeHandler('b', 1, 1, true, MODETYPE_CHANNEL, false)
28 ModeAction ModeChannelBan::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
30 int status = cstatus(source, channel);
31 /* Call the correct method depending on wether we're adding or removing the mode */
34 parameter = this->AddBan(source, parameter, channel, status);
38 parameter = this->DelBan(source, parameter, channel, status);
40 /* If the method above 'ate' the parameter by reducing it to an empty string, then
41 * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
42 * the return value and is always MODEACTION_DENY if the mode is supposed to have
45 return MODEACTION_ALLOW;
48 void ModeChannelBan::DisplayList(userrec* user, chanrec* channel)
50 /* Display the channel banlist */
51 for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
53 WriteServ(user->fd,"367 %s %s %s %s %d",user->nick, channel->name, i->data, i->set_by, i->set_time);
55 WriteServ(user->fd,"368 %s %s :End of channel ban list",user->nick, channel->name);
59 std::string& ModeChannelBan::AddBan(userrec *user,std::string &dest,chanrec *chan,int status)
61 if ((!user) || (!chan))
63 log(DEFAULT,"*** BUG *** AddBan was given an invalid parameter");
68 /* Attempt to tidy the mask */
69 ModeParser::CleanMask(dest);
70 /* If the mask was invalid, we exit */
74 long maxbans = GetMaxBans(chan->name);
75 if ((unsigned)chan->bans.size() > (unsigned)maxbans)
77 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);
83 FOREACH_RESULT(I_OnAddBan,OnAddBan(user,chan,dest));
90 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
92 if (!strcasecmp(i->data,dest.c_str()))
94 /* dont allow a user to set the same ban twice */
101 strlcpy(b.data,dest.c_str(),MAXBUF);
104 strlcpy(b.set_by,user->nick,NICKMAX-1);
108 strlcpy(b.set_by,Config->ServerName,NICKMAX-1);
110 chan->bans.push_back(b);
114 std::string& ModeChannelBan::DelBan(userrec *user,std::string& dest,chanrec *chan,int status)
116 if ((!user) || (!chan))
118 log(DEFAULT,"*** BUG *** TakeBan was given an invalid parameter");
123 /* 'Clean' the mask, e.g. nick -> nick!*@* */
124 ModeParser::CleanMask(dest);
126 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
128 if (!strcasecmp(i->data,dest.c_str()))
131 FOREACH_RESULT(I_OnDelBan,OnDelBan(user,chan,dest));