]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_cloaking.cpp
Add the family() member to the sockaddrs union.
[user/henk/code/inspircd.git] / src / modules / m_cloaking.cpp
index 1cfd9516cf957ab48638fa724f4b94088abeab19..87ff14a9d15c4e25b83ba464ebdd13100193b641 100644 (file)
@@ -42,18 +42,22 @@ static const char base32[] = "0123456789abcdefghijklmnopqrstuv";
 class CloakUser : public ModeHandler
 {
  public:
+       bool active;
        LocalStringExt ext;
        std::string debounce_uid;
        time_t debounce_ts;
        int debounce_count;
 
        CloakUser(Module* source)
-               : ModeHandler(source, "cloak", 'x', PARAM_NONE, MODETYPE_USER),
-               ext("cloaked_host", ExtensionItem::EXT_USER, source), debounce_ts(0), debounce_count(0)
+               : ModeHandler(source, "cloak", 'x', PARAM_NONE, MODETYPE_USER)
+               , active(false)
+               , ext("cloaked_host", ExtensionItem::EXT_USER, source)
+               , debounce_ts(0)
+               , debounce_count(0)
        {
        }
 
-       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
+       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) CXX11_OVERRIDE
        {
                LocalUser* user = IS_LOCAL(dest);
 
@@ -63,6 +67,8 @@ class CloakUser : public ModeHandler
                 */
                if (!user)
                {
+                       // Remote setters broadcast mode before host while local setters do the opposite, so this takes that into account
+                       active = IS_LOCAL(source) ? adding : !adding;
                        dest->SetMode(this, adding);
                        return MODEACTION_ALLOW;
                }
@@ -131,7 +137,7 @@ class CommandCloak : public Command
                syntax = "<host>";
        }
 
-       CmdResult Handle(const std::vector<std::string> &parameters, User *user);
+       CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE;
 };
 
 class ModuleCloaking : public Module
@@ -146,7 +152,11 @@ class ModuleCloaking : public Module
        unsigned int domainparts;
        dynamic_reference<HashProvider> Hash;
 
-       ModuleCloaking() : cu(this), mode(MODE_OPAQUE), ck(this), Hash(this, "hash/md5")
+       ModuleCloaking()
+               : cu(this)
+               , mode(MODE_OPAQUE)
+               , ck(this)
+               , Hash(this, "hash/md5")
        {
        }
 
@@ -213,7 +223,7 @@ class ModuleCloaking : public Module
                size_t hop1, hop2, hop3;
                size_t len1, len2;
                std::string rv;
-               if (ip.sa.sa_family == AF_INET6)
+               if (ip.family() == AF_INET6)
                {
                        bindata = std::string((const char*)ip.in6.sin6_addr.s6_addr, 16);
                        hop1 = 8;
@@ -257,7 +267,7 @@ class ModuleCloaking : public Module
                }
                else
                {
-                       if (ip.sa.sa_family == AF_INET6)
+                       if (ip.family() == AF_INET6)
                        {
                                rv.append(InspIRCd::Format(".%02x%02x.%02x%02x%s",
                                        ip.in6.sin6_addr.s6_addr[2], ip.in6.sin6_addr.s6_addr[3],
@@ -300,11 +310,12 @@ 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(cu))
+               if (u->IsModeSet(cu) && !cu.active)
                {
                        u->SetMode(cu, false);
                        u->WriteCommand("MODE", "-" + ConvToStr(cu.GetModeChar()));
                }
+               cu.active = false;
        }
 
        Version GetVersion() CXX11_OVERRIDE
@@ -342,7 +353,7 @@ class ModuleCloaking : public Module
                if (modestr == "half")
                {
                        mode = MODE_HALF_CLOAK;
-                       domainparts = tag->getInt("domainparts", 3, 1, 10);
+                       domainparts = tag->getUInt("domainparts", 3, 1, 10);
                }
                else if (modestr == "full")
                        mode = MODE_OPAQUE;