mirror of
https://github.com/anope/anope.git
synced 2026-06-12 17:24:49 +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);
|
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.
|
/* 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.
|
||||||
|
|||||||
@@ -79,6 +79,12 @@ namespace Anope
|
|||||||
*/
|
*/
|
||||||
extern CoreExport Anope::string FormatCTCP(const Anope::string &name, const Anope::string &body = "");
|
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.
|
/** Parses a CTCP message received from a client.
|
||||||
* @param text The raw message to parse.
|
* @param text The raw message to parse.
|
||||||
* @param name The location to store the name of the CTCP.
|
* @param name The location to store the name of the CTCP.
|
||||||
|
|||||||
@@ -299,11 +299,7 @@ public:
|
|||||||
{
|
{
|
||||||
Anope::map<Anope::string> tags;
|
Anope::map<Anope::string> tags;
|
||||||
if (timestamp)
|
if (timestamp)
|
||||||
{
|
tags["time"] = Anope::FormatISO8601(message->when, 0);
|
||||||
char timebuf[32];
|
|
||||||
strftime(timebuf, sizeof(timebuf), "%Y-%m-%dT%H:%M:%S.000Z", gmtime(&message->when));
|
|
||||||
tags["time"] = timebuf;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (u->ShouldPrivmsg())
|
if (u->ShouldPrivmsg())
|
||||||
IRCD->SendContextPrivmsg(c->ci->WhoSends(), u, c, message->message, tags);
|
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
|
bool IsTagValid(const Anope::string &tname, const Anope::string &tvalue) override
|
||||||
{
|
{
|
||||||
// InspIRCd accepts arbitrary message tags.
|
// 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());
|
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)
|
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
|
// 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)
|
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);
|
MessageTokenizer tokens(buffer);
|
||||||
|
|||||||
+12
-5
@@ -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++;
|
||||||
@@ -83,13 +86,17 @@ void Uplink::SendInternal(const Anope::map<Anope::string> &tags, const MessageSo
|
|||||||
Log(LOG_RAWIO) << "Sent " << message;
|
Log(LOG_RAWIO) << "Sent " << message;
|
||||||
if (Anope::ProtocolDebug)
|
if (Anope::ProtocolDebug)
|
||||||
{
|
{
|
||||||
if (tags.empty())
|
auto sent_tag = false;
|
||||||
Log() << "\tNo tags";
|
for (const auto &[tname, tvalue] : fulltags)
|
||||||
else
|
|
||||||
{
|
{
|
||||||
for (const auto &[tname, tvalue] : tags)
|
if (IRCD->IsTagValid(tname, tvalue))
|
||||||
|
{
|
||||||
Log() << "\tTag " << tname << ": " << tvalue;
|
Log() << "\tTag " << tname << ": " << tvalue;
|
||||||
|
sent_tag = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (!sent_tag)
|
||||||
|
Log() << "\tNo tags";
|
||||||
|
|
||||||
if (source.GetSource().empty())
|
if (source.GetSource().empty())
|
||||||
Log() << "\tNo source";
|
Log() << "\tNo source";
|
||||||
|
|||||||
Reference in New Issue
Block a user