]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_cloaking.cpp
Implement support for IPv6 GeoIP lookups.
[user/henk/code/inspircd.git] / src / modules / m_cloaking.cpp
index e5f912c95ffa30cc8ea42b0709fb43261ead210f..b9ff085c3ebdc488894e4db053b3ef64cddceb98 100644 (file)
@@ -137,7 +137,7 @@ class CommandCloak : public Command
                syntax = "<host>";
        }
 
-       CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE;
+       CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
 };
 
 class ModuleCloaking : public Module
@@ -223,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;
@@ -267,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],
@@ -313,7 +313,13 @@ class ModuleCloaking : public Module
                if (u->IsModeSet(cu) && !cu.active)
                {
                        u->SetMode(cu, false);
-                       u->WriteCommand("MODE", "-" + ConvToStr(cu.GetModeChar()));
+
+                       if (!IS_LOCAL(u))
+                               return;
+                       Modes::ChangeList modechangelist;
+                       modechangelist.push_remove(&cu);
+                       ClientProtocol::Events::Mode modeevent(ServerInstance->FakeClient, NULL, u, modechangelist);
+                       static_cast<LocalUser*>(u)->Send(modeevent);
                }
                cu.active = false;
        }
@@ -350,12 +356,12 @@ class ModuleCloaking : public Module
                suffix = tag->getString("suffix", ".IP");
 
                std::string modestr = tag->getString("mode");
-               if (modestr == "half")
+               if (stdalgo::string::equalsci(modestr, "half"))
                {
                        mode = MODE_HALF_CLOAK;
-                       domainparts = tag->getInt("domainparts", 3, 1, 10);
+                       domainparts = tag->getUInt("domainparts", 3, 1, 10);
                }
-               else if (modestr == "full")
+               else if (stdalgo::string::equalsci(modestr, "full"))
                        mode = MODE_OPAQUE;
                else
                        throw ModuleException("Bad value for <cloak:mode>; must be half or full");
@@ -395,11 +401,15 @@ class ModuleCloaking : public Module
                if (cloak)
                        return;
 
+               // TODO: decide how we are going to cloak AF_UNIX hostnames.
+               if (dest->client_sa.family() != AF_INET && dest->client_sa.family() != AF_INET6)
+                       return;
+
                cu.ext.set(dest, GenCloak(dest->client_sa, dest->GetIPString(), dest->GetRealHost()));
        }
 };
 
-CmdResult CommandCloak::Handle(const std::vector<std::string> &parameters, User *user)
+CmdResult CommandCloak::Handle(User* user, const Params& parameters)
 {
        ModuleCloaking* mod = (ModuleCloaking*)(Module*)creator;
        irc::sockets::sockaddrs sa;