1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/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(User* source, User*, Channel* channel, std::string ¶meter, bool adding, bool servermode)
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, servermode);
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(Channel* channel, irc::modestacker* stack)
56 for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
61 for (BanList::iterator i = copy.begin(); i != copy.end(); i++)
65 stack->Push(this->GetModeChar(), i->data);
69 std::vector<std::string> parameters; parameters.push_back(channel->name); parameters.push_back("-b"); parameters.push_back(i->data);
70 ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
75 void ModeChannelBan::RemoveMode(User*, irc::modestacker* stack)
79 void ModeChannelBan::DisplayList(User* user, Channel* channel)
81 /* Display the channel banlist */
82 for (BanList::reverse_iterator i = channel->bans.rbegin(); i != channel->bans.rend(); ++i)
84 user->WriteServ("367 %s %s %s %s %lu",user->nick.c_str(), channel->name.c_str(), i->data.c_str(), i->set_by.c_str(), (unsigned long)i->set_time);
86 user->WriteServ("368 %s %s :End of channel ban list",user->nick.c_str(), channel->name.c_str());
90 void ModeChannelBan::DisplayEmptyList(User* user, Channel* channel)
92 user->WriteServ("368 %s %s :End of channel ban list",user->nick.c_str(), channel->name.c_str());
95 std::string& ModeChannelBan::AddBan(User *user, std::string &dest, Channel *chan, int, bool servermode)
97 if ((!user) || (!chan))
99 ServerInstance->Logs->Log("MODE",DEFAULT,"*** BUG *** AddBan was given an invalid parameter");
104 /* Attempt to tidy the mask */
105 ModeParser::CleanMask(dest);
106 /* If the mask was invalid, we exit */
110 long maxbans = chan->GetMaxBans();
111 if (!IS_LOCAL(user) && ((unsigned)chan->bans.size() > (unsigned)maxbans))
113 user->WriteServ("478 %s %s :Channel ban list for %s is full (maximum entries for this channel is %ld)",user->nick.c_str(), chan->name.c_str(), chan->name.c_str(), maxbans);
119 FOREACH_RESULT(I_OnAddBan,OnAddBan(user,chan,dest));
126 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
130 /* dont allow a user to set the same ban twice */
136 b.set_time = ServerInstance->Time();
137 b.data.assign(dest, 0, MAXBUF);
138 b.set_by.assign(servermode ? ServerInstance->Config->ServerName : user->nick, 0, 64);
139 chan->bans.push_back(b);
143 ModePair ModeChannelBan::ModeSet(User*, User*, Channel* channel, const std::string ¶meter)
145 for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
147 if (!strcasecmp(i->data.c_str(), parameter.c_str()))
149 return std::make_pair(true, i->data);
152 return std::make_pair(false, parameter);
155 std::string& ModeChannelBan::DelBan(User *user, std::string& dest, Channel *chan, int)
157 if ((!user) || (!chan))
159 ServerInstance->Logs->Log("MODE",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.c_str(), dest.c_str()))
172 FOREACH_RESULT(I_OnDelBan,OnDelBan(user, chan, dest));