X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_cloaking.cpp;h=e5f912c95ffa30cc8ea42b0709fb43261ead210f;hb=c18edeeea37d81dfdefe4f8a9d57a5d153da8e5b;hp=7e9c78b319489375e9c06138e424ec4f62782687;hpb=a3e0768758ca68429a29d9c78ce672f2d938c6e7;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_cloaking.cpp b/src/modules/m_cloaking.cpp index 7e9c78b31..e5f912c95 100644 --- a/src/modules/m_cloaking.cpp +++ b/src/modules/m_cloaking.cpp @@ -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 ¶meter, 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; } @@ -90,7 +96,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 +122,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; } } @@ -131,7 +137,7 @@ class CommandCloak : public Command syntax = ""; } - CmdResult Handle(const std::vector ¶meters, User *user); + CmdResult Handle(const std::vector& parameters, User* user) CXX11_OVERRIDE; }; class ModuleCloaking : public Module @@ -146,7 +152,11 @@ class ModuleCloaking : public Module unsigned int domainparts; dynamic_reference 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") { } @@ -187,7 +197,7 @@ class ModuleCloaking : public Module * @param id A unique ID for this type of item (to make it unique if the item matches) * @param len The length of the output. Maximum for MD5 is 16 characters. */ - std::string SegmentCloak(const std::string& item, char id, int len) + std::string SegmentCloak(const std::string& item, char id, size_t len) { std::string input; input.reserve(key.length() + 3 + item.length()); @@ -197,7 +207,7 @@ class ModuleCloaking : public Module input.append(item); std::string rv = Hash->GenerateRaw(input).substr(0,len); - for(int i=0; i < len; i++) + for(size_t i = 0; i < len; i++) { // this discards 3 bits per byte. We have an // overabundance of bits in the hash output, doesn't @@ -210,8 +220,8 @@ class ModuleCloaking : public Module std::string SegmentIP(const irc::sockets::sockaddrs& ip, bool full) { std::string bindata; - int hop1, hop2, hop3; - int len1, len2; + size_t hop1, hop2, hop3; + size_t len1, len2; std::string rv; if (ip.sa.sa_family == AF_INET6) { @@ -281,7 +291,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)) @@ -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 @@ -384,7 +395,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())); } };