]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_stripcolor.cpp
Move the OnCheckExemption hook out of the core.
[user/henk/code/inspircd.git] / src / modules / m_stripcolor.cpp
index b7e26afd5bbf3d97119786062f5193cad7f2ec69..6ad32bfc1010207530b46b36c976b3fa857f50ce 100644 (file)
@@ -20,8 +20,7 @@
 
 
 #include "inspircd.h"
-
-/* $ModDesc: Provides channel +S mode (strip ansi color) */
+#include "modules/exemption.h"
 
 /** Handles channel mode +S
  */
@@ -42,20 +41,16 @@ class UserStripColor : public SimpleUserModeHandler
 
 class ModuleStripColor : public Module
 {
+       CheckExemption::EventProvider exemptionprov;
        ChannelStripColor csc;
        UserStripColor usc;
 
  public:
-       ModuleStripColor() : csc(this), usc(this)
-       {
-       }
-
-       void init() CXX11_OVERRIDE
+       ModuleStripColor()
+               : exemptionprov(this)
+               , csc(this)
+               , usc(this)
        {
-               ServerInstance->Modules->AddService(usc);
-               ServerInstance->Modules->AddService(csc);
-               Implementation eventlist[] = { I_OnUserPreMessage, I_On005Numeric };
-               ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
        void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
@@ -72,17 +67,18 @@ class ModuleStripColor : public Module
                if (target_type == TYPE_USER)
                {
                        User* t = (User*)dest;
-                       active = t->IsModeSet('S');
+                       active = t->IsModeSet(usc);
                }
                else if (target_type == TYPE_CHANNEL)
                {
                        Channel* t = (Channel*)dest;
-                       ModResult res = ServerInstance->OnCheckExemption(user,t,"stripcolor");
+                       ModResult res;
+                       FIRST_MOD_RESULT_CUSTOM(exemptionprov, CheckExemption::EventListener, OnCheckExemption, res, (user, t, "stripcolor"));
 
                        if (res == MOD_RES_ALLOW)
                                return MOD_RES_PASSTHRU;
 
-                       active = !t->GetExtBanStatus(user, 'S').check(!t->IsModeSet('S'));
+                       active = !t->GetExtBanStatus(user, 'S').check(!t->IsModeSet(csc));
                }
 
                if (active)
@@ -93,6 +89,24 @@ class ModuleStripColor : public Module
                return MOD_RES_PASSTHRU;
        }
 
+       void OnUserPart(Membership* memb, std::string& partmessage, CUList& except_list) CXX11_OVERRIDE
+       {
+               User* user = memb->user;
+               Channel* channel = memb->chan;
+
+               if (!IS_LOCAL(user))
+                       return;
+
+               if (channel->GetExtBanStatus(user, 'S').check(!user->IsModeSet(csc)))
+               {
+                       ModResult res;
+                       FIRST_MOD_RESULT_CUSTOM(exemptionprov, CheckExemption::EventListener, OnCheckExemption, res, (user, channel, "stripcolor"));
+
+                       if (res != MOD_RES_ALLOW)
+                               InspIRCd::StripColor(partmessage);
+               }
+       }
+
        Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides channel +S mode (strip ansi color)", VF_VENDOR);