1
0
mirror of https://github.com/anope/anope.git synced 2026-06-12 18:54:47 +02:00

Add a protocol module function for extracting timestamps.

This commit is contained in:
Sadie Powell
2024-03-12 00:14:13 +00:00
parent 1538909ac0
commit 04e1a4f5c8
9 changed files with 44 additions and 31 deletions
+3
View File
@@ -120,6 +120,9 @@ public:
virtual Anope::string UID_Retrieve();
virtual Anope::string SID_Retrieve();
/** Extracts a timestamp from a string. */
virtual time_t ExtractTimestamp(const Anope::string &str);
/** Sends an error to the uplink before disconnecting.
* @param reason The error message.
*/
+5 -5
View File
@@ -323,7 +323,7 @@ struct IRCDMessageMode final
if (params.size() > 2 && IRCD->IsChannelValid(params[0]))
{
Channel *c = Channel::Find(params[0]);
auto ts = Anope::Convert<time_t>(params[1], 0);
auto ts = IRCD->ExtractTimestamp(params[1]);
Anope::string modes = params[2];
for (unsigned int i = 3; i < params.size(); ++i)
@@ -376,8 +376,8 @@ struct IRCDMessageNick final
}
NickAlias *na = NULL;
auto signon = Anope::Convert<time_t>(params[2], 0);
auto stamp = Anope::Convert<time_t>(params[7], 0);
auto signon = IRCD->ExtractTimestamp(params[2]);
auto stamp = IRCD->ExtractTimestamp(params[7]);
if (signon && signon == stamp)
na = NickAlias::Find(params[0]);
@@ -457,7 +457,7 @@ struct IRCDMessageSJoin final
}
}
auto ts = Anope::Convert<time_t>(params[0], Anope::CurTime);
auto ts = IRCD->ExtractTimestamp(params[0]);
Message::Join::SJoin(source, params[1], ts, modes, users);
}
};
@@ -471,7 +471,7 @@ struct IRCDMessageTopic final
{
Channel *c = Channel::Find(params[0]);
if (c)
c->ChangeTopicInternal(source.GetUser(), params[1], params[3], Anope::Convert<time_t>(params[2], Anope::CurTime));
c->ChangeTopicInternal(source.GetUser(), params[1], params[3], IRCD->ExtractTimestamp(params[2]));
}
};
+6 -6
View File
@@ -468,7 +468,7 @@ struct IRCDMessageNick final
/* :0MCAAAAAB NICK newnick 1350157102 */
void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
source.GetUser()->ChangeNick(params[0], Anope::Convert<time_t>(params[1], Anope::CurTime));
source.GetUser()->ChangeNick(params[0], IRCD->ExtractTimestamp(params[1]));
}
};
@@ -581,7 +581,7 @@ struct IRCDMessageSJoin final
users.push_back(sju);
}
auto ts = Anope::Convert<time_t>(params[0], Anope::CurTime);
auto ts = IRCD->ExtractTimestamp(params[0]);
Message::Join::SJoin(source, params[1], ts, modes, users);
}
};
@@ -600,7 +600,7 @@ struct IRCDMessageSVSMode final
if (!u)
return;
if (Anope::Convert<time_t>(params[1], 0) != u->timestamp)
if (IRCD->ExtractTimestamp(params[1]) != u->timestamp)
return;
u->SetModesInternal(source, params[2]);
@@ -618,7 +618,7 @@ struct IRCDMessageTBurst final
{
Anope::string setter;
sepstream(params[3], '!').GetToken(setter, 0);
auto topic_time = Anope::Convert<time_t>(params[2], Anope::CurTime);
auto topic_time = IRCD->ExtractTimestamp(params[2]);
Channel *c = Channel::Find(params[1]);
if (c)
@@ -635,7 +635,7 @@ struct IRCDMessageTMode final
/* :0MC TMODE 1654867975 #nether +ntR */
void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
auto ts = Anope::Convert<time_t>(params[0], 0);
auto ts = IRCD->ExtractTimestamp(params[0]);
Channel *c = Channel::Find(params[1]);
Anope::string modes = params[2];
@@ -663,7 +663,7 @@ struct IRCDMessageUID final
/* Source is always the server */
User::OnIntroduce(params[0], params[4], params[6], params[5], params[7], source.GetServer(), params[10],
Anope::Convert<time_t>(params[2], 0), params[3], params[8], na ? *na->nc : NULL);
IRCD->ExtractTimestamp(params[2]), params[3], params[8], na ? *na->nc : NULL);
}
};
+9 -8
View File
@@ -1721,7 +1721,7 @@ struct IRCDMessageSave final
void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
User *targ = User::Find(params[0]);
auto ts = Anope::Convert<time_t>(params[1], 0);
auto ts = IRCD->ExtractTimestamp(params[1]);
if (!targ || !ts || targ->timestamp != ts)
return;
@@ -1990,7 +1990,7 @@ struct IRCDMessageFJoin final
users.push_back(sju);
}
auto ts = Anope::Convert<time_t>(params[0], Anope::CurTime);
auto ts = IRCD->ExtractTimestamp(params[0]);
Message::Join::SJoin(source, params[0], ts, modes, users);
}
};
@@ -2009,7 +2009,7 @@ struct IRCDMessageFMode final
modes += " " + params[n];
Channel *c = Channel::Find(params[0]);
auto ts = Anope::Convert<time_t>(params[1], 0);
auto ts = IRCD->ExtractTimestamp(params[1]);
if (c)
c->SetModesInternal(source, modes, ts);
}
@@ -2025,12 +2025,13 @@ struct IRCDMessageFTopic final
// :source FTOPIC channel ts topicts :topic
// :source FTOPIC channel ts topicts setby :topic (burst or RESYNC)
auto ts = IRCD->ExtractTimestamp(params[2]);
const Anope::string &setby = params.size() > 4 ? params[3] : source.GetName();
const Anope::string &topic = params.size() > 4 ? params[4] : params[3];
Channel *c = Channel::Find(params[0]);
if (c)
c->ChangeTopicInternal(NULL, setby, topic, Anope::Convert<time_t>(params[2], Anope::CurTime));
c->ChangeTopicInternal(NULL, setby, topic, ts);
}
};
@@ -2079,7 +2080,7 @@ struct IRCDMessageIJoin final
time_t chants = Anope::CurTime;
if (params.size() >= 4)
{
chants = Anope::Convert<time_t>(params[2], 0);
chants = IRCD->ExtractTimestamp(params[2]);
for (auto mode : params[3])
user.first.AddMode(mode);
}
@@ -2107,7 +2108,7 @@ struct IRCDMessageLMode final
return; // Channel doesn't exist.
// If the TS is greater than ours, we drop the mode and don't pass it anywhere.
auto chants = Anope::Convert<time_t>(params[1], Anope::CurTime);
auto chants = IRCD->ExtractTimestamp(params[1]);
if (chants > chan->creation_time)
return;
@@ -2301,7 +2302,7 @@ struct IRCDMessageUID final
void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
size_t offset = params[8][0] == '+' ? 0 : 1;
time_t ts = Anope::Convert<time_t>(params[1], 0);
auto ts = IRCD->ExtractTimestamp(params[1]);
Anope::string modes = params[8+offset];
for (unsigned i = 9+offset; i < params.size() - 1; ++i)
@@ -2326,7 +2327,7 @@ struct IRCDMessageUID final
User *u = User::OnIntroduce(params[2], params[5+offset], params[3], params[4], params[6+offset], source.GetServer(), params[params.size() - 1], ts, modes, params[0], na ? *na->nc : NULL);
if (u)
u->signon = Anope::Convert<time_t>(params[7+offset], 0);
u->signon = IRCD->ExtractTimestamp(params[7+offset]);
}
};
+2 -2
View File
@@ -306,9 +306,9 @@ struct IRCDMessageUID final
if (ip == "0")
ip.clear();
auto ts = Anope::Convert<time_t>(params[2], Anope::CurTime);
auto ts = IRCD->ExtractTimestamp(params[2]);
NickAlias *na = NULL;
if (Anope::Convert<time_t>(params[8], 0) == ts)
if (IRCD->ExtractTimestamp(params[8]) == ts)
na = NickAlias::Find(params[0]);
if (params[8] != "0" && !na)
+2 -2
View File
@@ -228,7 +228,7 @@ struct IRCDMessageTBurst final
*/
void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
auto topic_time = Anope::Convert<time_t>(params[1], Anope::CurTime);
auto topic_time = IRCD->ExtractTimestamp(params[1]);
Channel *c = Channel::Find(params[0]);
if (!c)
@@ -250,7 +250,7 @@ struct IRCDMessageUID final
void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
/* Source is always the server */
User::OnIntroduce(params[0], params[4], params[5], "", params[6], source.GetServer(), params[8], Anope::Convert<time_t>(params[2], 0), params[3], params[7], NULL);
User::OnIntroduce(params[0], params[4], params[5], "", params[6], source.GetServer(), params[8], IRCD->ExtractTimestamp(params[2]), params[3], params[7], NULL);
}
};
+2 -1
View File
@@ -254,7 +254,8 @@ struct IRCDMessageEUID final
if (params[9] != "*")
na = NickAlias::Find(params[9]);
User::OnIntroduce(params[0], params[4], (params[8] != "*" ? params[8] : params[5]), params[5], params[6], source.GetServer(), params[10], Anope::Convert<time_t>(params[2], Anope::CurTime), params[3], params[7], na ? *na->nc : NULL);
User::OnIntroduce(params[0], params[4], (params[8] != "*" ? params[8] : params[5]), params[5], params[6], source.GetServer(),
params[10], IRCD->ExtractTimestamp(params[2]), params[3], params[7], na ? *na->nc : NULL);
}
};
+7 -7
View File
@@ -1159,7 +1159,7 @@ struct IRCDMessageMode final
if (IRCD->IsChannelValid(params[0]))
{
Channel *c = Channel::Find(params[0]);
auto ts = Anope::Convert<time_t>(params[params.size() - 1], 0);
auto ts = IRCD->ExtractTimestamp(params.back());
if (c)
c->SetModesInternal(source, modes, ts);
@@ -1238,7 +1238,7 @@ struct IRCDMessageNick final
if (vhost.equals_cs("*"))
vhost.clear();
auto user_ts = Anope::Convert<time_t>(params[2], Anope::CurTime);
auto user_ts = IRCD->ExtractTimestamp(params[2]);
Server *s = Server::Find(params[5]);
if (s == NULL)
{
@@ -1252,7 +1252,7 @@ struct IRCDMessageNick final
;
else if (params[6].is_pos_number_only())
{
if (Anope::Convert<time_t>(params[6], 0) == user_ts)
if (IRCD->ExtractTimestamp(params[6]) == user_ts)
na = NickAlias::Find(params[0]);
}
else
@@ -1477,7 +1477,7 @@ struct IRCDMessageSJoin final
}
}
auto ts = Anope::Convert<time_t>(params[0], Anope::CurTime);
auto ts = IRCD->ExtractTimestamp(params[0]);
Message::Join::SJoin(source, params[1], ts, modes, users);
if (!bans.empty() || !excepts.empty() || !invites.empty())
@@ -1556,7 +1556,7 @@ struct IRCDMessageTopic final
{
Channel *c = Channel::Find(params[0]);
if (c)
c->ChangeTopicInternal(source.GetUser(), params[1], params[3], Anope::Convert<time_t>(params[2], Anope::CurTime));
c->ChangeTopicInternal(source.GetUser(), params[1], params[3], IRCD->ExtractTimestamp(params[2]));
}
};
@@ -1611,7 +1611,7 @@ struct IRCDMessageUID final
if (chost == "*")
chost.clear();
auto user_ts = Anope::Convert<time_t>(timestamp, Anope::CurTime);
auto user_ts = IRCD->ExtractTimestamp(timestamp);
NickAlias *na = NULL;
if (account == "0")
@@ -1620,7 +1620,7 @@ struct IRCDMessageUID final
}
else if (account.is_pos_number_only())
{
if (Anope::Convert<time_t>(account, 0) == user_ts)
if (IRCD->ExtractTimestamp(account) == user_ts)
na = NickAlias::Find(nickname);
}
else
+8
View File
@@ -86,6 +86,14 @@ Anope::string IRCDProto::SID_Retrieve()
return current_sid;
}
time_t IRCDProto::ExtractTimestamp(const Anope::string &str)
{
auto ts = Anope::TryConvert<time_t>(str);
if (!ts.has_value())
throw ProtocolException("Invalid timestamp: " + str);
return ts.value();
}
void IRCDProto::SendError(const Anope::string &reason)
{
Uplink::Send("ERROR", reason);