2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
5 * Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
7 * This file is part of InspIRCd. InspIRCd is free software: you can
8 * redistribute it and/or modify it under the terms of the GNU General Public
9 * License as published by the Free Software Foundation, version 2.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "inspircd_config.h"
25 #include "configreader.h"
31 #include "inspstring.h"
33 #include "modes/cmode_b.h"
35 ModeChannelBan::ModeChannelBan() : ModeHandler(NULL, "ban", 'b', PARAM_ALWAYS, MODETYPE_CHANNEL)
40 ModeAction ModeChannelBan::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding)
42 int status = channel->GetPrefixValue(source);
43 /* Call the correct method depending on wether we're adding or removing the mode */
46 this->AddBan(source, parameter, channel, status);
50 this->DelBan(source, parameter, channel, status);
52 /* If the method above 'ate' the parameter by reducing it to an empty string, then
53 * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
54 * the return value and is always MODEACTION_DENY if the mode is supposed to have
57 return MODEACTION_ALLOW;
60 void ModeChannelBan::RemoveMode(Channel* channel, irc::modestacker* stack)
64 for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
69 for (BanList::iterator i = copy.begin(); i != copy.end(); i++)
73 stack->Push(this->GetModeChar(), i->data);
77 std::vector<std::string> parameters; parameters.push_back(channel->name); parameters.push_back("-b"); parameters.push_back(i->data);
78 ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
83 void ModeChannelBan::RemoveMode(User*, irc::modestacker* stack)
87 void ModeChannelBan::DisplayList(User* user, Channel* channel)
89 /* Display the channel banlist */
90 for (BanList::reverse_iterator i = channel->bans.rbegin(); i != channel->bans.rend(); ++i)
92 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);
94 user->WriteServ("368 %s %s :End of channel ban list",user->nick.c_str(), channel->name.c_str());
98 void ModeChannelBan::DisplayEmptyList(User* user, Channel* channel)
100 user->WriteServ("368 %s %s :End of channel ban list",user->nick.c_str(), channel->name.c_str());
103 std::string& ModeChannelBan::AddBan(User *user, std::string &dest, Channel *chan, int)
105 if ((!user) || (!chan))
107 ServerInstance->Logs->Log("MODE",DEFAULT,"*** BUG *** AddBan was given an invalid parameter");
112 /* Attempt to tidy the mask */
113 ModeParser::CleanMask(dest);
114 /* If the mask was invalid, we exit */
115 if (dest.empty() || dest.length() > 250)
118 long maxbans = chan->GetMaxBans();
119 if (IS_LOCAL(user) && ((unsigned)chan->bans.size() >= (unsigned)maxbans))
121 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);
126 ModResult MOD_RESULT;
127 FIRST_MOD_RESULT(OnAddBan, MOD_RESULT, (user,chan,dest));
128 if (MOD_RESULT == MOD_RES_DENY)
134 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
138 /* dont allow a user to set the same ban twice */
144 b.set_time = ServerInstance->Time();
145 b.data.assign(dest, 0, MAXBUF);
146 b.set_by.assign(user->nick, 0, 64);
147 chan->bans.push_back(b);
151 std::string& ModeChannelBan::DelBan(User *user, std::string& dest, Channel *chan, int)
153 if ((!user) || (!chan))
155 ServerInstance->Logs->Log("MODE",DEFAULT,"*** BUG *** TakeBan was given an invalid parameter");
160 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
162 if (!strcasecmp(i->data.c_str(), dest.c_str()))
164 ModResult MOD_RESULT;
165 FIRST_MOD_RESULT(OnDelBan, MOD_RESULT, (user, chan, dest));
166 if (MOD_RESULT == MOD_RES_DENY)