3 #include "inspircd_config.h"
4 #include "configreader.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::RemoveMode(chanrec* channel)
43 char moderemove[MAXBUF];
44 userrec* n = new userrec(ServerInstance);
45 n->SetFd(FD_MAGIC_NUMBER);
47 for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
51 for (BanList::iterator i = copy.begin(); i != copy.end(); i++)
53 sprintf(moderemove,"-%c",this->GetModeChar());
54 const char* parameters[] = { channel->name, moderemove, i->data };
55 ServerInstance->SendMode(parameters, 3, n);
61 void ModeChannelBan::RemoveMode(userrec* user)
65 void ModeChannelBan::DisplayList(userrec* user, chanrec* channel)
67 /* Display the channel banlist */
68 for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
70 user->WriteServ("367 %s %s %s %s %d",user->nick, channel->name, i->data, i->set_by, i->set_time);
72 user->WriteServ("368 %s %s :End of channel ban list",user->nick, channel->name);
76 std::string& ModeChannelBan::AddBan(userrec *user,std::string &dest,chanrec *chan,int status)
78 if ((!user) || (!chan))
80 ServerInstance->Log(DEFAULT,"*** BUG *** AddBan was given an invalid parameter");
85 /* Attempt to tidy the mask */
86 ModeParser::CleanMask(dest);
87 /* If the mask was invalid, we exit */
91 long maxbans = chan->GetMaxBans();
92 if ((unsigned)chan->bans.size() > (unsigned)maxbans)
94 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);
100 FOREACH_RESULT(I_OnAddBan,OnAddBan(user,chan,dest));
107 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
109 if (!strcasecmp(i->data,dest.c_str()))
111 /* dont allow a user to set the same ban twice */
117 b.set_time = ServerInstance->Time();
118 strlcpy(b.data,dest.c_str(),MAXBUF);
121 strlcpy(b.set_by,user->nick,NICKMAX-1);
125 strlcpy(b.set_by,ServerInstance->Config->ServerName,NICKMAX-1);
127 chan->bans.push_back(b);
131 ModePair ModeChannelBan::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
133 for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
135 if (!strcasecmp(i->data,parameter.c_str()))
137 return std::make_pair(true, i->data);
140 return std::make_pair(false, parameter);
143 std::string& ModeChannelBan::DelBan(userrec *user,std::string& dest,chanrec *chan,int status)
145 if ((!user) || (!chan))
147 ServerInstance->Log(DEFAULT,"*** BUG *** TakeBan was given an invalid parameter");
152 /* 'Clean' the mask, e.g. nick -> nick!*@* */
153 ModeParser::CleanMask(dest);
155 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
157 if (!strcasecmp(i->data,dest.c_str()))
160 FOREACH_RESULT(I_OnDelBan,OnDelBan(user,chan,dest));