From 0a0eeca20aeee2beb64b554e0d822ea026815c6b Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 9 Feb 2025 02:02:17 +0100 Subject: [PATCH] NetCon: update code to use new RCON API Changed in commit b1d81e2dc54596fff7efa31fd874134c3c2671a3, sizes must now be provided to minimize the amount of strlen's performed by protobuf internally. --- src/netconsole/netconsole.cpp | 25 ++++++++++++++++++------- src/netconsole/netconsole.h | 4 ++-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/netconsole/netconsole.cpp b/src/netconsole/netconsole.cpp index 33636bf4..09b1d45b 100644 --- a/src/netconsole/netconsole.cpp +++ b/src/netconsole/netconsole.cpp @@ -242,18 +242,27 @@ void CNetCon::RunInput(const string& lineInput) { if (V_strcmp(cmd.Arg(0), "PASS") == 0) // Auth with RCON server. { - bSend = Serialize(vecMsg, cmd.Arg(1), "", + const char* const pass = cmd.Arg(1); + const size_t passLen = strlen(pass); + + bSend = Serialize(vecMsg, pass, passLen, "", 0, netcon::request_e::SERVERDATA_REQUEST_AUTH); } else // Execute command query. { - bSend = Serialize(vecMsg, cmd.Arg(0), cmd.GetCommandString(), + const char* const request = cmd.Arg(0); + const size_t requestLen = strlen(request); + + const char* const command = cmd.GetCommandString(); + const size_t commandLen = strlen(command); + + bSend = Serialize(vecMsg, request, requestLen, command, commandLen, netcon::request_e::SERVERDATA_REQUEST_EXECCOMMAND); } } else // Single arg command query. { - bSend = Serialize(vecMsg, lineInput.c_str(), "", netcon::request_e::SERVERDATA_REQUEST_EXECCOMMAND); + bSend = Serialize(vecMsg, lineInput.c_str(), lineInput.length(), "", 0, netcon::request_e::SERVERDATA_REQUEST_EXECCOMMAND); } if (bSend) // Only send if serialization process was successful. @@ -433,7 +442,7 @@ bool CNetCon::ProcessMessage(const char* pMsgBuf, const int nMsgLen) if (!i) // Means we are marked 'input only' on the rcon server. { vector vecMsg; - bool ret = Serialize(vecMsg, "", "1", netcon::request_e::SERVERDATA_REQUEST_SEND_CONSOLE_LOG); + bool ret = Serialize(vecMsg, "", 0, "1", 1, netcon::request_e::SERVERDATA_REQUEST_SEND_CONSOLE_LOG); if (ret && !Send(GetSocket(), vecMsg.data(), int(vecMsg.size()))) { @@ -465,14 +474,16 @@ bool CNetCon::ProcessMessage(const char* pMsgBuf, const int nMsgLen) // Purpose: serializes message to vector // Input : &vecBuf - // *szReqBuf - +// nReqMsgLen - // *svReqVal - +// nReqValLen - // requestType - // Output : true on success, false otherwise //----------------------------------------------------------------------------- -bool CNetCon::Serialize(vector& vecBuf, const char* szReqBuf, - const char* szReqVal, const netcon::request_e requestType) const +bool CNetCon::Serialize(vector& vecBuf, const char* szReqBuf, const size_t nReqMsgLen, + const char* szReqVal, const size_t nReqValLen, const netcon::request_e requestType) const { - return NetconClient_Serialize(this, vecBuf, szReqBuf, szReqVal, requestType, m_bEncryptFrames, true); + return NetconClient_Serialize(this, vecBuf, szReqBuf, nReqMsgLen, szReqVal, nReqValLen, requestType, m_bEncryptFrames, true); } //----------------------------------------------------------------------------- diff --git a/src/netconsole/netconsole.h b/src/netconsole/netconsole.h index 0e35c19d..a81ac05a 100644 --- a/src/netconsole/netconsole.h +++ b/src/netconsole/netconsole.h @@ -38,8 +38,8 @@ public: virtual bool ProcessMessage(const char* pMsgBuf, const int nMsgLen) override; void TrySetKey(const char* const pKey); - bool Serialize(vector& vecBuf, const char* szReqBuf, - const char* szReqVal, const netcon::request_e requestType) const; + bool Serialize(vector& vecBuf, const char* szReqBuf, const size_t nReqMsgLen, + const char* szReqVal, const size_t nReqValLen, const netcon::request_e requestType) const; SocketHandle_t GetSocket(void); bool IsInitialized(void) const;