]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/coremods/core_user/core_user.cpp
Fix sending malformed pong messages in some cases.
[user/henk/code/inspircd.git] / src / coremods / core_user / core_user.cpp
index 8504de8e0e969e8426c0c6699e6b3bc49bf60f21..622e82c75813f927f717445463a5478b8fefec58 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * InspIRCd -- Internet Relay Chat Daemon
  *
- *   Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
+ *   Copyright (C) 2017-2020 Sadie Powell <sadie@witchery.services>
+ *   Copyright (C) 2014-2016, 2018 Attila Molnar <attilamolnar@hush.com>
  *
  * This file is part of InspIRCd.  InspIRCd is free software: you can
  * redistribute it and/or modify it under the terms of the GNU General Public
@@ -40,7 +41,7 @@ class CommandPass : public SplitCommand
         * @param user The user issuing the command
         * @return A value from CmdResult to indicate command success or failure.
         */
-       CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* user) CXX11_OVERRIDE
+       CmdResult HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE
        {
                // Check to make sure they haven't registered -- Fix by FCS
                if (user->registered == REG_ALL)
@@ -57,15 +58,15 @@ class CommandPass : public SplitCommand
 
 /** Handle /PING.
  */
-class CommandPing : public Command
+class CommandPing : public SplitCommand
 {
  public:
        /** Constructor for ping.
         */
        CommandPing(Module* parent)
-               : Command(parent, "PING", 1, 2)
+               : SplitCommand(parent, "PING", 1)
        {
-               syntax = "<servername> [:<servername>]";
+               syntax = "<cookie> [<servername>]";
        }
 
        /** Handle command.
@@ -73,9 +74,17 @@ class CommandPing : public Command
         * @param user The user issuing the command
         * @return A value from CmdResult to indicate command success or failure.
         */
-       CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE
+       CmdResult HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE
        {
-               user->WriteServ("PONG %s :%s", ServerInstance->Config->ServerName.c_str(), parameters[0].c_str());
+               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] : ServerInstance->Config->GetServerName());
+               user->Send(ServerInstance->GetRFCEvents().pong, pong);
                return CMD_SUCCESS;
        }
 };
@@ -88,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.
@@ -99,8 +108,15 @@ class CommandPong : public Command
         * @param user The user issuing the command
         * @return A value from CmdResult to indicate command success or failure.
         */
-       CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE
+       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)
@@ -139,7 +155,6 @@ void MessageWrapper::ReadConfig(const char* prefixname, const char* suffixname,
 class CoreModUser : public Module
 {
        CommandAway cmdaway;
-       CommandMode cmdmode;
        CommandNick cmdnick;
        CommandPart cmdpart;
        CommandPass cmdpass;
@@ -147,6 +162,8 @@ class CoreModUser : public Module
        CommandPong cmdpong;
        CommandQuit cmdquit;
        CommandUser cmduser;
+       CommandIson cmdison;
+       CommandUserhost cmduserhost;
        SimpleUserModeHandler invisiblemode;
        ModeUserOperator operatormode;
        ModeUserServerNoticeMask snomaskmode;
@@ -154,7 +171,6 @@ class CoreModUser : public Module
  public:
        CoreModUser()
                : cmdaway(this)
-               , cmdmode(this)
                , cmdnick(this)
                , cmdpart(this)
                , cmdpass(this)
@@ -162,6 +178,8 @@ class CoreModUser : public Module
                , cmdpong(this)
                , cmdquit(this)
                , cmduser(this)
+               , cmdison(this)
+               , cmduserhost(this)
                , invisiblemode(this, "invisible", 'i')
                , operatormode(this)
                , snomaskmode(this)
@@ -176,7 +194,7 @@ class CoreModUser : public Module
 
        Version GetVersion() CXX11_OVERRIDE
        {
-               return Version("Provides the AWAY, MODE, NICK, PART, PASS, PING, PONG, QUIT and USER commands", VF_VENDOR|VF_CORE);
+               return Version("Provides the AWAY, ISON, NICK, PART, PASS, PING, PONG, QUIT, USERHOST, and USER commands", VF_VENDOR|VF_CORE);
        }
 };