mirror of
https://github.com/anope/anope.git
synced 2026-06-12 15:44:46 +02:00
Compare commits
4 Commits
a861a059f6
...
ca8fcbe119
| Author | SHA1 | Date | |
|---|---|---|---|
| ca8fcbe119 | |||
| b9d0762f2b | |||
| 4878b1787e | |||
| 0163d92b1d |
@@ -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> ¶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<Anope::string> &tags, const MessageSource &source, const Anope::string &command, const std::vector<Anope::string> ¶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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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> ¶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<Anope::string> &tags, Anope::string &source, Anope::string &command, std::vector<Anope::string> ¶ms)
|
||||
{
|
||||
MessageTokenizer tokens(buffer);
|
||||
|
||||
+12
-5
@@ -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)
|
||||
{
|
||||
for (const auto &[tname, tvalue] : tags)
|
||||
if (IRCD->IsTagValid(tname, tvalue))
|
||||
{
|
||||
Log() << "\tTag " << tname << ": " << tvalue;
|
||||
sent_tag = true;
|
||||
}
|
||||
}
|
||||
if (!sent_tag)
|
||||
Log() << "\tNo tags";
|
||||
|
||||
if (source.GetSource().empty())
|
||||
Log() << "\tNo source";
|
||||
|
||||
Reference in New Issue
Block a user