From a810c07ccf85cc3eb0ea7de3c1391ea287fa4fa7 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Wed, 13 Apr 2022 00:17:36 +0100 Subject: [PATCH] Remove FPART, force REMOVE to always use the new syntax. FPART was deprecated in v3 when the parameters for REMOVE were switched. This does not need any compat layer changes as v3 always forwarded FPART as REMOVE. --- docs/conf/helpop.conf.example | 21 +++----- docs/conf/modules.conf.example | 3 +- src/modules/m_remove.cpp | 98 ++++++++-------------------------- 3 files changed, 30 insertions(+), 92 deletions(-) diff --git a/docs/conf/helpop.conf.example b/docs/conf/helpop.conf.example index b57809110..163ef86e1 100644 --- a/docs/conf/helpop.conf.example +++ b/docs/conf/helpop.conf.example @@ -30,14 +30,14 @@ parameter for this command. - - # # supportnokicks: If yes, /REMOVE is not allowed on channels where the diff --git a/src/modules/m_remove.cpp b/src/modules/m_remove.cpp index 0369ec25b..8e13fb1b5 100644 --- a/src/modules/m_remove.cpp +++ b/src/modules/m_remove.cpp @@ -31,55 +31,40 @@ #include "inspircd.h" #include "modules/isupport.h" -/* - * This module supports the use of the +q and +a usermodes, but should work without them too. - * Usage of the command is restricted to +hoaq, and you cannot remove a user with a "higher" level than yourself. - * eg: +h can remove +hv and users with no modes. +a can remove +aohv and users with no modes. -*/ - -/** Base class for /FPART and /REMOVE - */ -class RemoveBase +class CommandRemove final : public Command { - bool& supportnokicks; - ChanModeReference& nokicksmode; +private: + ChanModeReference nokicksmode; public: unsigned long protectedrank; + bool supportnokicks; - RemoveBase(Module* Creator, bool& snk, ChanModeReference& nkm, const char* cmdn) - : Command(Creator, cmdn, 2, 3) - , supportnokicks(snk) - , nokicksmode(nkm) + CommandRemove(Module* Creator) + : Command(Creator, "REMOVE", 2, 3) + , nokicksmode(Creator, "nokick") { + syntax = { " [:]" }; + translation = { TR_TEXT, TR_NICK, TR_TEXT }; } - CmdResult HandleRMB(User* user, const CommandBase::Params& parameters, bool fpart) + CmdResult Handle(User* user, const CommandBase::Params& parameters) override { - User* target; - Channel* channel; - std::string reason; - - // If the command is a /REMOVE then detect the parameter order - bool neworder = (fpart || ServerInstance->Channels.IsPrefix(parameters[0][0])); - - /* Set these to the parameters needed, the new version of this module switches it's parameters around - * supplying a new command with the new order while keeping the old /remove with the older order. - * /remove [reason ...] - * /fpart [reason ...] - */ + // Keep compatibility with v3 servers by allowing them to send removes with the old order. + bool neworder = !IS_LOCAL(user) && ServerInstance->Channels.IsPrefix(parameters[0][0]); const std::string& channame = parameters[neworder ? 0 : 1]; const std::string& username = parameters[neworder ? 1 : 0]; /* Look up the user we're meant to be removing from the channel */ + User* target; if (IS_LOCAL(user)) target = ServerInstance->Users.FindNick(username); else target = ServerInstance->Users.Find(username); /* And the channel we're meant to be removing them from */ - channel = ServerInstance->Channels.Find(channame); + Channel* channel = ServerInstance->Channels.Find(channame); /* Fix by brain - someone needs to learn to validate their input! */ if (!channel) @@ -120,11 +105,9 @@ public: // REMOVE will be sent to the target's server and it will reply with a PART (or do nothing if it doesn't understand the command) if (!IS_LOCAL(target)) { - // Send an ENCAP REMOVE with parameters being in the old order which is - // compatible with both 2.0 and 3.0. This also turns FPART into REMOVE. CommandBase::Params p; - p.push_back(target->uuid); p.push_back(channel->name); + p.push_back(target->uuid); if (parameters.size() > 2) p.push_back(":" + parameters[2]); ServerInstance->PI->SendEncapsulatedData(target->server->GetName(), "REMOVE", p, user); @@ -141,7 +124,7 @@ public: reasonparam = "No reason given"; /* Build up the part reason string. */ - reason = "Removed by " + user->nick + ": " + reasonparam; + std::string reason = "Removed by " + user->nick + ": " + reasonparam; channel->WriteRemoteNotice(InspIRCd::Format("%s removed %s from the channel", user->nick.c_str(), target->nick.c_str())); target->WriteNotice("*** " + user->nick + " removed you from " + channel->name + " with the message: " + reasonparam); @@ -165,57 +148,18 @@ public: } }; -class CommandRemove final - : public RemoveBase -{ -public: - CommandRemove(Module* Creator, bool& snk, ChanModeReference& nkm) - : RemoveBase(Creator, snk, nkm, "REMOVE") - { - syntax = { " [:]" }; - translation = { TR_NICK, TR_TEXT, TR_TEXT }; - } - - CmdResult Handle(User* user, const Params& parameters) override - { - return HandleRMB(user, parameters, false); - } -}; - -class CommandFpart final - : public RemoveBase -{ -public: - CommandFpart(Module* Creator, bool& snk, ChanModeReference& nkm) - : RemoveBase(Creator, snk, nkm, "FPART") - { - syntax = { " [:]" }; - translation = { TR_TEXT, TR_NICK, TR_TEXT }; - } - - CmdResult Handle(User* user, const Params& parameters) override - { - return HandleRMB(user, parameters, true); - } -}; - class ModuleRemove final : public Module , public ISupport::EventListener { private: - ChanModeReference nokicksmode; - CommandRemove cmd1; - CommandFpart cmd2; - bool supportnokicks; + CommandRemove cmd; public: ModuleRemove() - : Module(VF_VENDOR | VF_OPTCOMMON, "Adds the /FPART and /REMOVE commands which allows channel operators to force part users from a channel.") + : Module(VF_VENDOR | VF_OPTCOMMON, "Adds the /REMOVE command which allows channel operators to force part users from a channel.") , ISupport::EventListener(this) - , nokicksmode(this, "nokick") - , cmd1(this, supportnokicks, nokicksmode) - , cmd2(this, supportnokicks, nokicksmode) + , cmd(this) { } @@ -227,8 +171,8 @@ public: void ReadConfig(ConfigStatus& status) override { auto tag = ServerInstance->Config->ConfValue("remove"); - supportnokicks = tag->getBool("supportnokicks"); - cmd1.protectedrank = cmd2.protectedrank = tag->getUInt("protectedrank", 50000); + cmd.supportnokicks = tag->getBool("supportnokicks"); + cmd.protectedrank = tag->getUInt("protectedrank", 50000); } };