]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Fix the behaviour of multi-value PING and PONG messages.
authorSadie Powell <sadie@witchery.services>
Mon, 26 Oct 2020 18:02:23 +0000 (18:02 +0000)
committerSadie Powell <sadie@witchery.services>
Mon, 26 Oct 2020 18:02:23 +0000 (18:02 +0000)
include/clientprotocolmsg.h
src/coremods/core_user/core_user.cpp
src/coremods/core_user/core_user.h

index 863cdf8b24880e43d352b1f432b4018e1a8226c4..07f32b686d6058707f33b37b8d3fe34c494edfb1 100644 (file)
@@ -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);
        }
 };
index a5c2d4048881090fcdfbdd192f7cb30a1dbab543..0f526305b79bbdacfd0e9f5646b0a511da75414d 100644 (file)
@@ -64,9 +64,9 @@ class CommandPing : public SplitCommand
        /** Constructor for ping.
         */
        CommandPing(Module* parent)
-               : SplitCommand(parent, "PING", 1, 2)
+               : SplitCommand(parent, "PING", 1)
        {
-               syntax = "<servername> [:<servername>]";
+               syntax = "<cookie> [<servername>]";
        }
 
        /** 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 = "<ping-text>";
+               syntax = "<cookie> [<servername>]";
        }
 
        /** 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)
index 8289ad5a80e958070e0a65a4b9bfd96bb49400a1..760ed9cf62f921ee6dcbb62e7dc1a54a6cb39943 100644 (file)
 #include "listmode.h"
 #include "modules/away.h"
 
+enum
+{
+       // From RFC 1459.
+       ERR_NOORIGIN = 409
+};
+
 class MessageWrapper
 {
        std::string prefix;