X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_shun.cpp;h=4e7d979d1fa6d7caf95f09f71e38581e24831694;hb=b52e957bcf6a0ecadfd1785783a3c163093871f8;hp=f10ac79f57c304b5114d824f335742ba64c8f5df;hpb=5fff3610d5fe938213e98a24ed67263f8bee7a55;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_shun.cpp b/src/modules/m_shun.cpp index f10ac79f5..4e7d979d1 100644 --- a/src/modules/m_shun.cpp +++ b/src/modules/m_shun.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2019 Matt Schatz * Copyright (C) 2018 linuxdaemon * Copyright (C) 2017-2018 B00mX0r - * Copyright (C) 2013, 2017-2018 Sadie Powell + * Copyright (C) 2013, 2017-2018, 2020 Sadie Powell * Copyright (C) 2012-2016 Attila Molnar * Copyright (C) 2012, 2018-2019 Robby * Copyright (C) 2012 Jens Voss @@ -57,14 +57,13 @@ class ShunFactory : public XLineFactory } }; -//typedef std::vector shunlist; - class CommandShun : public Command { public: CommandShun(Module* Creator) : Command(Creator, "SHUN", 1, 3) { - flags_needed = 'o'; this->syntax = " [ :]"; + flags_needed = 'o'; + syntax = " [ :]"; } CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE @@ -152,11 +151,26 @@ class CommandShun : public Command class ModuleShun : public Module, public Stats::EventListener { + private: CommandShun cmd; - ShunFactory f; - insp::flat_set ShunEnabledCommands; - bool NotifyOfShun; + ShunFactory shun; + insp::flat_set enabledcommands; bool affectopers; + bool notifyuser; + + bool IsShunned(LocalUser* user) + { + // Exempt the user from shuns if they are an oper and affectopers is disabled. + if (!affectopers && user->IsOper()) + return false; + + // Exempt the user from shuns if they are an oper with the servers/ignore-shun privilege. + if (user->HasPrivPermission("servers/ignore-shun")) + return false; + + // Check whether the user is actually shunned. + return ServerInstance->XLines->MatchesLine("SHUN", user); + } public: ModuleShun() @@ -167,13 +181,13 @@ class ModuleShun : public Module, public Stats::EventListener void init() CXX11_OVERRIDE { - ServerInstance->XLines->RegisterFactory(&f); + ServerInstance->XLines->RegisterFactory(&shun); } ~ModuleShun() { ServerInstance->XLines->DelAll("SHUN"); - ServerInstance->XLines->UnregisterFactory(&f); + ServerInstance->XLines->UnregisterFactory(&shun); } void Prioritize() CXX11_OVERRIDE @@ -195,39 +209,24 @@ class ModuleShun : public Module, public Stats::EventListener { ConfigTag* tag = ServerInstance->Config->ConfValue("shun"); - ShunEnabledCommands.clear(); - irc::spacesepstream enabledcmds(tag->getString("enabledcommands", "PING PONG QUIT", 1)); + enabledcommands.clear(); + irc::spacesepstream enabledcmds(tag->getString("enabledcommands", "ADMIN OPER PING PONG QUIT", 1)); for (std::string enabledcmd; enabledcmds.GetToken(enabledcmd); ) - { - std::transform(enabledcmd.begin(), enabledcmd.end(), enabledcmd.begin(), ::toupper); - ShunEnabledCommands.insert(enabledcmd); - } + enabledcommands.insert(enabledcmd); - NotifyOfShun = tag->getBool("notifyuser", true); affectopers = tag->getBool("affectopers", false); + notifyuser = tag->getBool("notifyuser", true); } ModResult OnPreCommand(std::string& command, CommandBase::Params& parameters, LocalUser* user, bool validated) CXX11_OVERRIDE { - if (validated) + if (validated || !IsShunned(user)) return MOD_RES_PASSTHRU; - if (!ServerInstance->XLines->MatchesLine("SHUN", user)) - { - /* Not shunned, don't touch. */ - return MOD_RES_PASSTHRU; - } - - if (!affectopers && user->IsOper()) - { - /* Don't do anything if the user is an operator and affectopers isn't set */ - return MOD_RES_PASSTHRU; - } - - if (!ShunEnabledCommands.count(command)) + if (!enabledcommands.count(command)) { - if (NotifyOfShun) - user->WriteNotice("*** Command " + command + " not processed, as you have been blocked from issuing commands (SHUN)"); + if (notifyuser) + user->WriteNotice("*** " + command + " command not processed as you have been blocked from issuing commands."); return MOD_RES_DENY; } @@ -248,7 +247,7 @@ class ModuleShun : public Module, public Stats::EventListener Version GetVersion() CXX11_OVERRIDE { - return Version("Provides the SHUN command, which stops a user from executing all except configured commands", VF_VENDOR|VF_COMMON); + return Version("Adds the /SHUN command which allows server operators to prevent users from executing commands.", VF_VENDOR|VF_COMMON); } };