-/* +------------------------------------+
- * | Inspire Internet Relay Chat Daemon |
- * +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
*
- * InspIRCd: (C) 2002-2008 InspIRCd Development Team
- * See: http://www.inspircd.org/wiki/index.php/Credits
+ * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
+ * Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
*
- * This program is free but copyrighted software; see
- * the file COPYING for details.
+ * This file is part of InspIRCd. InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
*
- * ---------------------------------------------------
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+
#include "inspircd.h"
#include <string>
#include <vector>
#include "hashcomp.h"
#include "modes/cmode_b.h"
-ModeChannelBan::ModeChannelBan(InspIRCd* Instance) : ModeHandler(Instance, 'b', 1, 1, true, MODETYPE_CHANNEL, false)
+ModeChannelBan::ModeChannelBan() : ModeHandler(NULL, "ban", 'b', PARAM_ALWAYS, MODETYPE_CHANNEL)
{
+ list = true;
}
-ModeAction ModeChannelBan::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding, bool servermode)
+ModeAction ModeChannelBan::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding)
{
- int status = channel->GetStatus(source);
+ int status = channel->GetPrefixValue(source);
/* Call the correct method depending on wether we're adding or removing the mode */
if (adding)
{
- parameter = this->AddBan(source, parameter, channel, status, servermode);
+ parameter = this->AddBan(source, parameter, channel, status);
}
else
{
/* Display the channel banlist */
for (BanList::reverse_iterator i = channel->bans.rbegin(); i != channel->bans.rend(); ++i)
{
- user->WriteServ("367 %s %s %s %s %lu",user->nick, channel->name, i->data, i->set_by, (unsigned long)i->set_time);
+ 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);
}
- user->WriteServ("368 %s %s :End of channel ban list",user->nick, channel->name);
+ user->WriteServ("368 %s %s :End of channel ban list",user->nick.c_str(), channel->name.c_str());
return;
}
void ModeChannelBan::DisplayEmptyList(User* user, Channel* channel)
{
- user->WriteServ("368 %s %s :End of channel ban list",user->nick, channel->name);
+ user->WriteServ("368 %s %s :End of channel ban list",user->nick.c_str(), channel->name.c_str());
}
-std::string& ModeChannelBan::AddBan(User *user, std::string &dest, Channel *chan, int, bool servermode)
+std::string& ModeChannelBan::AddBan(User *user, std::string &dest, Channel *chan, int)
{
if ((!user) || (!chan))
{
/* Attempt to tidy the mask */
ModeParser::CleanMask(dest);
/* If the mask was invalid, we exit */
- if (dest == "")
+ if (dest == "" || dest.length() > 250)
return dest;
long maxbans = chan->GetMaxBans();
- if ((unsigned)chan->bans.size() > (unsigned)maxbans)
+ if (IS_LOCAL(user) && ((unsigned)chan->bans.size() > (unsigned)maxbans))
{
- user->WriteServ("478 %s %s :Channel ban list for %s is full (maximum entries for this channel is %ld)",user->nick, chan->name,chan->name,maxbans);
+ 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);
dest = "";
return dest;
}
- int MOD_RESULT = 0;
- FOREACH_RESULT(I_OnAddBan,OnAddBan(user,chan,dest));
- if (MOD_RESULT)
+ ModResult MOD_RESULT;
+ FIRST_MOD_RESULT(OnAddBan, MOD_RESULT, (user,chan,dest));
+ if (MOD_RESULT == MOD_RES_DENY)
{
dest = "";
return dest;
for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
{
- if (!strcasecmp(i->data, dest.c_str()))
+ if (i->data == dest)
{
/* dont allow a user to set the same ban twice */
dest = "";
}
b.set_time = ServerInstance->Time();
- strlcpy(b.data, dest.c_str(), MAXBUF);
- strlcpy(b.set_by, servermode ? ServerInstance->Config->ServerName : user->nick, 63);
+ b.data.assign(dest, 0, MAXBUF);
+ b.set_by.assign(user->nick, 0, 64);
chan->bans.push_back(b);
return dest;
}
-ModePair ModeChannelBan::ModeSet(User*, User*, Channel* channel, const std::string ¶meter)
-{
- for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
- {
- if (!strcasecmp(i->data,parameter.c_str()))
- {
- return std::make_pair(true, i->data);
- }
- }
- return std::make_pair(false, parameter);
-}
-
std::string& ModeChannelBan::DelBan(User *user, std::string& dest, Channel *chan, int)
{
if ((!user) || (!chan))
return dest;
}
- /* 'Clean' the mask, e.g. nick -> nick!*@* */
- ModeParser::CleanMask(dest);
-
for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
{
- if (!strcasecmp(i->data,dest.c_str()))
+ if (!strcasecmp(i->data.c_str(), dest.c_str()))
{
- int MOD_RESULT = 0;
- FOREACH_RESULT(I_OnDelBan,OnDelBan(user,chan,dest));
- if (MOD_RESULT)
+ ModResult MOD_RESULT;
+ FIRST_MOD_RESULT(OnDelBan, MOD_RESULT, (user, chan, dest));
+ if (MOD_RESULT == MOD_RES_DENY)
{
dest = "";
return dest;