From 4c931b6f6acbb3bc77d3d60d6a67d9d8cf867e76 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Fri, 21 Feb 2020 09:01:48 +0000 Subject: Send an account id tag when account-tag & message-tags are enabled. --- src/modules/m_ircv3_accounttag.cpp | 33 +++++++++++++++++++++++++++++++++ src/modules/m_services_account.cpp | 2 ++ 2 files changed, 35 insertions(+) (limited to 'src/modules') diff --git a/src/modules/m_ircv3_accounttag.cpp b/src/modules/m_ircv3_accounttag.cpp index a8f940169..6201ee267 100644 --- a/src/modules/m_ircv3_accounttag.cpp +++ b/src/modules/m_ircv3_accounttag.cpp @@ -19,6 +19,7 @@ #include "inspircd.h" +#include "modules/ctctags.h" #include "modules/ircv3.h" #include "modules/account.h" @@ -44,13 +45,45 @@ class AccountTag : public IRCv3::CapTag } }; +class AccountIdTag : public ClientProtocol::MessageTagProvider +{ + private: + AccountTag& acctag; + CTCTags::CapReference ctctagcap; + + public: + AccountIdTag(Module* mod, AccountTag& tag) + : ClientProtocol::MessageTagProvider(mod) + , acctag(tag) + , ctctagcap(mod) + { + } + + void OnPopulateTags(ClientProtocol::Message& msg) CXX11_OVERRIDE + { + const User* user = msg.GetSourceUser(); + const AccountExtItem* accextitem = user ? GetAccountIdExtItem() : NULL; + const std::string* accountid = accextitem ? accextitem->get(user) : NULL; + if (accountid) + msg.AddTag("inspircd.org/account-id", this, *accountid); + } + + bool ShouldSendTag(LocalUser* user, const ClientProtocol::MessageTagData& tagdata) CXX11_OVERRIDE + { + return acctag.GetCap().get(user) && ctctagcap.get(user); + } +}; + class ModuleIRCv3AccountTag : public Module { + private: AccountTag tag; + AccountIdTag idtag; public: ModuleIRCv3AccountTag() : tag(this) + , idtag(this, tag) { } diff --git a/src/modules/m_services_account.cpp b/src/modules/m_services_account.cpp index cf57a4246..87bd5cf13 100644 --- a/src/modules/m_services_account.cpp +++ b/src/modules/m_services_account.cpp @@ -148,6 +148,7 @@ class ModuleServicesAccount SimpleUserModeHandler regdeafmode; Channel_r chanregmode; User_r userregmode; + AccountExtItem accountid; AccountExtItemImpl accountname; bool checking_ban; @@ -162,6 +163,7 @@ class ModuleServicesAccount , regdeafmode(this, "regdeaf", 'R') , chanregmode(this) , userregmode(this) + , accountid("accountid", ExtensionItem::EXT_USER, this) , accountname(this) , checking_ban(false) { -- cgit v1.3.1-10-gc9f91