From 5bd6432862f527d82ccd58b45a54418df492bd81 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Wed, 3 Aug 2022 09:32:48 +0200 Subject: [PATCH] Additional RCON system cleanup --- r5dev/engine/client/cl_rcon.cpp | 16 ++++++++-------- r5dev/engine/server/sv_rcon.cpp | 31 ++++++++++++++----------------- r5dev/engine/server/sv_rcon.h | 4 ++-- r5dev/netconsole/netconsole.cpp | 12 ++++++------ r5dev/vstdlib/callback.cpp | 3 +-- 5 files changed, 31 insertions(+), 35 deletions(-) diff --git a/r5dev/engine/client/cl_rcon.cpp b/r5dev/engine/client/cl_rcon.cpp index 4588cdc9..b28f7fc0 100644 --- a/r5dev/engine/client/cl_rcon.cpp +++ b/r5dev/engine/client/cl_rcon.cpp @@ -290,43 +290,43 @@ void CRConClient::ProcessMessage(const sv_rcon::response& sv_response) const case sv_rcon::response_t::SERVERDATA_RESPONSE_CONSOLE_LOG: { // !TODO: Network the enum for this. - if (strstr(svOut.c_str(), SQVM_LOG_T[0].c_str())) + if (svOut.find(SQVM_LOG_T[0])) { SQVM_PrintFunc(nullptr, const_cast("%s"), svOut.c_str()); } else // This has to be done for RUI color logging. { - if (strstr(svOut.c_str(), sDLL_T[0].c_str())) + if (svOut.find(sDLL_T[0])) { StringReplace(svOut, sDLL_T[0], ""); DevMsg(eDLL_T::SERVER, "%s", svOut.c_str()); } - if (strstr(svOut.c_str(), sDLL_T[1].c_str())) + if (svOut.find(sDLL_T[1])) { StringReplace(svOut, sDLL_T[1], ""); DevMsg(eDLL_T::CLIENT, "%s", svOut.c_str()); } - if (strstr(svOut.c_str(), sDLL_T[2].c_str())) + if (svOut.find(sDLL_T[2])) { StringReplace(svOut, sDLL_T[2], ""); DevMsg(eDLL_T::UI, "%s", svOut.c_str()); } - if (strstr(svOut.c_str(), sDLL_T[3].c_str())) + if (svOut.find(sDLL_T[3])) { StringReplace(svOut, sDLL_T[3], ""); DevMsg(eDLL_T::ENGINE, "%s", svOut.c_str()); } - if (strstr(svOut.c_str(), sDLL_T[4].c_str())) + if (svOut.find(sDLL_T[4])) { StringReplace(svOut, sDLL_T[4], ""); DevMsg(eDLL_T::FS, "%s", svOut.c_str()); } - if (strstr(svOut.c_str(), sDLL_T[5].c_str())) + if (svOut.find(sDLL_T[5])) { StringReplace(svOut, sDLL_T[5], ""); DevMsg(eDLL_T::RTECH, "%s", svOut.c_str()); } - if (strstr(svOut.c_str(), sDLL_T[6].c_str())) + if (svOut.find(sDLL_T[6])) { StringReplace(svOut, sDLL_T[6], ""); DevMsg(eDLL_T::MS, "%s", svOut.c_str()); diff --git a/r5dev/engine/server/sv_rcon.cpp b/r5dev/engine/server/sv_rcon.cpp index 8846dd65..293475e3 100644 --- a/r5dev/engine/server/sv_rcon.cpp +++ b/r5dev/engine/server/sv_rcon.cpp @@ -19,9 +19,9 @@ //----------------------------------------------------------------------------- -// Purpose: NETCON systems init +// Purpose: //----------------------------------------------------------------------------- -CRConServer::CRConServer() +CRConServer::CRConServer(void) : m_bInitialized(false) , m_nConnIndex(0) { @@ -29,6 +29,15 @@ CRConServer::CRConServer() m_pSocket = new CSocketCreator(); } +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +CRConServer::~CRConServer(void) +{ + delete m_pAdr2; + delete m_pSocket; +} + //----------------------------------------------------------------------------- // Purpose: NETCON systems init //----------------------------------------------------------------------------- @@ -74,7 +83,7 @@ void CRConServer::Think(void) for (m_nConnIndex = nCount - 1; m_nConnIndex >= 0; m_nConnIndex--) { CNetAdr2 netAdr2 = m_pSocket->GetAcceptedSocketAddress(m_nConnIndex); - if (std::strcmp(netAdr2.GetIP(true).c_str(), sv_rcon_whitelist_address->GetString()) != 0) + if (netAdr2.GetIP(true).compare(sv_rcon_whitelist_address->GetString()) != 0) { CConnectedNetConsoleData* pData = m_pSocket->GetAcceptedSocketData(m_nConnIndex); if (!pData->m_bAuthorized) @@ -156,19 +165,7 @@ void CRConServer::Send(const std::string& svMessage) const if (pData->m_bAuthorized) { - size_t nMsgCount = (ssSendBuf.str().size() + MAX_NETCONSOLE_INPUT_LEN - 1) / MAX_NETCONSOLE_INPUT_LEN; - size_t nDataSize = ssSendBuf.str().size(); - size_t nPos = 0; - - for (size_t j = 0; j < nMsgCount; j++) - { - size_t nSize = std::min(MAX_NETCONSOLE_INPUT_LEN, nDataSize); - nDataSize -= nSize; - string svFinal = ssSendBuf.str().substr(nPos, nSize); - - ::send(pData->m_hSocket, svFinal.data(), static_cast(svFinal.size()), MSG_NOSIGNAL); - nPos += nSize; - } + ::send(pData->m_hSocket, ssSendBuf.str().data(), static_cast(ssSendBuf.str().size()), MSG_NOSIGNAL); } } } @@ -523,7 +520,7 @@ bool CRConServer::CheckForBan(CConnectedNetConsoleData* pData) || pData->m_nIgnoredMessage >= sv_rcon_maxignores->GetInt()) { // Don't add whitelisted address to ban vector. - if (std::strcmp(netAdr2.GetIP(true).c_str(), sv_rcon_whitelist_address->GetString()) == 0) + if (netAdr2.GetIP(true).compare(sv_rcon_whitelist_address->GetString()) == 0) { pData->m_nFailedAttempts = 0; pData->m_nIgnoredMessage = 0; diff --git a/r5dev/engine/server/sv_rcon.h b/r5dev/engine/server/sv_rcon.h index fa187b15..5aeb801b 100644 --- a/r5dev/engine/server/sv_rcon.h +++ b/r5dev/engine/server/sv_rcon.h @@ -12,8 +12,8 @@ constexpr char s_pszAuthMessage[] = "RCON authentication successfull.\n"; class CRConServer { public: - CRConServer(); - ~CRConServer() { delete m_pAdr2; delete m_pSocket; } + CRConServer(void); + ~CRConServer(void); void Init(void); void Shutdown(void); diff --git a/r5dev/netconsole/netconsole.cpp b/r5dev/netconsole/netconsole.cpp index f52c36b1..1362f7d3 100644 --- a/r5dev/netconsole/netconsole.cpp +++ b/r5dev/netconsole/netconsole.cpp @@ -125,14 +125,14 @@ void CNetCon::UserInput(void) if (std::getline(std::cin, svInput)) { - if (strcmp(svInput.c_str(), "nquit") == 0) + if (svInput.compare("nquit") == 0) { m_bQuitApplication = true; return; } if (m_abConnEstablished) { - if (strcmp(svInput.c_str(), "disconnect") == 0) + if (svInput.compare("disconnect") == 0) { this->Disconnect(); return; @@ -141,12 +141,12 @@ void CNetCon::UserInput(void) vector vSubStrings = StringSplit(svInput, ' ', 2); if (vSubStrings.size() > 1) { - if (strcmp(vSubStrings[0].c_str(), "PASS") == 0) // Auth with RCON server. + if (vSubStrings[0].compare("PASS") == 0) // Auth with RCON server. { std::string svSerialized = this->Serialize(vSubStrings[1], "", cl_rcon::request_t::SERVERDATA_REQUEST_AUTH); this->Send(svSerialized); } - else if (strcmp(vSubStrings[0].c_str(), "SET") == 0) // Set value query. + else if (vSubStrings[0].compare("SET") == 0) // Set value query. { if (vSubStrings.size() > 2) { @@ -156,13 +156,13 @@ void CNetCon::UserInput(void) } else // Execute command query. { - std::string svSerialized = this->Serialize(svInput.c_str(), "", cl_rcon::request_t::SERVERDATA_REQUEST_EXECCOMMAND); + std::string svSerialized = this->Serialize(svInput, "", cl_rcon::request_t::SERVERDATA_REQUEST_EXECCOMMAND); this->Send(svSerialized); } } else if (!svInput.empty()) // Single arg command query. { - std::string svSerialized = this->Serialize(svInput.c_str(), "", cl_rcon::request_t::SERVERDATA_REQUEST_EXECCOMMAND); + std::string svSerialized = this->Serialize(svInput, "", cl_rcon::request_t::SERVERDATA_REQUEST_EXECCOMMAND); this->Send(svSerialized); } } diff --git a/r5dev/vstdlib/callback.cpp b/r5dev/vstdlib/callback.cpp index 2e9bad50..0ae4698c 100644 --- a/r5dev/vstdlib/callback.cpp +++ b/r5dev/vstdlib/callback.cpp @@ -780,8 +780,7 @@ void RCON_CmdQuery_f(const CCommand& args) return; } - string svCmdQuery = RCONClient()->Serialize(args.ArgS(), "", cl_rcon::request_t::SERVERDATA_REQUEST_EXECCOMMAND); - RCONClient()->Send(svCmdQuery); + RCONClient()->Send(RCONClient()->Serialize(args.ArgS(), "", cl_rcon::request_t::SERVERDATA_REQUEST_EXECCOMMAND)); return; } else