]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_shun.cpp
Unite SSL service providers and SSL profile classes
[user/henk/code/inspircd.git] / src / modules / m_shun.cpp
index a06149b62d2c13cae70df5721664a6c9daed4eeb..66cc7fd58dc488e2a4585d57d76ffa9675bc1ac0 100644 (file)
@@ -23,8 +23,6 @@
 #include "inspircd.h"
 #include "xline.h"
 
-/* $ModDesc: Provides the /SHUN command, which stops a user from executing all except configured commands. */
-
 class Shun : public XLine
 {
 public:
@@ -46,6 +44,9 @@ public:
                if (InspIRCd::Match(u->GetFullHost(), matchtext) || InspIRCd::Match(u->GetFullRealHost(), matchtext) || InspIRCd::Match(u->nick+"!"+u->ident+"@"+u->GetIPString(), matchtext))
                        return true;
 
+               if (InspIRCd::MatchCIDR(u->GetIPString(), matchtext, ascii_case_insensitive_map))
+                       return true;
+
                return false;
        }
 
@@ -105,13 +106,17 @@ class CommandShun : public Command
 
                if (parameters.size() == 1)
                {
-                       if (ServerInstance->XLines->DelLine(target.c_str(), "SHUN", user))
+                       if (ServerInstance->XLines->DelLine(parameters[0].c_str(), "SHUN", user))
                        {
-                               ServerInstance->SNO->WriteToSnoMask('x',"%s removed SHUN on %s",user->nick.c_str(),target.c_str());
+                               ServerInstance->SNO->WriteToSnoMask('x', "%s removed SHUN on %s", user->nick.c_str(), parameters[0].c_str());
+                       }
+                       else if (ServerInstance->XLines->DelLine(target.c_str(), "SHUN", user))
+                       {
+                               ServerInstance->SNO->WriteToSnoMask('x',"%s removed SHUN on %s", user->nick.c_str(), target.c_str());
                        }
                        else
                        {
-                               user->WriteNotice("*** Shun " + target + " not found in list, try /stats H.");
+                               user->WriteNotice("*** Shun " + parameters[0] + " not found in list, try /stats H.");
                                return CMD_FAILURE;
                        }
                }
@@ -142,7 +147,7 @@ class CommandShun : public Command
                                else
                                {
                                        time_t c_requires_crap = duration + ServerInstance->Time();
-                                       std::string timestr = ServerInstance->TimeString(c_requires_crap);
+                                       std::string timestr = InspIRCd::TimeString(c_requires_crap);
                                        ServerInstance->SNO->WriteToSnoMask('x', "%s added timed SHUN for %s to expire on %s: %s",
                                                user->nick.c_str(), target.c_str(), timestr.c_str(), expr.c_str());
                                }
@@ -170,7 +175,7 @@ class ModuleShun : public Module
 {
        CommandShun cmd;
        ShunFactory f;
-       std::set<std::string> ShunEnabledCommands;
+       insp::flat_set<std::string> ShunEnabledCommands;
        bool NotifyOfShun;
        bool affectopers;
 
@@ -182,11 +187,6 @@ class ModuleShun : public Module
        void init() CXX11_OVERRIDE
        {
                ServerInstance->XLines->RegisterFactory(&f);
-               ServerInstance->Modules->AddService(cmd);
-
-               Implementation eventlist[] = { I_OnStats, I_OnPreCommand, I_OnRehash };
-               ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
-               OnRehash(NULL);
        }
 
        ~ModuleShun()
@@ -195,22 +195,22 @@ class ModuleShun : public Module
                ServerInstance->XLines->UnregisterFactory(&f);
        }
 
-       void Prioritize()
+       void Prioritize() CXX11_OVERRIDE
        {
                Module* alias = ServerInstance->Modules->Find("m_alias.so");
-               ServerInstance->Modules->SetPriority(this, I_OnPreCommand, PRIORITY_BEFORE, &alias);
+               ServerInstance->Modules->SetPriority(this, I_OnPreCommand, PRIORITY_BEFORE, alias);
        }
 
-       ModResult OnStats(char symbol, User* user, string_list& out) CXX11_OVERRIDE
+       ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE
        {
-               if (symbol != 'H')
+               if (stats.GetSymbol() != 'H')
                        return MOD_RES_PASSTHRU;
 
-               ServerInstance->XLines->InvokeStats("SHUN", 223, user, out);
+               ServerInstance->XLines->InvokeStats("SHUN", 223, stats);
                return MOD_RES_DENY;
        }
 
-       void OnRehash(User* user) CXX11_OVERRIDE
+       void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("shun");
                std::string cmds = tag->getString("enabledcommands");
@@ -221,10 +221,10 @@ class ModuleShun : public Module
 
                ShunEnabledCommands.clear();
 
-               std::stringstream dcmds(cmds);
+               irc::spacesepstream dcmds(cmds);
                std::string thiscmd;
 
-               while (dcmds >> thiscmd)
+               while (dcmds.GetToken(thiscmd))
                {
                        ShunEnabledCommands.insert(thiscmd);
                }
@@ -250,9 +250,7 @@ class ModuleShun : public Module
                        return MOD_RES_PASSTHRU;
                }
 
-               std::set<std::string>::iterator i = ShunEnabledCommands.find(command);
-
-               if (i == ShunEnabledCommands.end())
+               if (!ShunEnabledCommands.count(command))
                {
                        if (NotifyOfShun)
                                user->WriteNotice("*** Command " + command + " not processed, as you have been blocked from issuing commands (SHUN)");