]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_cloaking.cpp
Replace snprintf usage with InspIRCd::Format.
[user/henk/code/inspircd.git] / src / modules / m_cloaking.cpp
index ccc98e557e7ca96e99ff5b26c0c4b8c6c55ca25e..890c799f2b2b55d2e96b4c099db9bdc1163a9f75 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 */
@@ -51,7 +49,7 @@ class CloakUser : public ModeHandler
 
        CloakUser(Module* source)
                : ModeHandler(source, "cloak", 'x', PARAM_NONE, MODETYPE_USER),
-               ext("cloaked_host", source), debounce_ts(0), debounce_count(0)
+               ext("cloaked_host", ExtensionItem::EXT_USER, source), debounce_ts(0), debounce_count(0)
        {
        }
 
@@ -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 */
@@ -101,8 +99,8 @@ class CloakUser : public ModeHandler
                        }
                        if (cloak)
                        {
-                               user->ChangeDisplayedHost(cloak->c_str());
-                               user->SetMode('x',true);
+                               user->ChangeDisplayedHost(*cloak);
+                               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,18 +146,6 @@ class ModuleCloaking : public Module
        {
        }
 
-       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,
         * or the last domain part if only two are available. Failing that it just returns what it was given.
         *
@@ -206,7 +192,7 @@ class ModuleCloaking : public Module
                input.append(1, '\0'); // null does not terminate a C++ string
                input.append(item);
 
-               std::string rv = Hash->sum(input).substr(0,len);
+               std::string rv = Hash->GenerateRaw(input).substr(0,len);
                for(int i=0; i < len; i++)
                {
                        // this discards 3 bits per byte. We have an
@@ -267,19 +253,17 @@ class ModuleCloaking : public Module
                }
                else
                {
-                       char buf[50];
                        if (ip.sa.sa_family == AF_INET6)
                        {
-                               snprintf(buf, 50, ".%02x%02x.%02x%02x%s",
+                               rv.append(InspIRCd::Format(".%02x%02x.%02x%02x%s",
                                        ip.in6.sin6_addr.s6_addr[2], ip.in6.sin6_addr.s6_addr[3],
-                                       ip.in6.sin6_addr.s6_addr[0], ip.in6.sin6_addr.s6_addr[1], suffix.c_str());
+                                       ip.in6.sin6_addr.s6_addr[0], ip.in6.sin6_addr.s6_addr[1], suffix.c_str()));
                        }
                        else
                        {
                                const unsigned char* ip4 = (const unsigned char*)&ip.in4.sin_addr;
-                               snprintf(buf, 50, ".%d.%d%s", ip4[1], ip4[0], suffix.c_str());
+                               rv.append(InspIRCd::Format(".%d.%d%s", ip4[1], ip4[0], suffix.c_str()));
                        }
-                       rv.append(buf);
                }
                return rv;
        }
@@ -312,10 +296,10 @@ class ModuleCloaking : public Module
        // mode change, we will call SetMode back to true AFTER the host change is done.
        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->WriteCommand("MODE", "-" + ConvToStr(cu.GetModeChar()));
                }
        }
 
@@ -336,7 +320,7 @@ class ModuleCloaking : public Module
                return Version("Provides masking of user hostnames", VF_COMMON|VF_VENDOR, testcloak);
        }
 
-       void OnRehash(User* user) CXX11_OVERRIDE
+       void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("cloak");
                prefix = tag->getString("prefix");