From ca8fcbe119dea1c451b74350927a16967bc7391d Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Wed, 10 Jun 2026 09:05:14 +0100 Subject: [PATCH] Allow protocol modules to apply tags to sent messages. This is useful because for some IRCv3 specifications we need to apply tags to all messages and its annoying to have to do this inline when sending each message. --- include/protocol.h | 8 ++++++++ src/process.cpp | 7 +++++++ src/uplink.cpp | 7 +++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/include/protocol.h b/include/protocol.h index 82d97d30b..744c776d3 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -58,6 +58,14 @@ public: */ virtual bool Parse(const Anope::string &message, Anope::map &tags, Anope::string &source, Anope::string &command, std::vector ¶ms); + /* Populates the tags that should be sent on all messages. + * @param tags The location to store tags. + * @param source Source of the message. + * @param command Command name. + * @param params Any extra parameters. + */ + virtual void PopulateTags(Anope::map &tags, const MessageSource &source, const Anope::string &command, const std::vector ¶ms); + /* Formats an outgoing message so it can be sent to the IRC server. * @param message The location to store the formatted message. * @param tags IRCv3 message tags. diff --git a/src/process.cpp b/src/process.cpp index 5dce80fce..045322176 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -100,6 +100,13 @@ void Anope::ProcessInternal(MessageSource &src, const Anope::string &command, co } } +void IRCDProto::PopulateTags(Anope::map &tags, const MessageSource &source, const Anope::string &command, const std::vector ¶ms) +{ + auto it = tags.find("time"); // https://ircv3.net/specs/extensions/server-time + if (it == tags.end()) + tags["time"] = Anope::FormatISO8601(Anope::CurTime, Anope::CurTimeNs / 1'000'000); +} + bool IRCDProto::Parse(const Anope::string &buffer, Anope::map &tags, Anope::string &source, Anope::string &command, std::vector ¶ms) { MessageTokenizer tokens(buffer); diff --git a/src/uplink.cpp b/src/uplink.cpp index c43fd770a..812e2d1ad 100644 --- a/src/uplink.cpp +++ b/src/uplink.cpp @@ -73,8 +73,11 @@ void Uplink::SendInternal(const Anope::map &tags, const MessageSo return; } + Anope::map fulltags(tags); + IRCD->PopulateTags(fulltags, source, command, params); + Anope::string message; - if (!IRCD->Format(message, tags, source, command, params)) + if (!IRCD->Format(message, fulltags, source, command, params)) return; UplinkSock->sent_msgs++; @@ -84,7 +87,7 @@ void Uplink::SendInternal(const Anope::map &tags, const MessageSo if (Anope::ProtocolDebug) { auto sent_tag = false; - for (const auto &[tname, tvalue] : tags) + for (const auto &[tname, tvalue] : fulltags) { if (IRCD->IsTagValid(tname, tvalue)) {