]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_cloaking.cpp
Hide User#host and User#dhost and use accessors to modify them.
[user/henk/code/inspircd.git] / src / modules / m_cloaking.cpp
index c114516c9fe442de075e0ce4c2ff4f76f8adfd14..f9a7fa38027cc28b2b1b9e81e0d77dba00ae04a3 100644 (file)
@@ -90,7 +90,7 @@ class CloakUser : public ModeHandler
                if (adding)
                {
                        // assume this is more correct
-                       if (user->registered != REG_ALL && user->host != user->dhost)
+                       if (user->registered != REG_ALL && user->GetRealHost() != user->GetDisplayedHost())
                                return MODEACTION_DENY;
 
                        std::string* cloak = ext.get(user);
@@ -116,7 +116,7 @@ class CloakUser : public ModeHandler
                         * and make it match the displayed one.
                         */
                        user->SetMode(this, false);
-                       user->ChangeDisplayedHost(user->host.c_str());
+                       user->ChangeDisplayedHost(user->GetRealHost().c_str());
                        return MODEACTION_ALLOW;
                }
        }
@@ -143,7 +143,7 @@ class ModuleCloaking : public Module
        std::string prefix;
        std::string suffix;
        std::string key;
-       const char* xtab[4];
+       unsigned int domainparts;
        dynamic_reference<HashProvider> Hash;
 
        ModuleCloaking() : cu(this), mode(MODE_OPAQUE), ck(this), Hash(this, "hash/md5")
@@ -161,7 +161,7 @@ class ModuleCloaking : public Module
         */
        std::string LastTwoDomainParts(const std::string &host)
        {
-               int dots = 0;
+               unsigned int dots = 0;
                std::string::size_type splitdot = host.length();
 
                for (std::string::size_type x = host.length() - 1; x; --x)
@@ -171,7 +171,7 @@ class ModuleCloaking : public Module
                                splitdot = x;
                                dots++;
                        }
-                       if (dots >= 3)
+                       if (dots >= domainparts)
                                break;
                }
 
@@ -281,7 +281,7 @@ class ModuleCloaking : public Module
                OnUserConnect(lu);
                std::string* cloak = cu.ext.get(user);
                /* Check if they have a cloaked host, but are not using it */
-               if (cloak && *cloak != user->dhost)
+               if (cloak && *cloak != user->GetDisplayedHost())
                {
                        const std::string cloakMask = user->nick + "!" + user->ident + "@" + *cloak;
                        if (InspIRCd::Match(cloakMask, mask))
@@ -315,7 +315,15 @@ class ModuleCloaking : public Module
                        switch (mode)
                        {
                                case MODE_HALF_CLOAK:
-                                       testcloak = prefix + SegmentCloak("*", 3, 8) + suffix;
+                                       // Use old cloaking verification to stay compatible with 2.0
+                                       // But verify domainparts when use 3.0-only features
+                                       if (domainparts == 3)
+                                               testcloak = prefix + SegmentCloak("*", 3, 8) + suffix;
+                                       else
+                                       {
+                                               irc::sockets::sockaddrs sa;
+                                               testcloak = GenCloak(sa, "", testcloak + ConvToStr(domainparts));
+                                       }
                                        break;
                                case MODE_OPAQUE:
                                        testcloak = prefix + SegmentCloak("*", 4, 8) + suffix;
@@ -332,7 +340,10 @@ class ModuleCloaking : public Module
 
                std::string modestr = tag->getString("mode");
                if (modestr == "half")
+               {
                        mode = MODE_HALF_CLOAK;
+                       domainparts = tag->getInt("domainparts", 3, 1, 10);
+               }
                else if (modestr == "full")
                        mode = MODE_OPAQUE;
                else
@@ -373,7 +384,7 @@ class ModuleCloaking : public Module
                if (cloak)
                        return;
 
-               cu.ext.set(dest, GenCloak(dest->client_sa, dest->GetIPString(), dest->host));
+               cu.ext.set(dest, GenCloak(dest->client_sa, dest->GetIPString(), dest->GetRealHost()));
        }
 };