3 #include "inspircd_config.h"
4 #include "configreader.h"
10 #include "helperfuncs.h"
12 #include "inspstring.h"
14 #include "modes/cmode_b.h"
18 ModeChannelBan::ModeChannelBan(InspIRCd* Instance) : ModeHandler(Instance, 'b', 1, 1, true, MODETYPE_CHANNEL, false)
22 ModeAction ModeChannelBan::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
24 int status = channel->GetStatus(source);
25 /* Call the correct method depending on wether we're adding or removing the mode */
28 parameter = this->AddBan(source, parameter, channel, status);
32 parameter = this->DelBan(source, parameter, channel, status);
34 /* If the method above 'ate' the parameter by reducing it to an empty string, then
35 * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
36 * the return value and is always MODEACTION_DENY if the mode is supposed to have
39 return MODEACTION_ALLOW;
42 void ModeChannelBan::DisplayList(userrec* user, chanrec* channel)
44 /* Display the channel banlist */
45 for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
47 user->WriteServ("367 %s %s %s %s %d",user->nick, channel->name, i->data, i->set_by, i->set_time);
49 user->WriteServ("368 %s %s :End of channel ban list",user->nick, channel->name);
53 std::string& ModeChannelBan::AddBan(userrec *user,std::string &dest,chanrec *chan,int status)
55 if ((!user) || (!chan))
57 log(DEFAULT,"*** BUG *** AddBan was given an invalid parameter");
62 /* Attempt to tidy the mask */
63 ModeParser::CleanMask(dest);
64 /* If the mask was invalid, we exit */
68 long maxbans = chan->GetMaxBans();
69 if ((unsigned)chan->bans.size() > (unsigned)maxbans)
71 user->WriteServ("478 %s %s :Channel ban list for %s is full (maximum entries for this channel is %d)",user->nick, chan->name,chan->name,maxbans);
77 FOREACH_RESULT(I_OnAddBan,OnAddBan(user,chan,dest));
84 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
86 if (!strcasecmp(i->data,dest.c_str()))
88 /* dont allow a user to set the same ban twice */
95 strlcpy(b.data,dest.c_str(),MAXBUF);
98 strlcpy(b.set_by,user->nick,NICKMAX-1);
102 strlcpy(b.set_by,ServerInstance->Config->ServerName,NICKMAX-1);
104 chan->bans.push_back(b);
108 ModePair ModeChannelBan::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
110 for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
112 if (!strcasecmp(i->data,parameter.c_str()))
114 return std::make_pair(true, i->data);
117 return std::make_pair(false, parameter);
120 std::string& ModeChannelBan::DelBan(userrec *user,std::string& dest,chanrec *chan,int status)
122 if ((!user) || (!chan))
124 log(DEFAULT,"*** BUG *** TakeBan was given an invalid parameter");
129 /* 'Clean' the mask, e.g. nick -> nick!*@* */
130 ModeParser::CleanMask(dest);
132 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
134 if (!strcasecmp(i->data,dest.c_str()))
137 FOREACH_RESULT(I_OnDelBan,OnDelBan(user,chan,dest));