]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_cban.cpp
Initial support for listening on UNIX socket endpoints.
[user/henk/code/inspircd.git] / src / modules / m_cban.cpp
index 4fb0653a91b1014e6da68ff377f9d17dfa5947df..7235a8befa3d186aca0d82882b7bddf8121d003b 100644 (file)
 
 #include "inspircd.h"
 #include "xline.h"
+#include "modules/stats.h"
 
 /** Holds a CBAN item
  */
 class CBan : public XLine
 {
 private:
-       std::string displaytext;
-       irc::string matchtext;
+       std::string matchtext;
 
 public:
        CBan(time_t s_time, long d, const std::string& src, const std::string& re, const std::string& ch)
                : XLine(s_time, d, src, re, "CBAN")
+               , matchtext(ch)
        {
-               this->displaytext = ch;
-               this->matchtext = ch.c_str();
        }
 
        // XXX I shouldn't have to define this
-       bool Matches(User *u)
+       bool Matches(User* u) CXX11_OVERRIDE
        {
                return false;
        }
 
-       bool Matches(const std::string &s)
+       bool Matches(const std::string& s) CXX11_OVERRIDE
        {
-               if (matchtext == s)
-                       return true;
-               return false;
+               return irc::equals(matchtext, s);
        }
 
-       const std::string& Displayable()
+       const std::string& Displayable() CXX11_OVERRIDE
        {
-               return displaytext;
+               return matchtext;
        }
 };
 
@@ -67,12 +64,12 @@ class CBanFactory : public XLineFactory
 
        /** Generate a CBAN
        */
-       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
        {
                return new CBan(set_time, duration, source, reason, xline_specific_mask);
        }
 
-       bool AutoApplyToUserList(XLine *x)
+       bool AutoApplyToUserList(XLine* x) CXX11_OVERRIDE
        {
                return false; // No, we apply to channels.
        }
@@ -88,7 +85,7 @@ class CommandCBan : public Command
                flags_needed = 'o'; this->syntax = "<channel> [<duration> :<reason>]";
        }
 
-       CmdResult Handle(const std::vector<std::string> &parameters, User *user)
+       CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE
        {
                /* syntax: CBAN #channel time :reason goes here */
                /* 'time' is a human-readable timestring, like 2d3h2s. */
@@ -135,7 +132,7 @@ class CommandCBan : public Command
                return CMD_SUCCESS;
        }
 
-       RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
+       RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) CXX11_OVERRIDE
        {
                if (IS_LOCAL(user))
                        return ROUTE_LOCALONLY; // spanningtree will send ADDLINE
@@ -144,13 +141,15 @@ class CommandCBan : public Command
        }
 };
 
-class ModuleCBan : public Module
+class ModuleCBan : public Module, public Stats::EventListener
 {
        CommandCBan mycommand;
        CBanFactory f;
 
  public:
-       ModuleCBan() : mycommand(this)
+       ModuleCBan()
+               : Stats::EventListener(this)
+               , mycommand(this)
        {
        }
 
@@ -165,12 +164,12 @@ class ModuleCBan : public Module
                ServerInstance->XLines->UnregisterFactory(&f);
        }
 
-       ModResult OnStats(char symbol, User* user, string_list &out) CXX11_OVERRIDE
+       ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE
        {
-               if (symbol != 'C')
+               if (stats.GetSymbol() != 'C')
                        return MOD_RES_PASSTHRU;
 
-               ServerInstance->XLines->InvokeStats("CBAN", 210, user, out);
+               ServerInstance->XLines->InvokeStats("CBAN", 210, stats);
                return MOD_RES_DENY;
        }
 
@@ -181,7 +180,7 @@ class ModuleCBan : public Module
                if (rl)
                {
                        // Channel is banned.
-                       user->WriteNumeric(384, "%s :Cannot join channel, CBANed (%s)", cname.c_str(), rl->reason.c_str());
+                       user->WriteNumeric(384, cname, InspIRCd::Format("Cannot join channel, CBANed (%s)", rl->reason.c_str()));
                        ServerInstance->SNO->WriteGlobalSno('a', "%s tried to join %s which is CBANed (%s)",
                                 user->nick.c_str(), cname.c_str(), rl->reason.c_str());
                        return MOD_RES_DENY;