X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodes%2Fcmode_b.cpp;h=e45f191f78d330a1ce280b9ec93f6827dc6611c3;hb=e6601069038c35c546fd3f3dce95024b0d13f1b4;hp=6dc7f4c370dd5400cac022b8d62e2d490002f05b;hpb=d9f48b75602a6363fc5f50c53bd1fc6d1b96e3bd;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modes/cmode_b.cpp b/src/modes/cmode_b.cpp index 6dc7f4c37..e45f191f7 100644 --- a/src/modes/cmode_b.cpp +++ b/src/modes/cmode_b.cpp @@ -1,121 +1,179 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2007 Dennis Friis + * Copyright (C) 2006 Craig Edwards + * + * 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 . + */ + + +#include "inspircd.h" #include #include #include "inspircd_config.h" #include "configreader.h" #include "hash_map.h" -#include "inspircd.h" #include "mode.h" #include "channels.h" #include "users.h" -#include "helperfuncs.h" -#include "message.h" #include "modules.h" #include "inspstring.h" #include "hashcomp.h" #include "modes/cmode_b.h" -extern InspIRCd* ServerInstance; -extern ServerConfig* Config; -extern std::vector modules; -extern std::vector factory; -extern int MODCOUNT; -extern time_t TIME; - -ModeChannelBan::ModeChannelBan() : ModeHandler('b', 1, 1, true, MODETYPE_CHANNEL, false) +ModeChannelBan::ModeChannelBan() : ModeHandler(NULL, "ban", 'b', PARAM_ALWAYS, MODETYPE_CHANNEL) { + list = true; } -ModeAction ModeChannelBan::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding) +ModeAction ModeChannelBan::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding) { - int status = cstatus(source, channel); - adding ? parameter = this->AddBan(source, parameter, channel, status) : parameter = this->DelBan(source, parameter, channel, status); + int status = channel->GetPrefixValue(source); + /* Call the correct method depending on wether we're adding or removing the mode */ + if (adding) + { + this->AddBan(source, parameter, channel, status); + } + else + { + this->DelBan(source, parameter, channel, status); + } + /* If the method above 'ate' the parameter by reducing it to an empty string, then + * it won't matter wether we return ALLOW or DENY here, as an empty string overrides + * the return value and is always MODEACTION_DENY if the mode is supposed to have + * a parameter. + */ return MODEACTION_ALLOW; } -std::string& ModeChannelBan::AddBan(userrec *user,std::string &dest,chanrec *chan,int status) +void ModeChannelBan::RemoveMode(Channel* channel, irc::modestacker* stack) +{ + BanList copy; + + for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++) + { + copy.push_back(*i); + } + + for (BanList::iterator i = copy.begin(); i != copy.end(); i++) + { + if (stack) + { + stack->Push(this->GetModeChar(), i->data); + } + else + { + std::vector parameters; parameters.push_back(channel->name); parameters.push_back("-b"); parameters.push_back(i->data); + ServerInstance->SendMode(parameters, ServerInstance->FakeClient); + } + } +} + +void ModeChannelBan::RemoveMode(User*, irc::modestacker* stack) +{ +} + +void ModeChannelBan::DisplayList(User* user, Channel* channel) { - BanItem b; - int toomanyexclamation = 0; - int toomanyat = 0; + /* 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.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.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.c_str(), channel->name.c_str()); +} + +std::string& ModeChannelBan::AddBan(User *user, std::string &dest, Channel *chan, int) +{ if ((!user) || (!chan)) { - log(DEFAULT,"*** BUG *** AddBan was given an invalid parameter"); - dest = ""; + ServerInstance->Logs->Log("MODE",DEFAULT,"*** BUG *** AddBan was given an invalid parameter"); + dest.clear(); return dest; } /* Attempt to tidy the mask */ ModeParser::CleanMask(dest); /* If the mask was invalid, we exit */ - if (dest == "") + if (dest.empty() || dest.length() > 250) return dest; - long maxbans = GetMaxBans(chan->name); - if ((unsigned)chan->bans.size() > (unsigned)maxbans) + long maxbans = chan->GetMaxBans(); + if (IS_LOCAL(user) && ((unsigned)chan->bans.size() >= (unsigned)maxbans)) { - WriteServ(user->fd,"478 %s %s :Channel ban list for %s is full (maximum entries for this channel is %d)",user->nick, chan->name,chan->name,maxbans); - dest = ""; + 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.clear(); 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 = ""; + dest.clear(); 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 = ""; + dest.clear(); return dest; } } - b.set_time = TIME; - strlcpy(b.data,dest.c_str(),MAXBUF); - if (*user->nick) - { - strlcpy(b.set_by,user->nick,NICKMAX-1); - } - else - { - strlcpy(b.set_by,Config->ServerName,NICKMAX-1); - } + b.set_time = ServerInstance->Time(); + b.data.assign(dest, 0, MAXBUF); + b.set_by.assign(user->nick, 0, 64); chan->bans.push_back(b); return dest; } -std::string& ModeChannelBan::DelBan(userrec *user,std::string& dest,chanrec *chan,int status) +std::string& ModeChannelBan::DelBan(User *user, std::string& dest, Channel *chan, int) { if ((!user) || (!chan)) { - log(DEFAULT,"*** BUG *** TakeBan was given an invalid parameter"); - dest = ""; + ServerInstance->Logs->Log("MODE",DEFAULT,"*** BUG *** TakeBan was given an invalid parameter"); + dest.clear(); return 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 = ""; + dest.clear(); return dest; } + dest = i->data; chan->bans.erase(i); return dest; } } - dest = ""; + dest.clear(); return dest; }