1
0
mirror of https://github.com/anope/anope.git synced 2026-06-12 17:24:49 +02:00

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.
This commit is contained in:
Sadie Powell
2026-06-10 09:05:14 +01:00
parent b9d0762f2b
commit ca8fcbe119
3 changed files with 20 additions and 2 deletions
+8
View File
@@ -58,6 +58,14 @@ public:
*/ */
virtual bool Parse(const Anope::string &message, Anope::map<Anope::string> &tags, Anope::string &source, Anope::string &command, std::vector<Anope::string> &params); virtual bool Parse(const Anope::string &message, Anope::map<Anope::string> &tags, Anope::string &source, Anope::string &command, std::vector<Anope::string> &params);
/* 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<Anope::string> &tags, const MessageSource &source, const Anope::string &command, const std::vector<Anope::string> &params);
/* Formats an outgoing message so it can be sent to the IRC server. /* Formats an outgoing message so it can be sent to the IRC server.
* @param message The location to store the formatted message. * @param message The location to store the formatted message.
* @param tags IRCv3 message tags. * @param tags IRCv3 message tags.
+7
View File
@@ -100,6 +100,13 @@ void Anope::ProcessInternal(MessageSource &src, const Anope::string &command, co
} }
} }
void IRCDProto::PopulateTags(Anope::map<Anope::string> &tags, const MessageSource &source, const Anope::string &command, const std::vector<Anope::string> &params)
{
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<Anope::string> &tags, Anope::string &source, Anope::string &command, std::vector<Anope::string> &params) bool IRCDProto::Parse(const Anope::string &buffer, Anope::map<Anope::string> &tags, Anope::string &source, Anope::string &command, std::vector<Anope::string> &params)
{ {
MessageTokenizer tokens(buffer); MessageTokenizer tokens(buffer);
+5 -2
View File
@@ -73,8 +73,11 @@ void Uplink::SendInternal(const Anope::map<Anope::string> &tags, const MessageSo
return; return;
} }
Anope::map<Anope::string> fulltags(tags);
IRCD->PopulateTags(fulltags, source, command, params);
Anope::string message; Anope::string message;
if (!IRCD->Format(message, tags, source, command, params)) if (!IRCD->Format(message, fulltags, source, command, params))
return; return;
UplinkSock->sent_msgs++; UplinkSock->sent_msgs++;
@@ -84,7 +87,7 @@ void Uplink::SendInternal(const Anope::map<Anope::string> &tags, const MessageSo
if (Anope::ProtocolDebug) if (Anope::ProtocolDebug)
{ {
auto sent_tag = false; auto sent_tag = false;
for (const auto &[tname, tvalue] : tags) for (const auto &[tname, tvalue] : fulltags)
{ {
if (IRCD->IsTagValid(tname, tvalue)) if (IRCD->IsTagValid(tname, tvalue))
{ {