From 6b1f323bb519009048a94c8bb3d003288a339345 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 28 Dec 2012 15:59:33 -0500 Subject: [PATCH] Move some of CheckKick to the respective modules --- include/modules.h | 6 ++- modules/commands/cs_akick.cpp | 38 +++++++++++++++ modules/commands/cs_set.cpp | 13 +++++- modules/commands/cs_suspend.cpp | 11 ++++- modules/commands/ns_resetpass.cpp | 8 +++- src/regchannel.cpp | 77 +++++-------------------------- 6 files changed, 83 insertions(+), 70 deletions(-) diff --git a/include/modules.h b/include/modules.h index eba0138b8..cc5bb4b07 100644 --- a/include/modules.h +++ b/include/modules.h @@ -642,9 +642,11 @@ class CoreExport Module : public Extensible * @param u The user * @param ci The channel * @param kick Set to true to kick - * @return EVENT_ALLOW to stop processing immediatly + * @param mask The mask to ban, if any + * @param reason The reason for the kick + * @return EVENT_STOP to prevent the user from joining by kicking/banning the user */ - virtual EventReturn OnCheckKick(User *u, ChannelInfo *ci, bool &kick) { return EVENT_CONTINUE; } + virtual EventReturn OnCheckKick(User *u, ChannelInfo *ci, Anope::string &mask, Anope::string &reason) { return EVENT_CONTINUE; } /** Called when a user requests info for a channel * @param source The user requesting info diff --git a/modules/commands/cs_akick.cpp b/modules/commands/cs_akick.cpp index 52d0ecd76..28bc54857 100644 --- a/modules/commands/cs_akick.cpp +++ b/modules/commands/cs_akick.cpp @@ -502,6 +502,44 @@ class CSAKick : public Module { this->SetAuthor("Anope"); + Implementation i[] = { I_OnCheckKick }; + ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); + } + + EventReturn OnCheckKick(User *u, ChannelInfo *ci, Anope::string &mask, Anope::string &reason) anope_override + { + if (ci->c->MatchesList(u, CMODE_EXCEPT)) + return EVENT_CONTINUE; + + for (unsigned j = 0, end = ci->GetAkickCount(); j < end; ++j) + { + AutoKick *autokick = ci->GetAkick(j); + bool kick = false; + + if (autokick->HasFlag(AK_ISNICK)) + { + if (autokick->nc == u->Account()) + kick = true; + } + else + { + Entry akick_mask(CMODE_BEGIN, autokick->mask); + if (akick_mask.Matches(u)) + kick = true; + } + + if (kick) + { + Log(LOG_DEBUG_2) << u->nick << " matched akick " << (autokick->HasFlag(AK_ISNICK) ? autokick->nc->display : autokick->mask); + autokick->last_used = Anope::CurTime; + if (!autokick->HasFlag(AK_ISNICK)) + mask = autokick->mask; + reason = autokick->reason.empty() ? Config->CSAutokickReason : autokick->reason; + return EVENT_STOP; + } + } + + return EVENT_CONTINUE; } }; diff --git a/modules/commands/cs_set.cpp b/modules/commands/cs_set.cpp index 5ac235c8f..48cad51af 100644 --- a/modules/commands/cs_set.cpp +++ b/modules/commands/cs_set.cpp @@ -1166,7 +1166,7 @@ class CSSet : public Module { this->SetAuthor("Anope"); - Implementation i[] = { I_OnReload, I_OnChanRegistered }; + Implementation i[] = { I_OnReload, I_OnChanRegistered, I_OnCheckKick }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); this->OnReload(); @@ -1183,6 +1183,17 @@ class CSSet : public Module if (CSDefChanstats) ci->SetFlag(CI_STATS); } + + EventReturn OnCheckKick(User *u, ChannelInfo *ci, Anope::string &mask, Anope::string &reason) anope_override + { + if (!ci->HasFlag(CI_RESTRICTED) || ci->c->MatchesList(u, CMODE_EXCEPT)) + return EVENT_CONTINUE; + + if (ci->AccessFor(u).empty() && (!ci->GetFounder() || u->Account() != ci->GetFounder())) + return EVENT_STOP; + + return EVENT_CONTINUE; + } }; MODULE_INIT(CSSet) diff --git a/modules/commands/cs_suspend.cpp b/modules/commands/cs_suspend.cpp index 4f840f576..f97f761cb 100644 --- a/modules/commands/cs_suspend.cpp +++ b/modules/commands/cs_suspend.cpp @@ -216,7 +216,7 @@ class CSSuspend : public Module { this->SetAuthor("Anope"); - Implementation i[] = { I_OnPreChanExpire }; + Implementation i[] = { I_OnPreChanExpire, I_OnCheckKick }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); } @@ -250,6 +250,15 @@ class CSSuspend : public Module Log(LOG_NORMAL, "expire", ChanServ) << "Expiring suspend for " << ci->name; } } + + EventReturn OnCheckKick(User *u, ChannelInfo *ci, Anope::string &mask, Anope::string &reason) anope_override + { + if (u->HasMode(UMODE_OPER) || !ci->HasFlag(CI_SUSPENDED)) + return EVENT_CONTINUE; + + reason = Language::Translate(u, _("This channel may not be used.")); + return EVENT_STOP; + } }; MODULE_INIT(CSSuspend) diff --git a/modules/commands/ns_resetpass.cpp b/modules/commands/ns_resetpass.cpp index 39eead56e..fb4fb4ae9 100644 --- a/modules/commands/ns_resetpass.cpp +++ b/modules/commands/ns_resetpass.cpp @@ -29,7 +29,7 @@ class CommandNSResetPass : public Command { const NickAlias *na; - if (Config->RestrictMail && source.HasCommand("nickserv/resetpass")) + if (Config->RestrictMail && !source.HasCommand("nickserv/resetpass")) source.Reply(ACCESS_DENIED); else if (!(na = NickAlias::Find(params[0]))) source.Reply(NICK_X_NOT_REGISTERED, params[0].c_str()); @@ -78,6 +78,12 @@ class NSResetPass : public Module ModuleManager::Attach(I_OnPreCommand, this); } + ~NSResetPass() + { + for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + it->second->Shrink("ns_resetpass"); + } + EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector ¶ms) anope_override { if (command->name == "nickserv/confirm" && params.size() > 1) diff --git a/src/regchannel.cpp b/src/regchannel.cpp index 28c247cd9..13e0f16d5 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -945,69 +945,19 @@ bool ChannelInfo::CheckKick(User *user) if (user->IsProtected()) return false; - bool set_modes = false, do_kick = false; + Anope::string mask, reason; EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnCheckKick, OnCheckKick(user, this, do_kick)); - if (MOD_RESULT == EVENT_ALLOW) + FOREACH_RESULT(I_OnCheckKick, OnCheckKick(user, this, mask, reason)); + if (MOD_RESULT != EVENT_STOP) return false; - - Anope::string mask, reason; - if (!user->HasMode(UMODE_OPER) && this->HasFlag(CI_SUSPENDED)) - { - mask = this->GetIdealBan(user); - reason = Language::Translate(user, _("This channel may not be used.")); - set_modes = true; - do_kick = true; - } - - if (!do_kick && !this->c->MatchesList(user, CMODE_EXCEPT)) - return false; - - const NickCore *nc = user->Account() || user->IsRecognized() ? user->Account() : NULL; - - if (!do_kick) - { - for (unsigned j = 0, end = this->GetAkickCount(); j < end; ++j) - { - AutoKick *autokick = this->GetAkick(j); - - if (autokick->HasFlag(AK_ISNICK)) - { - if (autokick->nc == nc) - do_kick = true; - } - else - { - Entry akick_mask(CMODE_BEGIN, autokick->mask); - if (akick_mask.Matches(user)) - do_kick = true; - } - if (do_kick) - { - Log(LOG_DEBUG_2) << user->nick << " matched akick " << (autokick->HasFlag(AK_ISNICK) ? autokick->nc->display : autokick->mask); - autokick->last_used = Anope::CurTime; - if (autokick->HasFlag(AK_ISNICK)) - mask = this->GetIdealBan(user); - else - mask = autokick->mask; - reason = autokick->reason.empty() ? Config->CSAutokickReason : autokick->reason; - break; - } - } - } - - if (!do_kick && this->HasFlag(CI_RESTRICTED) && this->AccessFor(user).empty() && (!this->founder || user->Account() != this->founder)) - { - do_kick = true; + + if (mask.empty()) mask = this->GetIdealBan(user); + if (reason.empty()) reason = Language::Translate(user->Account(), CHAN_NOT_ALLOWED_TO_JOIN); - } - if (!do_kick) - return false; - - Log(LOG_DEBUG) << "Autokicking "<< user->GetMask() << " from " << this->name; + Log(LOG_DEBUG) << "Autokicking " << user->nick << " (" << mask << ") from " << this->name; /* If the channel isn't syncing and doesn't have any users, join ChanServ * Note that the user AND POSSIBLY the botserv bot exist here @@ -1016,14 +966,11 @@ bool ChannelInfo::CheckKick(User *user) */ if (this->c->users.size() == (this->bi && this->c->FindUser(this->bi) ? 2 : 1) && !this->c->HasFlag(CH_INHABIT) && !this->c->HasFlag(CH_SYNCING)) { - /* Set +si to prevent rejoin */ - if (set_modes) - { - c->SetMode(NULL, CMODE_NOEXTERNAL); - c->SetMode(NULL, CMODE_TOPIC); - c->SetMode(NULL, CMODE_SECRET); - c->SetMode(NULL, CMODE_INVITE); - } + /* Set +ntsi to prevent rejoin */ + c->SetMode(NULL, CMODE_NOEXTERNAL); + c->SetMode(NULL, CMODE_TOPIC); + c->SetMode(NULL, CMODE_SECRET); + c->SetMode(NULL, CMODE_INVITE); /* Join ChanServ and set a timer for this channel to part ChanServ later */ this->c->Hold();