]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
Hide User#host and User#dhost and use accessors to modify them.
[user/henk/code/inspircd.git] / src / users.cpp
index 9fef906d16d83de783acfe89e93de293563443bf..aa5031b2b1632bdda7c885f0ad3b3d1935d6da83 100644 (file)
@@ -106,7 +106,7 @@ LocalUser::LocalUser(int myfd, irc::sockets::sockaddrs* client, irc::sockets::so
        eh.SetFd(myfd);
        memcpy(&client_sa, client, sizeof(irc::sockets::sockaddrs));
        memcpy(&server_sa, servaddr, sizeof(irc::sockets::sockaddrs));
-       dhost = host = GetIPString();
+       ChangeRealHost(GetIPString(), true);
 }
 
 User::~User()
@@ -119,7 +119,7 @@ const std::string& User::MakeHost()
                return this->cached_makehost;
 
        // XXX: Is there really a need to cache this?
-       this->cached_makehost = ident + "@" + host;
+       this->cached_makehost = ident + "@" + GetRealHost();
        return this->cached_makehost;
 }
 
@@ -139,7 +139,7 @@ const std::string& User::GetFullHost()
                return this->cached_fullhost;
 
        // XXX: Is there really a need to cache this?
-       this->cached_fullhost = nick + "!" + ident + "@" + dhost;
+       this->cached_fullhost = nick + "!" + ident + "@" + GetDisplayedHost();
        return this->cached_fullhost;
 }
 
@@ -149,7 +149,7 @@ const std::string& User::GetFullRealHost()
                return this->cached_fullrealhost;
 
        // XXX: Is there really a need to cache this?
-       this->cached_fullrealhost = nick + "!" + ident + "@" + host;
+       this->cached_fullrealhost = nick + "!" + ident + "@" + GetRealHost();
        return this->cached_fullrealhost;
 }
 
@@ -360,7 +360,7 @@ void User::Oper(OperInfo* info)
        }
 
        ServerInstance->SNO->WriteToSnoMask('o',"%s (%s@%s) is now an IRC operator of type %s (using oper '%s')",
-               nick.c_str(), ident.c_str(), host.c_str(), oper->name.c_str(), opername.c_str());
+               nick.c_str(), ident.c_str(), GetRealHost().c_str(), oper->name.c_str(), opername.c_str());
        this->WriteNumeric(RPL_YOUAREOPER, InspIRCd::Format("You are now %s %s", strchr("aeiouAEIOU", oper->name[0]) ? "an" : "a", oper->name.c_str()));
 
        ServerInstance->Logs->Log("OPER", LOG_DEFAULT, "%s opered as type: %s", GetFullRealHost().c_str(), oper->name.c_str());
@@ -692,6 +692,21 @@ const std::string& User::GetIPString()
        return cachedip;
 }
 
+const std::string& User::GetHost(bool uncloak) const
+{
+       return uncloak ? GetRealHost() : GetDisplayedHost();
+}
+
+const std::string& User::GetDisplayedHost() const
+{
+       return displayhost.empty() ? realhost : displayhost;
+}
+
+const std::string& User::GetRealHost() const
+{
+       return realhost;
+}
+
 irc::sockets::cidr_mask User::GetCIDRMask()
 {
        int range = 0;
@@ -997,7 +1012,7 @@ bool User::ChangeName(const std::string& gecos)
 
 bool User::ChangeDisplayedHost(const std::string& shost)
 {
-       if (dhost == shost)
+       if (GetDisplayedHost() == shost)
                return true;
 
        if (IS_LOCAL(this))
@@ -1010,15 +1025,34 @@ bool User::ChangeDisplayedHost(const std::string& shost)
 
        FOREACH_MOD(OnChangeHost, (this,shost));
 
-       this->dhost.assign(shost, 0, ServerInstance->Config->Limits.MaxHost);
+       if (realhost == shost)
+               this->displayhost.clear();
+       else
+               this->displayhost.assign(shost, 0, ServerInstance->Config->Limits.MaxHost);
+
        this->InvalidateCache();
 
        if (IS_LOCAL(this))
-               this->WriteNumeric(RPL_YOURDISPLAYEDHOST, this->dhost, "is now your displayed host");
+               this->WriteNumeric(RPL_YOURDISPLAYEDHOST, this->GetDisplayedHost(), "is now your displayed host");
 
        return true;
 }
 
+void User::ChangeRealHost(const std::string& host, bool resetdisplay)
+{
+       if (displayhost == host)
+               return;
+       
+       if (displayhost.empty() && !resetdisplay)
+               displayhost = realhost;
+
+       else if (displayhost == host || resetdisplay)
+               displayhost.clear();
+
+       realhost = host;
+       this->InvalidateCache();
+}
+
 bool User::ChangeIdent(const std::string& newident)
 {
        if (this->ident == newident)
@@ -1085,7 +1119,7 @@ void LocalUser::SetClass(const std::string &explicit_name)
 
                        /* check if host matches.. */
                        if (!InspIRCd::MatchCIDR(this->GetIPString(), c->GetHost(), NULL) &&
-                           !InspIRCd::MatchCIDR(this->host, c->GetHost(), NULL))
+                           !InspIRCd::MatchCIDR(this->GetRealHost(), c->GetHost(), NULL))
                        {
                                ServerInstance->Logs->Log("CONNECTCLASS", LOG_DEBUG, "No host match (for %s)", c->GetHost().c_str());
                                continue;