From 581d1d8fa0ef62e20409543570390613c78e6f5b Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Mon, 26 Oct 2020 18:02:23 +0000 Subject: Fix the behaviour of multi-value PING and PONG messages. --- include/clientprotocolmsg.h | 5 ++++- src/coremods/core_user/core_user.cpp | 24 +++++++++++++++++++----- src/coremods/core_user/core_user.h | 6 ++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/include/clientprotocolmsg.h b/include/clientprotocolmsg.h index 863cdf8b2..07f32b686 100644 --- a/include/clientprotocolmsg.h +++ b/include/clientprotocolmsg.h @@ -663,11 +663,14 @@ struct ClientProtocol::Messages::Pong : public ClientProtocol::Message { /** Constructor. * @param cookie Ping cookie. Must remain valid as long as this object is alive. + * @param server Pinged server. Must remain valid as long as this object is alive if non-empty. */ - Pong(const std::string& cookie) + Pong(const std::string& cookie, const std::string& server = "") : ClientProtocol::Message("PONG", ServerInstance->Config->ServerName) { PushParamRef(ServerInstance->Config->ServerName); + if (!server.empty()) + PushParamRef(server); PushParamRef(cookie); } }; diff --git a/src/coremods/core_user/core_user.cpp b/src/coremods/core_user/core_user.cpp index a5c2d4048..0f526305b 100644 --- a/src/coremods/core_user/core_user.cpp +++ b/src/coremods/core_user/core_user.cpp @@ -64,9 +64,9 @@ class CommandPing : public SplitCommand /** Constructor for ping. */ CommandPing(Module* parent) - : SplitCommand(parent, "PING", 1, 2) + : SplitCommand(parent, "PING", 1) { - syntax = " [:]"; + syntax = " []"; } /** Handle command. @@ -76,7 +76,14 @@ class CommandPing : public SplitCommand */ CmdResult HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE { - ClientProtocol::Messages::Pong pong(parameters[0]); + size_t origin = parameters.size() > 1 ? 1 : 0; + if (parameters[origin].empty()) + { + user->WriteNumeric(ERR_NOORIGIN, "No origin specified"); + return CMD_FAILURE; + } + + ClientProtocol::Messages::Pong pong(parameters[0], origin ? parameters[1] : ""); user->Send(ServerInstance->GetRFCEvents().pong, pong); return CMD_SUCCESS; } @@ -90,10 +97,10 @@ class CommandPong : public Command /** Constructor for pong. */ CommandPong(Module* parent) - : Command(parent, "PONG", 0, 1) + : Command(parent, "PONG", 1) { Penalty = 0; - syntax = ""; + syntax = " []"; } /** Handle command. @@ -103,6 +110,13 @@ class CommandPong : public Command */ CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE { + size_t origin = parameters.size() > 1 ? 1 : 0; + if (parameters[origin].empty()) + { + user->WriteNumeric(ERR_NOORIGIN, "No origin specified"); + return CMD_FAILURE; + } + // set the user as alive so they survive to next ping LocalUser* localuser = IS_LOCAL(user); if (localuser) diff --git a/src/coremods/core_user/core_user.h b/src/coremods/core_user/core_user.h index 8289ad5a8..760ed9cf6 100644 --- a/src/coremods/core_user/core_user.h +++ b/src/coremods/core_user/core_user.h @@ -24,6 +24,12 @@ #include "listmode.h" #include "modules/away.h" +enum +{ + // From RFC 1459. + ERR_NOORIGIN = 409 +}; + class MessageWrapper { std::string prefix; -- cgit v1.2.3