]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_cban.cpp
Fix access checks on chanprotect preventing use of SAMODE
[user/henk/code/inspircd.git] / src / modules / m_cban.cpp
index 452f1539a9c26c6b35bcb26e932bb9ed5b6303ae..d5e62c98b09289c710a313c3c5cb743b4c8812a0 100644 (file)
@@ -23,9 +23,10 @@ class CBan : public XLine
 public:
        irc::string matchtext;
 
-       CBan(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char *ch) : XLine(Instance, s_time, d, src, re, "CBAN")
+       CBan(InspIRCd* Instance, time_t s_time, long d, std::string src, std::string re, std::string ch)
+               : XLine(Instance, s_time, d, src, re, "CBAN")
        {
-               this->matchtext = ch;
+               this->matchtext = ch.c_str();
        }
 
        ~CBan()
@@ -47,8 +48,9 @@ public:
 
        void DisplayExpiry()
        {
-               ServerInstance->SNO->WriteToSnoMask('x',"Removing expired CBan %s (set by %s %ld seconds ago)", this->matchtext.c_str(), this->source, (long int)(ServerInstance->Time() - this->set_time));
-               ServerInstance->PI->SendSNONotice("x", "Removing expired CBan " + assign(this->matchtext) + " (set by " + std::string(this->source) + " " + ConvToStr(ServerInstance->Time() - this->set_time) + " seconds ago)");
+               ServerInstance->SNO->WriteToSnoMask('x',"Removing expired CBan %s (set by %s %ld seconds ago)",
+                       this->matchtext.c_str(), this->source.c_str(), (long int)(ServerInstance->Time() - this->set_time));
+               ServerInstance->PI->SendSNONotice("x", "Removing expired CBan " + assign(this->matchtext) + " (set by " + this->source + " " + ConvToStr(ServerInstance->Time() - this->set_time) + " seconds ago)");
        }
 
        const char* Displayable()
@@ -66,7 +68,7 @@ class CBanFactory : public XLineFactory
 
        /** Generate a shun
        */
-       XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask)
+       XLine* Generate(time_t set_time, long duration, std::string source, std::string reason, std::string xline_specific_mask)
        {
                return new CBan(ServerInstance, set_time, duration, source, reason, xline_specific_mask);
        }
@@ -82,10 +84,9 @@ class CBanFactory : public XLineFactory
 class CommandCBan : public Command
 {
  public:
-       CommandCBan(InspIRCd* Me) : Command(Me, "CBAN", "o", 1, 3)
+       CommandCBan(Module* Creator) : Command(Creator, "CBAN", 1, 3)
        {
-               this->source = "m_cban.so";
-               this->syntax = "<channel> [<duration> :<reason>]";
+               flags_needed = 'o'; this->syntax = "<channel> [<duration> :<reason>]";
                TRANSLATE4(TR_TEXT,TR_TEXT,TR_TEXT,TR_END);
        }
 
@@ -152,54 +153,58 @@ class CommandCBan : public Command
 
                return CMD_FAILURE;
        }
+
+       RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
+       {
+               return ROUTE_BROADCAST;
+       }
 };
 
 class ModuleCBan : public Module
 {
-       CommandCBan* mycommand;
-       CBanFactory *f;
+       CommandCBan mycommand;
+       CBanFactory f;
 
  public:
-       ModuleCBan(InspIRCd* Me) : Module(Me)
+       ModuleCBan(InspIRCd* Me) : Module(Me), mycommand(this), f(Me)
        {
-               f = new CBanFactory(ServerInstance);
-               ServerInstance->XLines->RegisterFactory(f);
+               ServerInstance->XLines->RegisterFactory(&f);
 
-               mycommand = new CommandCBan(Me);
-               ServerInstance->AddCommand(mycommand);
-               Implementation eventlist[] = { I_OnUserPreJoin, I_OnSyncOtherMetaData, I_OnDecodeMetaData, I_OnStats };
-               ServerInstance->Modules->Attach(eventlist, this, 4);
+               ServerInstance->AddCommand(&mycommand);
+               Implementation eventlist[] = { I_OnUserPreJoin, I_OnStats };
+               ServerInstance->Modules->Attach(eventlist, this, 2);
        }
 
        virtual ~ModuleCBan()
        {
                ServerInstance->XLines->DelAll("CBAN");
-               ServerInstance->XLines->UnregisterFactory(f);
+               ServerInstance->XLines->UnregisterFactory(&f);
        }
 
-       virtual int OnStats(char symbol, User* user, string_list &out)
+       virtual ModResult OnStats(char symbol, User* user, string_list &out)
        {
                if (symbol != 'C')
-                       return 0;
+                       return MOD_RES_PASSTHRU;
 
                ServerInstance->XLines->InvokeStats("CBAN", 210, user, out);
-               return 1;
+               return MOD_RES_DENY;
        }
 
-       virtual int OnUserPreJoin(User *user, Channel *chan, const char *cname, std::string &privs, const std::string &keygiven)
+       virtual ModResult OnUserPreJoin(User *user, Channel *chan, const char *cname, std::string &privs, const std::string &keygiven)
        {
                XLine *rl = ServerInstance->XLines->MatchesLine("CBAN", cname);
 
                if (rl)
                {
                        // Channel is banned.
-                       user->WriteServ( "384 %s %s :Cannot join channel, CBANed (%s)", user->nick.c_str(), cname, rl->reason);
-                       ServerInstance->SNO->WriteToSnoMask('A', "%s tried to join %s which is CBANed (%s)", user->nick.c_str(), cname, rl->reason);
-                       ServerInstance->PI->SendSNONotice("A", user->nick + " tried to join " + std::string(cname) + " which is CBANed (" + std::string(rl->reason) + ")");
-                       return 1;
+                       user->WriteServ( "384 %s %s :Cannot join channel, CBANed (%s)", user->nick.c_str(), cname, rl->reason.c_str());
+                       ServerInstance->SNO->WriteToSnoMask('a', "%s tried to join %s which is CBANed (%s)",
+                                user->nick.c_str(), cname, rl->reason.c_str());
+                       ServerInstance->PI->SendSNONotice("A", user->nick + " tried to join " + std::string(cname) + " which is CBANed (" + rl->reason + ")");
+                       return MOD_RES_DENY;
                }
 
-               return 0;
+               return MOD_RES_PASSTHRU;
        }
 
        virtual Version GetVersion()