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

Compare commits

...

4 Commits

Author SHA1 Message Date
Sadie Powell ca8fcbe119 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.
2026-06-10 09:14:09 +01:00
Sadie Powell b9d0762f2b Add a function for building an ISO 8601 timestamp. 2026-06-10 09:14:09 +01:00
Sadie Powell 4878b1787e Only send tags on InspIRCd when we are done syncing. 2026-06-09 23:29:35 +01:00
Sadie Powell 0163d92b1d Fix showing tags in the protocoldebug output for sent messages. 2026-06-09 23:23:18 +01:00
7 changed files with 53 additions and 11 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);
/* 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.
* @param message The location to store the formatted message.
* @param tags IRCv3 message tags.
+6
View File
@@ -79,6 +79,12 @@ namespace Anope
*/
extern CoreExport Anope::string FormatCTCP(const Anope::string &name, const Anope::string &body = "");
/** Formats a date/time as an IS0 8601 timestamp.
* @param ts UNIX timestamp to format.
* @param ms Number of milliseconds to format.
*/
extern CoreExport Anope::string FormatISO8601(time_t ts, unsigned long long ms);
/** Parses a CTCP message received from a client.
* @param text The raw message to parse.
* @param name The location to store the name of the CTCP.
+1 -5
View File
@@ -299,11 +299,7 @@ public:
{
Anope::map<Anope::string> tags;
if (timestamp)
{
char timebuf[32];
strftime(timebuf, sizeof(timebuf), "%Y-%m-%dT%H:%M:%S.000Z", gmtime(&message->when));
tags["time"] = timebuf;
}
tags["time"] = Anope::FormatISO8601(message->when, 0);
if (u->ShouldPrivmsg())
IRCD->SendContextPrivmsg(c->ci->WhoSends(), u, c, message->message, tags);
+1 -1
View File
@@ -734,7 +734,7 @@ public:
bool IsTagValid(const Anope::string &tname, const Anope::string &tvalue) override
{
// InspIRCd accepts arbitrary message tags.
return true;
return Me->IsSynced();
}
};
+18
View File
@@ -1178,6 +1178,24 @@ Anope::string Anope::FormatCTCP(const Anope::string &name, const Anope::string &
return Anope::Format("\1%s %s\1", name.c_str(), value.c_str());
}
Anope::string Anope::FormatISO8601(time_t ts, unsigned long long ms)
{
static time_t last_ts = -1;
static unsigned long long last_ms = -1;
static Anope::string timestamp;
if (ts != last_ts || ms != last_ms)
{
last_ts = ts;
last_ms = ms;
char timebuf[32];
const auto *tm = gmtime(&ts);
strftime(timebuf, sizeof(timebuf), "%Y-%m-%dT%H:%M:%S", tm);
timestamp = Anope::Format("%s.%03lldZ", timebuf, ms);
}
return timestamp;
}
bool Anope::ParseCTCP(const Anope::string &text, Anope::string &name, Anope::string &body)
{
// According to draft-oakley-irc-ctcp-02 a valid CTCP must begin with SOH and
+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)
{
MessageTokenizer tokens(buffer);
+12 -5
View File
@@ -73,8 +73,11 @@ void Uplink::SendInternal(const Anope::map<Anope::string> &tags, const MessageSo
return;
}
Anope::map<Anope::string> 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++;
@@ -83,13 +86,17 @@ void Uplink::SendInternal(const Anope::map<Anope::string> &tags, const MessageSo
Log(LOG_RAWIO) << "Sent " << message;
if (Anope::ProtocolDebug)
{
if (tags.empty())
Log() << "\tNo tags";
else
auto sent_tag = false;
for (const auto &[tname, tvalue] : fulltags)
{
if (IRCD->IsTagValid(tname, tvalue))
{
for (const auto &[tname, tvalue] : tags)
Log() << "\tTag " << tname << ": " << tvalue;
sent_tag = true;
}
}
if (!sent_tag)
Log() << "\tNo tags";
if (source.GetSource().empty())
Log() << "\tNo source";