]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_cban.cpp
Merge tag 'v2.0.27' into master.
[user/henk/code/inspircd.git] / src / modules / m_cban.cpp
index 044aa45a582fd6b850f9962bae1aacce4386d253..d1fb23620b1d2b2ca01ef1c85f76d7a04158224c 100644 (file)
 
 #include "inspircd.h"
 #include "xline.h"
+#include "modules/stats.h"
 
-/* $ModDesc: Gives /cban, aka C:lines. Think Q:lines, for channels. */
+enum
+{
+       // InspIRCd-specific.
+       ERR_BADCHANNEL = 926
+};
 
 /** Holds a CBAN item
  */
 class CBan : public XLine
 {
-public:
-       irc::string matchtext;
+private:
+       std::string matchtext;
 
-       CBan(time_t s_time, long d, std::string src, std::string re, std::string ch)
+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->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 char* Displayable()
+       const std::string& Displayable() CXX11_OVERRIDE
        {
-               return matchtext.c_str();
+               return matchtext;
        }
 };
 
@@ -66,12 +70,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.
        }
@@ -85,10 +89,9 @@ class CommandCBan : public Command
        CommandCBan(Module* Creator) : Command(Creator, "CBAN", 1, 3)
        {
                flags_needed = 'o'; this->syntax = "<channel> [<duration> :<reason>]";
-               TRANSLATE4(TR_TEXT,TR_TEXT,TR_TEXT,TR_END);
        }
 
-       CmdResult Handle(const std::vector<std::string> &parameters, User *user)
+       CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
        {
                /* syntax: CBAN #channel time :reason goes here */
                /* 'time' is a human-readable timestring, like 2d3h2s. */
@@ -121,7 +124,7 @@ class CommandCBan : 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->WriteGlobalSno('x', "%s added timed CBan for %s, expires on %s: %s", user->nick.c_str(), parameters[0].c_str(), timestr.c_str(), reason);
                                }
                        }
@@ -135,7 +138,7 @@ class CommandCBan : 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
@@ -144,23 +147,21 @@ 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)
        {
        }
 
        void init() CXX11_OVERRIDE
        {
                ServerInstance->XLines->RegisterFactory(&f);
-
-               ServerInstance->Modules->AddService(mycommand);
-               Implementation eventlist[] = { I_OnUserPreJoin, I_OnStats };
-               ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
        ~ModuleCBan()
@@ -169,12 +170,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;
        }
 
@@ -185,7 +186,7 @@ class ModuleCBan : public Module
                if (rl)
                {
                        // Channel is banned.
-                       user->WriteServ( "384 %s %s :Cannot join channel, CBANed (%s)", user->nick.c_str(), cname.c_str(), rl->reason.c_str());
+                       user->WriteNumeric(ERR_BADCHANNEL, cname, InspIRCd::Format("Channel %s is CBANed: %s", cname.c_str(), 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;