diff options
author | Sadie Powell <sadie@witchery.services> | 2024-06-03 15:51:29 +0100 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2024-06-03 16:04:53 +0100 |
commit | e71a9e289441fd78ffa1bd3d8c20ea2cb8542426 (patch) | |
tree | 95def1c721754ed095e2ca9654892343f611a953 | |
parent | f80bdf06bace6d3e5c50ed982fe1c14451ae4518 (diff) |
Avoid NickAlias lookups by storing a pointer in the NickCore.
-rw-r--r-- | include/account.h | 4 | ||||
-rw-r--r-- | include/users.h | 5 | ||||
-rw-r--r-- | modules/hostserv/hostserv.cpp | 2 | ||||
-rw-r--r-- | modules/hostserv/hs_off.cpp | 2 | ||||
-rw-r--r-- | modules/hostserv/hs_on.cpp | 2 | ||||
-rw-r--r-- | modules/nickserv/ns_register.cpp | 2 | ||||
-rw-r--r-- | modules/sasl.cpp | 2 | ||||
-rw-r--r-- | src/nickalias.cpp | 2 | ||||
-rw-r--r-- | src/nickcore.cpp | 3 | ||||
-rw-r--r-- | src/users.cpp | 5 |
10 files changed, 22 insertions, 7 deletions
diff --git a/include/account.h b/include/account.h index b6a69cfcf..57ca5b506 100644 --- a/include/account.h +++ b/include/account.h @@ -145,6 +145,8 @@ public: /* Unsaved data */ + /** The display nick for this account. */ + NickAlias *na = nullptr; /* Number of channels registered by this account */ uint16_t channelcount = 0; /* Users online now logged into this account */ @@ -163,7 +165,7 @@ public: /** Changes the display for this account * @param na The new display, must be grouped to this account. */ - void SetDisplay(const NickAlias *na); + void SetDisplay(NickAlias *na); /** Checks whether this account is a services oper or not. * @return True if this account is a services oper, false otherwise. diff --git a/include/users.h b/include/users.h index 85435dd0f..fb740ab94 100644 --- a/include/users.h +++ b/include/users.h @@ -215,6 +215,11 @@ public: */ NickCore *Account() const; + /** Get the account nick the user is logged in using + * @return The account nick or NULL + */ + NickAlias *AccountNick() const; + /** Check if the user is identified for their nick * @param check_nick True to check if the user is identified to the nickname they are on too * @return true or false diff --git a/modules/hostserv/hostserv.cpp b/modules/hostserv/hostserv.cpp index 81257cf4f..39b49ec29 100644 --- a/modules/hostserv/hostserv.cpp +++ b/modules/hostserv/hostserv.cpp @@ -43,7 +43,7 @@ public: const NickAlias *na = NickAlias::Find(u->nick); if (!na || na->nc != u->Account() || !na->HasVHost()) - na = NickAlias::Find(u->Account()->display); + na = u->AccountNick(); if (!na || !na->HasVHost()) return; diff --git a/modules/hostserv/hs_off.cpp b/modules/hostserv/hs_off.cpp index 8689ff919..b5978582f 100644 --- a/modules/hostserv/hs_off.cpp +++ b/modules/hostserv/hs_off.cpp @@ -27,7 +27,7 @@ public: const NickAlias *na = NickAlias::Find(u->nick); if (!na || na->nc != u->Account() || !na->HasVHost()) - na = NickAlias::Find(u->Account()->display); + na = u->AccountNick(); if (!na || !na->HasVHost()) source.Reply(HOST_NOT_ASSIGNED); diff --git a/modules/hostserv/hs_on.cpp b/modules/hostserv/hs_on.cpp index d61975b0b..6d4904042 100644 --- a/modules/hostserv/hs_on.cpp +++ b/modules/hostserv/hs_on.cpp @@ -29,7 +29,7 @@ public: User *u = source.GetUser(); const NickAlias *na = NickAlias::Find(u->nick); if (!na || na->nc != u->Account() || !na->HasVHost()) - na = NickAlias::Find(u->Account()->display); + na = u->AccountNick(); if (na && u->Account() == na->nc && na->HasVHost()) { source.Reply(_("Your vhost of \002%s\002 is now activated."), na->GetVHostMask().c_str()); diff --git a/modules/nickserv/ns_register.cpp b/modules/nickserv/ns_register.cpp index 28582a7ab..277cc43a2 100644 --- a/modules/nickserv/ns_register.cpp +++ b/modules/nickserv/ns_register.cpp @@ -401,7 +401,7 @@ public: u->SendMessage(NickServ, _("All new accounts must be validated by an administrator. Please wait for your registration to be confirmed.")); else u->SendMessage(NickServ, _("Your email address is not confirmed. To confirm it, follow the instructions that were emailed to you.")); - const NickAlias *this_na = NickAlias::Find(u->Account()->display); + const NickAlias *this_na = u->AccountNick(); time_t time_registered = Anope::CurTime - this_na->time_registered; time_t unconfirmed_expire = Config->GetModule(this)->Get<time_t>("unconfirmedexpire", "1d"); if (unconfirmed_expire > time_registered) diff --git a/modules/sasl.cpp b/modules/sasl.cpp index f9be602b8..d84d08624 100644 --- a/modules/sasl.cpp +++ b/modules/sasl.cpp @@ -302,7 +302,7 @@ public: // If the user is already introduced then we log them in now. // Otherwise, we send an SVSLOGIN to log them in later. User *user = User::Find(session->uid); - NickAlias *na = nc ? NickAlias::Find(nc->display) : nullptr; + NickAlias *na = nc ? nc->na : nullptr; if (user) { if (na) diff --git a/src/nickalias.cpp b/src/nickalias.cpp index cfcd13381..f7c6a79e2 100644 --- a/src/nickalias.cpp +++ b/src/nickalias.cpp @@ -31,6 +31,8 @@ NickAlias::NickAlias(const Anope::string &nickname, NickCore *nickcore) throw CoreException("Empty nickcore passed to NickAlias constructor"); nickcore->aliases->push_back(this); + if (this->nick.equals_ci(nickcore->display)) + nickcore->na = this; if (!NickAliasList->insert_or_assign(this->nick, this).second) Log(LOG_DEBUG) << "Duplicate nick " << this->nick << " in NickAlias table"; diff --git a/src/nickcore.cpp b/src/nickcore.cpp index 64aa4f504..0fa721f8d 100644 --- a/src/nickcore.cpp +++ b/src/nickcore.cpp @@ -149,7 +149,7 @@ Serializable *NickCore::Unserialize(Serializable *obj, Serialize::Data &data) return nc; } -void NickCore::SetDisplay(const NickAlias *na) +void NickCore::SetDisplay(NickAlias *na) { if (na->nc != this || na->nick == this->display) return; @@ -164,6 +164,7 @@ void NickCore::SetDisplay(const NickAlias *na) NickCoreList->erase(this->display); this->display = na->nick; + this->na = na; (*NickCoreList)[this->display] = this; } diff --git a/src/users.cpp b/src/users.cpp index 8273e888d..9462881f1 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -430,6 +430,11 @@ NickCore *User::Account() const return this->nc; } +NickAlias *User::AccountNick() const +{ + return this->nc ? this->nc->na : nullptr; +} + bool User::IsIdentified(bool check_nick) const { if (check_nick && this->nc) |