From 3ca092f5985040bbbbe40e2f63556b88ab9efcb2 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 5 Aug 2023 20:29:07 +0200 Subject: [PATCH] Temporarily fix convar value assignment bug in 'CRConServer::Execute()' Command string buffer contains "sv_cheats" and value buffer contains "sv_cheats 1". Ideally value buffer only contains "1", and we just concatenate to "sv_cheats 1" for 'Cmd_Dispatch()' to avoid confusion on the netconsole's programmer side. This will be refactored in the future. --- r5dev/engine/server/sv_rcon.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/r5dev/engine/server/sv_rcon.cpp b/r5dev/engine/server/sv_rcon.cpp index 321a2921..f331425d 100644 --- a/r5dev/engine/server/sv_rcon.cpp +++ b/r5dev/engine/server/sv_rcon.cpp @@ -454,7 +454,9 @@ bool CRConServer::ProcessMessage(const char* pMsgBuf, const int nMsgLen) //----------------------------------------------------------------------------- void CRConServer::Execute(const cl_rcon::request& request) const { - const char* pCommandString = request.requestmsg().c_str(); + const string& commandString = request.requestmsg().c_str(); + const char* const pCommandString = commandString.c_str(); + ConCommandBase* pCommandBase = g_pCVar->FindCommandBase(pCommandString); if (!pCommandBase) @@ -463,13 +465,29 @@ void CRConServer::Execute(const cl_rcon::request& request) const return; } - const bool isCommand = pCommandBase->IsCommand(); - const char* pValueString = request.requestval().c_str(); + const char* const pValueString = request.requestval().c_str(); - if (!isCommand) + if (!pCommandBase->IsCommand()) { + // Here we want to skip over the command string in the value buffer. + // So if we got 'sv_cheats 1' in our value buffer, we want to skip + // over 'sv_cheats ', so that we are pointing directly to the value. + const char* pFound = V_strstr(pValueString, pCommandString); + const char* pValue = nullptr; + + if (pFound) + { + pValue = pFound + commandString.length(); + + // Skip any leading space characters. + while (*pValue == ' ') + { + ++pValue; + } + } + ConVar* pConVar = reinterpret_cast(pCommandBase); - pConVar->SetValue(pValueString); + pConVar->SetValue(pValue ? pValue : pValueString); } else // Invoke command callback directly. {