]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_rline.cpp
Rename User::fullname to realname and make it private.
[user/henk/code/inspircd.git] / src / modules / m_rline.cpp
index 01d8b753a23ac7bf2b83be83b2ed6bcd1980bfa9..bf6a64d84ce3398ff62d4d13575d54489b172a4a 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "inspircd.h"
 #include "modules/regex.h"
+#include "modules/stats.h"
 #include "xline.h"
 
 static bool ZlineOnMatch = false;
@@ -56,29 +57,30 @@ class RLine : public XLine
                delete regex;
        }
 
-       bool Matches(User *u)
+       bool Matches(User* u) CXX11_OVERRIDE
        {
                LocalUser* lu = IS_LOCAL(u);
                if (lu && lu->exempt)
                        return false;
 
-               std::string compare = u->nick + "!" + u->ident + "@" + u->host + " " + u->fullname;
-               return regex->Matches(compare);
+               const std::string host = u->nick + "!" + u->ident + "@" + u->GetRealHost() + " " + u->GetRealName();
+               const std::string ip = u->nick + "!" + u->ident + "@" + u->GetIPString() + " " + u->GetRealName();
+               return (regex->Matches(host) || regex->Matches(ip));
        }
 
-       bool Matches(const std::string &compare)
+       bool Matches(const std::string& compare) CXX11_OVERRIDE
        {
                return regex->Matches(compare);
        }
 
-       void Apply(User* u)
+       void Apply(User* u) CXX11_OVERRIDE
        {
                if (ZlineOnMatch)
                {
                        ZLine* zl = new ZLine(ServerInstance->Time(), duration ? expiry - ServerInstance->Time() : 0, ServerInstance->Config->ServerName.c_str(), reason.c_str(), u->GetIPString());
                        if (ServerInstance->XLines->AddLine(zl, NULL))
                        {
-                               std::string timestr = ServerInstance->TimeString(zl->expiry);
+                               std::string timestr = InspIRCd::TimeString(zl->expiry);
                                ServerInstance->SNO->WriteToSnoMask('x', "Z-line added due to R-line match on *@%s%s%s: %s",
                                        zl->ipaddr.c_str(), zl->duration ? " to expire on " : "", zl->duration ? timestr.c_str() : "", zl->reason.c_str());
                                added_zline = true;
@@ -89,7 +91,7 @@ class RLine : public XLine
                DefaultApply(u, "R", false);
        }
 
-       const std::string& Displayable()
+       const std::string& Displayable() CXX11_OVERRIDE
        {
                return matchtext;
        }
@@ -112,7 +114,7 @@ class RLineFactory : public XLineFactory
 
        /** Generate a RLine
         */
-       XLine* Generate(time_t set_time, long duration, std::string source, std::string reason, std::string xline_specific_mask)
+       XLine* Generate(time_t set_time, long duration, std::string source, std::string reason, std::string xline_specific_mask) CXX11_OVERRIDE
        {
                if (!rxfactory)
                {
@@ -138,7 +140,7 @@ class CommandRLine : public Command
                flags_needed = 'o'; this->syntax = "<regex> [<rline-duration>] :<reason>";
        }
 
-       CmdResult Handle (const std::vector<std::string>& parameters, User *user)
+       CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
        {
 
                if (parameters.size() >= 3)
@@ -154,7 +156,7 @@ class CommandRLine : public Command
                        }
                        catch (ModuleException &e)
                        {
-                               ServerInstance->SNO->WriteToSnoMask('a',"Could not add RLINE: %s", e.GetReason());
+                               ServerInstance->SNO->WriteToSnoMask('a',"Could not add RLINE: " + e.GetReason());
                        }
 
                        if (r)
@@ -168,7 +170,7 @@ class CommandRLine : 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 R-line for %s to expire on %s: %s", user->nick.c_str(), parameters[0].c_str(), timestr.c_str(), parameters[2].c_str());
                                        }
 
@@ -196,7 +198,7 @@ class CommandRLine : public Command
                return CMD_SUCCESS;
        }
 
-       RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
+       RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
        {
                if (IS_LOCAL(user))
                        return ROUTE_LOCALONLY; // spanningtree will send ADDLINE
@@ -205,7 +207,7 @@ class CommandRLine : public Command
        }
 };
 
-class ModuleRLine : public Module
+class ModuleRLine : public Module, public Stats::EventListener
 {
        dynamic_reference<RegexFactory> rxfactory;
        RLineFactory f;
@@ -216,14 +218,16 @@ class ModuleRLine : public Module
 
  public:
        ModuleRLine()
-               : rxfactory(this, "regex"), f(rxfactory), r(this, f)
+               : Stats::EventListener(this)
+               , rxfactory(this, "regex")
+               , f(rxfactory)
+               , r(this, f)
                , initing(true)
        {
        }
 
        void init() CXX11_OVERRIDE
        {
-               ServerInstance->Modules->AddService(r);
                ServerInstance->XLines->RegisterFactory(&f);
        }
 
@@ -285,12 +289,12 @@ class ModuleRLine : public Module
                initing = false;
        }
 
-       ModResult OnStats(char symbol, User* user, string_list &results) CXX11_OVERRIDE
+       ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE
        {
-               if (symbol != 'R')
+               if (stats.GetSymbol() != 'R')
                        return MOD_RES_PASSTHRU;
 
-               ServerInstance->XLines->InvokeStats("R", 223, user, results);
+               ServerInstance->XLines->InvokeStats("R", 223, stats);
                return MOD_RES_DENY;
        }
 
@@ -334,7 +338,7 @@ class ModuleRLine : public Module
                }
        }
 
-       void Prioritize()
+       void Prioritize() CXX11_OVERRIDE
        {
                Module* mod = ServerInstance->Modules->Find("m_cgiirc.so");
                ServerInstance->Modules->SetPriority(this, I_OnUserRegister, PRIORITY_AFTER, mod);