From c07baa7dc137daa006685bfa4757aaf429f81e1b Mon Sep 17 00:00:00 2001 From: Amos <48657826+Mauler125@users.noreply.github.com> Date: Fri, 4 Mar 2022 01:07:16 +0100 Subject: Cleanup and bug fixes Fixed several small bugs --- NorthstarDedicatedTest/NetAdr2.cpp | 25 +++++++++++++++++++++++++ NorthstarDedicatedTest/NetAdr2.h | 1 + NorthstarDedicatedTest/cl_rcon.cpp | 6 ++++-- NorthstarDedicatedTest/dedicated.cpp | 4 ---- NorthstarDedicatedTest/rcon_shared.cpp | 2 +- NorthstarDedicatedTest/squirrel.cpp | 2 +- NorthstarDedicatedTest/sv_rcon.cpp | 2 +- 7 files changed, 33 insertions(+), 9 deletions(-) (limited to 'NorthstarDedicatedTest') diff --git a/NorthstarDedicatedTest/NetAdr2.cpp b/NorthstarDedicatedTest/NetAdr2.cpp index 6f89b2ab..ff022238 100644 --- a/NorthstarDedicatedTest/NetAdr2.cpp +++ b/NorthstarDedicatedTest/NetAdr2.cpp @@ -279,6 +279,11 @@ std::string CNetAdr2::GetPort(void) const static std::regex rx(".*\\]:"); svport = std::regex_replace(svport, rx, ""); + if (!IsValidPort(svport)) + { + return "37015"; + } + return svport; } @@ -291,6 +296,11 @@ std::string CNetAdr2::GetPort(std::string svInPort) const static std::regex rx(".*\\]:"); svInPort = std::regex_replace(svInPort, rx, ""); + if (!IsValidPort(svInPort)) + { + return "37015"; + } + return svInPort; } @@ -472,6 +482,21 @@ void CNetAdr2::ToAdrinfo(addrinfo* pHint) const } } +//----------------------------------------------------------------------------- +// Purpose: returns true if this is a valid port string. +//----------------------------------------------------------------------------- +bool CNetAdr2::IsValidPort(const std::string& svInPort) const +{ + for (char const& c : svInPort) + { + if (std::isdigit(c) == 0) + { + return false; + } + } + return true; +} + //----------------------------------------------------------------------------- // Purpose: returns true if we are localhost. //----------------------------------------------------------------------------- diff --git a/NorthstarDedicatedTest/NetAdr2.h b/NorthstarDedicatedTest/NetAdr2.h index 1acd86c3..808d623d 100644 --- a/NorthstarDedicatedTest/NetAdr2.h +++ b/NorthstarDedicatedTest/NetAdr2.h @@ -73,6 +73,7 @@ public: void ToSockadr(sockaddr_storage* pSadr) const; void ToAdrinfo(addrinfo* pHint) const; + bool IsValidPort(const std::string& svInPort) const; bool IsLocalhost(void) const; bool IsLoopback(void) const; bool IsReservedAdr(void) const; diff --git a/NorthstarDedicatedTest/cl_rcon.cpp b/NorthstarDedicatedTest/cl_rcon.cpp index cdb746c9..00353a18 100644 --- a/NorthstarDedicatedTest/cl_rcon.cpp +++ b/NorthstarDedicatedTest/cl_rcon.cpp @@ -58,7 +58,7 @@ bool CRConClient::Connect(void) if (m_pSocket->ConnectSocket(*m_pNetAdr2, true) == SOCKET_ERROR) { - spdlog::info("Connection to RCON server failed: (SOCKET_ERROR)"); + spdlog::info("Connection to RCON server '{}' failed: (SOCKET_ERROR)", m_pNetAdr2->GetIPAndPort()); return false; } spdlog::info("Connected to: {}", m_pNetAdr2->GetIPAndPort().c_str()); @@ -83,7 +83,7 @@ bool CRConClient::Connect(const std::string& svInAdr, const std::string& svInPor if (m_pSocket->ConnectSocket(*m_pNetAdr2, true) == SOCKET_ERROR) { - spdlog::info("Connection to RCON server failed: (SOCKET_ERROR)"); + spdlog::info("Connection to RCON server '{}' failed: (SOCKET_ERROR)", m_pNetAdr2->GetIPAndPort()); return false; } spdlog::info("Connected to: {}", m_pNetAdr2->GetIPAndPort().c_str()); @@ -210,12 +210,14 @@ void CRConClient::ProcessMessage(const sv_rcon::response& sv_response) const { case sv_rcon::response_t::SERVERDATA_RESPONSE_AUTH: { + svOut.erase(std::remove(svOut.begin(), svOut.end(), '\n'), svOut.end()); spdlog::info("{}", svOut.c_str()); break; } case sv_rcon::response_t::SERVERDATA_RESPONSE_CONSOLE_LOG: { // !TODO: Network the enum to differentiate script/engine logs. + svOut.erase(std::remove(svOut.begin(), svOut.end(), '\n'), svOut.end()); spdlog::info("{}", svOut.c_str()); break; } diff --git a/NorthstarDedicatedTest/dedicated.cpp b/NorthstarDedicatedTest/dedicated.cpp index 75b95125..4add29c7 100644 --- a/NorthstarDedicatedTest/dedicated.cpp +++ b/NorthstarDedicatedTest/dedicated.cpp @@ -54,9 +54,6 @@ void RunServer(CDedicatedExports* dedicated) // ensure playlist initialises right, if we've not explicitly called setplaylist SetCurrentPlaylist(GetCurrentPlaylistName()); - // Initialize RCON server - g_pRConServer->Init(); - // note: we no longer manually set map and hoststate to start server in g_pHostState, we just use +map which seems to initialise stuff // better @@ -66,7 +63,6 @@ void RunServer(CDedicatedExports* dedicated) { double frameStart = Plat_FloatTime(); g_pEngine->Frame(); - g_pRConServer->RunFrame(); // only update the title after at least 500ms since the last update if ((frameStart - frameTitle) > 0.5) diff --git a/NorthstarDedicatedTest/rcon_shared.cpp b/NorthstarDedicatedTest/rcon_shared.cpp index a4127971..25ad11c1 100644 --- a/NorthstarDedicatedTest/rcon_shared.cpp +++ b/NorthstarDedicatedTest/rcon_shared.cpp @@ -108,7 +108,7 @@ _RCON_Disconnect_f */ void _RCON_Disconnect_f(const CCommand& args) { - if (IsDedicated) + if (IsDedicated()) { return; } diff --git a/NorthstarDedicatedTest/squirrel.cpp b/NorthstarDedicatedTest/squirrel.cpp index 6ff844a4..750ec54a 100644 --- a/NorthstarDedicatedTest/squirrel.cpp +++ b/NorthstarDedicatedTest/squirrel.cpp @@ -295,7 +295,7 @@ template void ScriptCompileErrorHook(void* sqvm, const c realContext = ScriptContext::UI; snprintf( - buffer, sizeof(buffer), "%s SCRIPT COMPILE ERROR %s\n%s line [%s] column [%s]", GetContextName(realContext), error, file, line, + buffer, sizeof(buffer), "%s SCRIPT COMPILE ERROR %s\n%s line [%d] column [%d]", GetContextName(realContext), error, file, line, column); spdlog::error("{}", buffer); if (IsDedicated()) diff --git a/NorthstarDedicatedTest/sv_rcon.cpp b/NorthstarDedicatedTest/sv_rcon.cpp index f4285c1b..7d81b887 100644 --- a/NorthstarDedicatedTest/sv_rcon.cpp +++ b/NorthstarDedicatedTest/sv_rcon.cpp @@ -365,7 +365,7 @@ void CRConServer::ProcessMessage(const cl_rcon::request& cl_request) { if (pData->m_bAuthorized) { - // TODO: Send conlog to true. + CVar_sv_rcon_sendlogs->SetValue(1); } break; } -- cgit v1.2.3