diff options
-rw-r--r-- | include/protocol.h | 3 | ||||
-rw-r--r-- | modules/protocol/bahamut.cpp | 10 | ||||
-rw-r--r-- | modules/protocol/hybrid.cpp | 12 | ||||
-rw-r--r-- | modules/protocol/inspircd.cpp | 17 | ||||
-rw-r--r-- | modules/protocol/plexus.cpp | 4 | ||||
-rw-r--r-- | modules/protocol/ratbox.cpp | 4 | ||||
-rw-r--r-- | modules/protocol/solanum.cpp | 3 | ||||
-rw-r--r-- | modules/protocol/unrealircd.cpp | 14 | ||||
-rw-r--r-- | src/protocol.cpp | 8 |
9 files changed, 44 insertions, 31 deletions
diff --git a/include/protocol.h b/include/protocol.h index aeac6a069..f89df0ab1 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -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. */ diff --git a/modules/protocol/bahamut.cpp b/modules/protocol/bahamut.cpp index e80de36ad..8e8f321b6 100644 --- a/modules/protocol/bahamut.cpp +++ b/modules/protocol/bahamut.cpp @@ -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])); } }; diff --git a/modules/protocol/hybrid.cpp b/modules/protocol/hybrid.cpp index fc937d819..4d2ed2e82 100644 --- a/modules/protocol/hybrid.cpp +++ b/modules/protocol/hybrid.cpp @@ -468,7 +468,7 @@ struct IRCDMessageNick final /* :0MCAAAAAB NICK newnick 1350157102 */ void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, 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> ¶ms, 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); } }; diff --git a/modules/protocol/inspircd.cpp b/modules/protocol/inspircd.cpp index f8b0c35eb..2c1908faf 100644 --- a/modules/protocol/inspircd.cpp +++ b/modules/protocol/inspircd.cpp @@ -1721,7 +1721,7 @@ struct IRCDMessageSave final void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, 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> ¶ms, 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]); } }; diff --git a/modules/protocol/plexus.cpp b/modules/protocol/plexus.cpp index a2282276a..77ab81d38 100644 --- a/modules/protocol/plexus.cpp +++ b/modules/protocol/plexus.cpp @@ -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) diff --git a/modules/protocol/ratbox.cpp b/modules/protocol/ratbox.cpp index d6f7a1b3a..5dfa6b0e2 100644 --- a/modules/protocol/ratbox.cpp +++ b/modules/protocol/ratbox.cpp @@ -228,7 +228,7 @@ struct IRCDMessageTBurst final */ void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, 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> ¶ms, 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); } }; diff --git a/modules/protocol/solanum.cpp b/modules/protocol/solanum.cpp index 6ac5cbc69..d0ce08d79 100644 --- a/modules/protocol/solanum.cpp +++ b/modules/protocol/solanum.cpp @@ -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); } }; diff --git a/modules/protocol/unrealircd.cpp b/modules/protocol/unrealircd.cpp index 146d0237b..a49adac56 100644 --- a/modules/protocol/unrealircd.cpp +++ b/modules/protocol/unrealircd.cpp @@ -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 diff --git a/src/protocol.cpp b/src/protocol.cpp index 5699a2d48..55603c8e7 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -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); |