1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
17 #include "inspircd_config.h"
18 #include "configreader.h"
24 #include "inspstring.h"
26 #include "modes/cmode_b.h"
28 ModeChannelBan::ModeChannelBan(InspIRCd* Instance) : ModeHandler(Instance, 'b', 1, 1, true, MODETYPE_CHANNEL, false)
32 ModeAction ModeChannelBan::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
34 int status = channel->GetStatus(source);
35 /* Call the correct method depending on wether we're adding or removing the mode */
38 parameter = this->AddBan(source, parameter, channel, status);
42 parameter = this->DelBan(source, parameter, channel, status);
44 /* If the method above 'ate' the parameter by reducing it to an empty string, then
45 * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
46 * the return value and is always MODEACTION_DENY if the mode is supposed to have
49 return MODEACTION_ALLOW;
52 void ModeChannelBan::RemoveMode(chanrec* channel)
55 char moderemove[MAXBUF];
56 userrec* n = new userrec(ServerInstance);
57 n->SetFd(FD_MAGIC_NUMBER);
59 for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
63 for (BanList::iterator i = copy.begin(); i != copy.end(); i++)
65 sprintf(moderemove,"-%c",this->GetModeChar());
66 const char* parameters[] = { channel->name, moderemove, i->data };
67 ServerInstance->SendMode(parameters, 3, n);
73 void ModeChannelBan::RemoveMode(userrec* user)
77 void ModeChannelBan::DisplayList(userrec* user, chanrec* channel)
79 /* Display the channel banlist */
80 for (BanList::reverse_iterator i = channel->bans.rbegin(); i != channel->bans.rend(); ++i)
82 user->WriteServ("367 %s %s %s %s %d",user->nick, channel->name, i->data, i->set_by, i->set_time);
84 user->WriteServ("368 %s %s :End of channel ban list",user->nick, channel->name);
88 std::string& ModeChannelBan::AddBan(userrec *user,std::string &dest,chanrec *chan,int status)
90 if ((!user) || (!chan))
92 ServerInstance->Log(DEFAULT,"*** BUG *** AddBan was given an invalid parameter");
97 /* Attempt to tidy the mask */
98 ModeParser::CleanMask(dest);
99 /* If the mask was invalid, we exit */
103 long maxbans = chan->GetMaxBans();
104 if ((unsigned)chan->bans.size() > (unsigned)maxbans)
106 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);
112 FOREACH_RESULT(I_OnAddBan,OnAddBan(user,chan,dest));
119 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
121 if (!strcasecmp(i->data,dest.c_str()))
123 /* dont allow a user to set the same ban twice */
129 b.set_time = ServerInstance->Time();
130 strlcpy(b.data,dest.c_str(),MAXBUF);
133 strlcpy(b.set_by,user->nick,NICKMAX-1);
137 strlcpy(b.set_by,ServerInstance->Config->ServerName,NICKMAX-1);
139 chan->bans.push_back(b);
143 ModePair ModeChannelBan::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
145 for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
147 if (!strcasecmp(i->data,parameter.c_str()))
149 return std::make_pair(true, i->data);
152 return std::make_pair(false, parameter);
155 std::string& ModeChannelBan::DelBan(userrec *user,std::string& dest,chanrec *chan,int status)
157 if ((!user) || (!chan))
159 ServerInstance->Log(DEFAULT,"*** BUG *** TakeBan was given an invalid parameter");
164 /* 'Clean' the mask, e.g. nick -> nick!*@* */
165 ModeParser::CleanMask(dest);
167 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
169 if (!strcasecmp(i->data,dest.c_str()))
172 FOREACH_RESULT(I_OnDelBan,OnDelBan(user,chan,dest));