From 6cecc3297e02bd553146d1a9b43ed523bb624303 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Wed, 19 Jul 2023 02:19:43 +0200 Subject: [PATCH] Move KeepAlive function to HostState Only used in HostState, moved to HostState with static linkage. --- r5dev/engine/host_state.cpp | 47 +++++++++++++++++++++++++++++++++-- r5dev/networksystem/pylon.cpp | 38 ---------------------------- r5dev/networksystem/pylon.h | 1 - 3 files changed, 45 insertions(+), 41 deletions(-) diff --git a/r5dev/engine/host_state.cpp b/r5dev/engine/host_state.cpp index f8ee976f..b33c96e2 100644 --- a/r5dev/engine/host_state.cpp +++ b/r5dev/engine/host_state.cpp @@ -17,6 +17,7 @@ #include "datacache/mdlcache.h" #ifndef CLIENT_DLL #include "engine/server/sv_rcon.h" +#include "engine/server/server.h" #endif // !CLIENT_DLL #ifndef DEDICATED #include "engine/client/cl_rcon.h" @@ -53,6 +54,46 @@ #endif // !CLIENT_DLL #include "game/shared/vscript_shared.h" +#ifndef CLIENT_DLL +//----------------------------------------------------------------------------- +// Purpose: Send keep alive request to Pylon Master Server. +// Input : &netGameServer - +// Output : Returns true on success, false otherwise. +//----------------------------------------------------------------------------- +static bool HostState_KeepAlive(const NetGameServer_t& netGameServer) +{ + if (!g_pServer->IsActive() || !sv_pylonVisibility->GetBool()) // Check for active game. + { + return false; + } + + string errorMsg; + string hostToken; + + const bool result = g_pMasterServer->PostServerHost(errorMsg, hostToken, netGameServer); + if (!result) + { + if (!errorMsg.empty() && g_pMasterServer->GetCurrentError().compare(errorMsg) != NULL) + { + g_pMasterServer->SetCurrentError(errorMsg); + Error(eDLL_T::SERVER, NO_ERROR, "%s\n", errorMsg.c_str()); + } + } + else // Attempt to log the token, if there is one. + { + if (!hostToken.empty() && g_pMasterServer->GetCurrentToken().compare(hostToken) != NULL) + { + g_pMasterServer->SetCurrentToken(hostToken); + DevMsg(eDLL_T::SERVER, "Published server with token: %s'%s%s%s'\n", + g_svReset, g_svGreyB, + hostToken.c_str(), g_svReset); + } + } + + return result; +} +#endif // !CLIENT_DLL + //----------------------------------------------------------------------------- // Purpose: state machine's main processing loop //----------------------------------------------------------------------------- @@ -303,7 +344,7 @@ void CHostState::Think(void) const ).count() }; - std::thread(&CPylon::KeepAlive, g_pMasterServer, netGameServer).detach(); + std::thread(&HostState_KeepAlive, netGameServer).detach(); pylonTimer.Start(); } #endif // DEDICATED @@ -370,9 +411,11 @@ void CHostState::State_NewGame(void) DevMsg(eDLL_T::ENGINE, "%s: Loading level: '%s'\n", __FUNCTION__, g_pHostState->m_levelName); LARGE_INTEGER time{}; + +#ifndef CLIENT_DLL bool bSplitScreenConnect = m_bSplitScreenConnect; m_bSplitScreenConnect = 0; -#ifndef CLIENT_DLL + if (!g_pServerGameClients) // Init Game if it ain't valid. { SV_InitGameDLL(); diff --git a/r5dev/networksystem/pylon.cpp b/r5dev/networksystem/pylon.cpp index 46ed2200..0c8b91ce 100644 --- a/r5dev/networksystem/pylon.cpp +++ b/r5dev/networksystem/pylon.cpp @@ -187,44 +187,6 @@ bool CPylon::PostServerHost(string& outMessage, string& outToken, return true; } -//----------------------------------------------------------------------------- -// Purpose: Send keep alive request to Pylon Master Server. -// Input : &netGameServer - -// Output : Returns true on success, false otherwise. -//----------------------------------------------------------------------------- -bool CPylon::KeepAlive(const NetGameServer_t& netGameServer) -{ - if (!g_pServer->IsActive() || !sv_pylonVisibility->GetBool()) // Check for active game. - { - return false; - } - - string errorMsg; - string hostToken; - - const bool result = PostServerHost(errorMsg, hostToken, netGameServer); - if (!result) - { - if (!errorMsg.empty() && m_ErrorMsg.compare(errorMsg) != NULL) - { - m_ErrorMsg = errorMsg; - Error(eDLL_T::SERVER, NO_ERROR, "%s\n", errorMsg.c_str()); - } - } - else // Attempt to log the token, if there is one. - { - if (!hostToken.empty() && m_Token.compare(hostToken) != NULL) - { - m_Token = hostToken; - DevMsg(eDLL_T::SERVER, "Published server with token: %s'%s%s%s'\n", - g_svReset, g_svGreyB, - hostToken.c_str(), g_svReset); - } - } - - return result; -} - //----------------------------------------------------------------------------- // Purpose: Checks a list of clients for their banned status. // Input : &inBannedVec - diff --git a/r5dev/networksystem/pylon.h b/r5dev/networksystem/pylon.h index a5dcae66..b7b7d1c9 100644 --- a/r5dev/networksystem/pylon.h +++ b/r5dev/networksystem/pylon.h @@ -20,7 +20,6 @@ public: bool SendRequest(const char* endpoint, const nlohmann::json& requestJson, nlohmann::json& responseJson, string& outMessage, CURLINFO& status, const char* errorText = nullptr) const; bool QueryServer(const char* endpoint, const char* request, string& outResponse, string& outMessage, CURLINFO& outStatus) const; - bool KeepAlive(const NetGameServer_t& netGameServer); inline const string& GetCurrentToken() const { return m_Token; } inline const string& GetCurrentError() const { return m_ErrorMsg; }