3 #include "inspircd_config.h"
4 #include "configreader.h"
10 #include "helperfuncs.h"
12 #include "inspstring.h"
14 #include "modes/cmode_b.h"
16 ModeChannelBan::ModeChannelBan(InspIRCd* Instance) : ModeHandler(Instance, 'b', 1, 1, true, MODETYPE_CHANNEL, false)
20 ModeAction ModeChannelBan::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
22 int status = channel->GetStatus(source);
23 /* Call the correct method depending on wether we're adding or removing the mode */
26 parameter = this->AddBan(source, parameter, channel, status);
30 parameter = this->DelBan(source, parameter, channel, status);
32 /* If the method above 'ate' the parameter by reducing it to an empty string, then
33 * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
34 * the return value and is always MODEACTION_DENY if the mode is supposed to have
37 return MODEACTION_ALLOW;
40 void ModeChannelBan::DisplayList(userrec* user, chanrec* channel)
42 /* Display the channel banlist */
43 for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
45 user->WriteServ("367 %s %s %s %s %d",user->nick, channel->name, i->data, i->set_by, i->set_time);
47 user->WriteServ("368 %s %s :End of channel ban list",user->nick, channel->name);
51 std::string& ModeChannelBan::AddBan(userrec *user,std::string &dest,chanrec *chan,int status)
53 if ((!user) || (!chan))
55 ServerInstance->Log(DEFAULT,"*** BUG *** AddBan was given an invalid parameter");
60 /* Attempt to tidy the mask */
61 ModeParser::CleanMask(dest);
62 /* If the mask was invalid, we exit */
66 long maxbans = chan->GetMaxBans();
67 if ((unsigned)chan->bans.size() > (unsigned)maxbans)
69 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);
75 FOREACH_RESULT(I_OnAddBan,OnAddBan(user,chan,dest));
82 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
84 if (!strcasecmp(i->data,dest.c_str()))
86 /* dont allow a user to set the same ban twice */
92 b.set_time = ServerInstance->Time();
93 strlcpy(b.data,dest.c_str(),MAXBUF);
96 strlcpy(b.set_by,user->nick,NICKMAX-1);
100 strlcpy(b.set_by,ServerInstance->Config->ServerName,NICKMAX-1);
102 chan->bans.push_back(b);
106 ModePair ModeChannelBan::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
108 for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
110 if (!strcasecmp(i->data,parameter.c_str()))
112 return std::make_pair(true, i->data);
115 return std::make_pair(false, parameter);
118 std::string& ModeChannelBan::DelBan(userrec *user,std::string& dest,chanrec *chan,int status)
120 if ((!user) || (!chan))
122 ServerInstance->Log(DEFAULT,"*** BUG *** TakeBan was given an invalid parameter");
127 /* 'Clean' the mask, e.g. nick -> nick!*@* */
128 ModeParser::CleanMask(dest);
130 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
132 if (!strcasecmp(i->data,dest.c_str()))
135 FOREACH_RESULT(I_OnDelBan,OnDelBan(user,chan,dest));