diff options
author | Sadie Powell <sadie@witchery.services> | 2025-02-25 20:45:34 +0000 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2025-02-25 20:45:34 +0000 |
commit | bb3e124bdb07cc12d51a0483b6cf913e4af58b8a (patch) | |
tree | ed380f9b8aed282b70412bae76636132407ecdc8 /include/modules | |
parent | 07610ad2d9261b3b1fb243380afd2327dd80a7a5 (diff) |
Deduplicate some SASL logic.
Diffstat (limited to 'include/modules')
-rw-r--r-- | include/modules/sasl.h | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/include/modules/sasl.h b/include/modules/sasl.h index f088ec1f1..d051e2e61 100644 --- a/include/modules/sasl.h +++ b/include/modules/sasl.h @@ -52,6 +52,17 @@ namespace SASL Reference<Mechanism> mech; Session(Mechanism *m, const Anope::string &u) : created(Anope::CurTime), uid(u), mech(m) { } + + inline Anope::string GetUserInfo() + { + auto *u = User::Find(uid); + if (u) + return u->GetMask(); + if (!hostname.empty() && !ip.empty()) + return Anope::printf("%s (%s)", hostname.c_str(), ip.c_str()); + return "A user"; + }; + virtual ~Session() { if (sasl) @@ -83,6 +94,16 @@ namespace SASL Anope::string uid; Anope::string hostname; + inline Anope::string GetUserInfo() + { + auto *u = User::Find(uid); + if (u) + return u->GetMask(); + if (!hostname.empty() && !GetAddress().empty()) + return Anope::printf("%s (%s)", hostname.c_str(), GetAddress().c_str()); + return "A user"; + }; + public: IdentifyRequest(Module *m, const Anope::string &id, const Anope::string &acc, const Anope::string &pass, const Anope::string &h, const Anope::string &i) : ::IdentifyRequest(m, acc, pass, i) @@ -107,11 +128,7 @@ namespace SASL Session *s = sasl->GetSession(uid); if (s) { - Anope::string user = "A user"; - if (!hostname.empty() && !GetAddress().empty()) - user = hostname + " (" + GetAddress() + ")"; - - Log(this->GetOwner(), "sasl", Config->GetClient("NickServ")) << user << " identified to account " << this->GetAccount() << " using SASL"; + Log(this->GetOwner(), "sasl", Config->GetClient("NickServ")) << GetUserInfo() << " identified to account " << this->GetAccount() << " using SASL"; sasl->Succeed(s, na->nc); delete s; } @@ -138,11 +155,7 @@ namespace SASL else if (na->nc->HasExt("UNCONFIRMED")) accountstatus = "unconfirmed "; - Anope::string user = "A user"; - if (!hostname.empty() && !GetAddress().empty()) - user = hostname + " (" + GetAddress() + ")"; - - Log(this->GetOwner(), "sasl", Config->GetClient("NickServ")) << user << " failed to identify for " << accountstatus << "account " << this->GetAccount() << " using SASL"; + Log(this->GetOwner(), "sasl", Config->GetClient("NickServ")) << GetUserInfo() << " failed to identify for " << accountstatus << "account " << this->GetAccount() << " using SASL"; } }; } |