From bb1e5a7b60ea200ddae99f263a38a219879f9617 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sun, 8 Mar 2026 17:01:22 +0000 Subject: Replace IS_* with member functions. - All user types get an Is* function. - Only local users are cast using the old function so only local users get an As* function. --- include/modules/shun.h | 2 +- include/usermanager.h | 9 ++++++--- include/users.h | 30 +++++++++++++----------------- 3 files changed, 20 insertions(+), 21 deletions(-) (limited to 'include') diff --git a/include/modules/shun.h b/include/modules/shun.h index b07cdfc51..2fda59e42 100644 --- a/include/modules/shun.h +++ b/include/modules/shun.h @@ -43,7 +43,7 @@ public: bool Matches(User* u) const override { - LocalUser* lu = IS_LOCAL(u); + auto* lu = u->AsLocal(); if (lu && lu->exempt) return false; diff --git a/include/usermanager.h b/include/usermanager.h index abf2b1f2d..850d74363 100644 --- a/include/usermanager.h +++ b/include/usermanager.h @@ -228,7 +228,8 @@ public: template std::enable_if_t, T*> Find(const std::string& nickuuid, bool fullyconnected = false) { - return IS_LOCAL(Find(nickuuid, fullyconnected)); + auto* u = Find(nickuuid, fullyconnected); + return u ? u->AsLocal() : nullptr; } /** Find a user by their nickname. @@ -246,7 +247,8 @@ public: template std::enable_if_t, T*> FindNick(const std::string& nick, bool fullyconnected = false) { - return IS_LOCAL(FindNick(nick, fullyconnected)); + auto* u = FindNick(nick, fullyconnected); + return u ? u->AsLocal() : nullptr; } /** Find a user by their UUID. @@ -264,6 +266,7 @@ public: template std::enable_if_t, T*> FindUUID(const std::string& uuid, bool fullyconnected = false) { - return IS_LOCAL(FindUUID(uuid, fullyconnected)); + auto* u = FindUUID(uuid, fullyconnected); + return u ? u->AsLocal() : nullptr; } }; diff --git a/include/users.h b/include/users.h index 4ff08cc5e..8d567df6b 100644 --- a/include/users.h +++ b/include/users.h @@ -481,6 +481,10 @@ public: /** What type of user is this? */ const uint8_t usertype:2; + /** If this user is a local user then returns a \p LocalUser; otherwise, returns nullptr. */ + LocalUser* AsLocal(); + const LocalUser* AsLocal() const; + /** Retrieves the username which should be included in bans for this user. */ const std::string& GetBanUser(bool real) const; @@ -582,6 +586,15 @@ public: */ bool IsOper() const { return !!oper; } + /** Checks whether this user is a local user. */ + inline auto IsLocal() const { return this->usertype == TYPE_LOCAL; } + + /** Checks whether this user is a remote user. */ + inline auto IsRemote() const { return this->usertype == TYPE_REMOTE; } + + /** Checks whether this user is a (fake) server user. */ + inline auto IsServer() const { return this->usertype == TYPE_SERVER; } + /** Returns true if a notice mask is set * @param sm A notice mask character to check * @return True if the notice mask is set @@ -1027,23 +1040,6 @@ public: const std::string& GetRealMask() override; }; -/* Faster than dynamic_cast */ -/** Is a local user */ -inline LocalUser* IS_LOCAL(User* u) -{ - return (u != nullptr && u->usertype == User::TYPE_LOCAL) ? static_cast(u) : nullptr; -} -/** Is a remote user */ -inline RemoteUser* IS_REMOTE(User* u) -{ - return (u != nullptr && u->usertype == User::TYPE_REMOTE) ? static_cast(u) : nullptr; -} -/** Is a server fakeuser */ -inline FakeUser* IS_SERVER(User* u) -{ - return (u != nullptr && u->usertype == User::TYPE_SERVER) ? static_cast(u) : nullptr; -} - inline bool User::IsModeSet(const ModeHandler* mh) const { return ((mh->GetId() != ModeParser::MODEID_MAX) && (modes[mh->GetId()])); -- cgit v1.3.1-10-gc9f91