summaryrefslogtreecommitdiff
path: root/src/users.cpp
diff options
context:
space:
mode:
authorPeter Powell <petpow@saberuk.com>2017-10-22 21:53:24 +0100
committerPeter Powell <petpow@saberuk.com>2017-10-28 16:16:10 +0100
commitd865b434865907bfad0a187dd403d4ca8144e469 (patch)
tree4c36b1028ab02ca8ac2d07b867819f96f38c2745 /src/users.cpp
parent08f6f056667df63d1673bea959c73b75393113c6 (diff)
Hide User#host and User#dhost and use accessors to modify them.
This removes the need to invalidate the cache after changing a user's hostname.
Diffstat (limited to 'src/users.cpp')
-rw-r--r--src/users.cpp52
1 files changed, 43 insertions, 9 deletions
diff --git a/src/users.cpp b/src/users.cpp
index 9fef906d1..aa5031b2b 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -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;