]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_cloaking.cpp
Automatically attach modules to events
[user/henk/code/inspircd.git] / src / modules / m_cloaking.cpp
index 9eb9a8da90421541e053db2b5977f29736af35cf..4e203d14c97a8079c06b946d5ef6196ef9a0ee37 100644 (file)
@@ -26,8 +26,6 @@
 #include "inspircd.h"
 #include "modules/hash.h"
 
-/* $ModDesc: Provides masking of user hostnames */
-
 enum CloakMode
 {
        /** 2.0 cloak of "half" of the hostname plus the full IP hash */
@@ -65,7 +63,7 @@ class CloakUser : public ModeHandler
                 */
                if (!user)
                {
-                       dest->SetMode('x',adding);
+                       dest->SetMode(this, adding);
                        return MODEACTION_ALLOW;
                }
 
@@ -82,7 +80,7 @@ class CloakUser : public ModeHandler
                        debounce_ts = ServerInstance->Time();
                }
 
-               if (adding == user->IsModeSet('x'))
+               if (adding == user->IsModeSet(this))
                        return MODEACTION_DENY;
 
                /* don't allow this user to spam modechanges */
@@ -102,7 +100,7 @@ class CloakUser : public ModeHandler
                        if (cloak)
                        {
                                user->ChangeDisplayedHost(cloak->c_str());
-                               user->SetMode('x',true);
+                               user->SetMode(this, true);
                                return MODEACTION_ALLOW;
                        }
                        else
@@ -113,7 +111,7 @@ class CloakUser : public ModeHandler
                        /* User is removing the mode, so restore their real host
                         * and make it match the displayed one.
                         */
-                       user->SetMode('x',false);
+                       user->SetMode(this, false);
                        user->ChangeDisplayedHost(user->host.c_str());
                        return MODEACTION_ALLOW;
                }
@@ -148,16 +146,13 @@ class ModuleCloaking : public Module
        {
        }
 
-       void init()
+       void init() CXX11_OVERRIDE
        {
                OnRehash(NULL);
 
                ServerInstance->Modules->AddService(cu);
                ServerInstance->Modules->AddService(ck);
                ServerInstance->Modules->AddService(cu.ext);
-
-               Implementation eventlist[] = { I_OnRehash, I_OnCheckBan, I_OnUserConnect, I_OnChangeHost };
-               ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
        }
 
        /** This function takes a domain name string and returns just the last two domain parts,
@@ -284,7 +279,7 @@ class ModuleCloaking : public Module
                return rv;
        }
 
-       ModResult OnCheckBan(User* user, Channel* chan, const std::string& mask)
+       ModResult OnCheckBan(User* user, Channel* chan, const std::string& mask) CXX11_OVERRIDE
        {
                LocalUser* lu = IS_LOCAL(user);
                if (!lu)
@@ -295,9 +290,8 @@ class ModuleCloaking : public Module
                /* Check if they have a cloaked host, but are not using it */
                if (cloak && *cloak != user->dhost)
                {
-                       char cmask[MAXBUF];
-                       snprintf(cmask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), cloak->c_str());
-                       if (InspIRCd::Match(cmask,mask))
+                       const std::string cloakMask = user->nick + "!" + user->ident + "@" + *cloak;
+                       if (InspIRCd::Match(cloakMask, mask))
                                return MOD_RES_DENY;
                }
                return MOD_RES_PASSTHRU;
@@ -311,16 +305,16 @@ class ModuleCloaking : public Module
 
        // this unsets umode +x on every host change. If we are actually doing a +x
        // mode change, we will call SetMode back to true AFTER the host change is done.
-       void OnChangeHost(User* u, const std::string& host)
+       void OnChangeHost(User* u, const std::string& host) CXX11_OVERRIDE
        {
-               if(u->IsModeSet('x'))
+               if (u->IsModeSet(cu))
                {
-                       u->SetMode('x', false);
-                       u->WriteServ("MODE %s -x", u->nick.c_str());
+                       u->SetMode(cu, false);
+                       u->WriteServ("MODE %s -%c", u->nick.c_str(), cu.GetModeChar());
                }
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                std::string testcloak = "broken";
                if (Hash)
@@ -337,7 +331,7 @@ class ModuleCloaking : public Module
                return Version("Provides masking of user hostnames", VF_COMMON|VF_VENDOR, testcloak);
        }
 
-       void OnRehash(User* user)
+       void OnRehash(User* user) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("cloak");
                prefix = tag->getString("prefix");
@@ -377,7 +371,7 @@ class ModuleCloaking : public Module
                return chost;
        }
 
-       void OnUserConnect(LocalUser* dest)
+       void OnUserConnect(LocalUser* dest) CXX11_OVERRIDE
        {
                std::string* cloak = cu.ext.get(dest);
                if (cloak)
@@ -398,7 +392,7 @@ CmdResult CommandCloak::Handle(const std::vector<std::string> &parameters, User
        else
                cloak = mod->GenCloak(sa, "", parameters[0]);
 
-       user->WriteServ("NOTICE %s :*** Cloak for %s is %s", user->nick.c_str(), parameters[0].c_str(), cloak.c_str());
+       user->WriteNotice("*** Cloak for " + parameters[0] + " is " + cloak);
 
        return CMD_SUCCESS;
 }