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() : ModeHandler(NULL, "ban", 'b', PARAM_ALWAYS, MODETYPE_CHANNEL)
33 ModeAction ModeChannelBan::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding)
35 int status = channel->GetPrefixValue(source);
36 /* Call the correct method depending on wether we're adding or removing the mode */
39 parameter = this->AddBan(source, parameter, channel, status);
43 parameter = this->DelBan(source, parameter, channel, status);
45 /* If the method above 'ate' the parameter by reducing it to an empty string, then
46 * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
47 * the return value and is always MODEACTION_DENY if the mode is supposed to have
50 return MODEACTION_ALLOW;
53 void ModeChannelBan::RemoveMode(Channel* channel, irc::modestacker* stack)
57 for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
62 for (BanList::iterator i = copy.begin(); i != copy.end(); i++)
66 stack->Push(this->GetModeChar(), i->data);
70 std::vector<std::string> parameters; parameters.push_back(channel->name); parameters.push_back("-b"); parameters.push_back(i->data);
71 ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
76 void ModeChannelBan::RemoveMode(User*, irc::modestacker* stack)
80 void ModeChannelBan::DisplayList(User* user, Channel* channel)
82 /* Display the channel banlist */
83 for (BanList::reverse_iterator i = channel->bans.rbegin(); i != channel->bans.rend(); ++i)
85 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);
87 user->WriteServ("368 %s %s :End of channel ban list",user->nick.c_str(), channel->name.c_str());
91 void ModeChannelBan::DisplayEmptyList(User* user, Channel* channel)
93 user->WriteServ("368 %s %s :End of channel ban list",user->nick.c_str(), channel->name.c_str());
96 std::string& ModeChannelBan::AddBan(User *user, std::string &dest, Channel *chan, int)
98 if ((!user) || (!chan))
100 ServerInstance->Logs->Log("MODE",DEFAULT,"*** BUG *** AddBan was given an invalid parameter");
105 /* Attempt to tidy the mask */
106 ModeParser::CleanMask(dest);
107 /* If the mask was invalid, we exit */
111 long maxbans = chan->GetMaxBans();
112 if (!IS_LOCAL(user) && ((unsigned)chan->bans.size() > (unsigned)maxbans))
114 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 ModResult MOD_RESULT;
120 FIRST_MOD_RESULT(OnAddBan, MOD_RESULT, (user,chan,dest));
121 if (MOD_RESULT == MOD_RES_DENY)
127 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
131 /* dont allow a user to set the same ban twice */
137 b.set_time = ServerInstance->Time();
138 b.data.assign(dest, 0, MAXBUF);
139 b.set_by.assign(user->nick, 0, 64);
140 chan->bans.push_back(b);
144 ModePair ModeChannelBan::ModeSet(User*, User*, Channel* channel, const std::string ¶meter)
146 for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
148 if (!strcasecmp(i->data.c_str(), parameter.c_str()))
150 return std::make_pair(true, i->data);
153 return std::make_pair(false, parameter);
156 std::string& ModeChannelBan::DelBan(User *user, std::string& dest, Channel *chan, int)
158 if ((!user) || (!chan))
160 ServerInstance->Logs->Log("MODE",DEFAULT,"*** BUG *** TakeBan was given an invalid parameter");
165 /* 'Clean' the mask, e.g. nick -> nick!*@* */
166 ModeParser::CleanMask(dest);
168 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
170 if (!strcasecmp(i->data.c_str(), dest.c_str()))
172 ModResult MOD_RESULT;
173 FIRST_MOD_RESULT(OnDelBan, MOD_RESULT, (user, chan, dest));
174 if (MOD_RESULT == MOD_RES_DENY)