From 26f52eea281263f6d550a2d4fc7e0c7939a1fc0d Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 12 Feb 2023 11:22:18 +0100 Subject: [PATCH] Server browser hosting logic improvements * Added missing mutex lock in 'CBrowser::UpdateHostingStatus' when host status is 'NOT_HOSTING'. * Use server's remote checksum to test whether or not the checksum is valid, as this is the one that will be used for hosting. * Construct 'NetGameServer_t' from the main thread instead, and dispatch back into separate thread for remote query. --- r5dev/gameui/IBrowser.cpp | 47 +++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/r5dev/gameui/IBrowser.cpp b/r5dev/gameui/IBrowser.cpp index dd7f0b9e..fb4027dd 100644 --- a/r5dev/gameui/IBrowser.cpp +++ b/r5dev/gameui/IBrowser.cpp @@ -672,7 +672,11 @@ void CBrowser::UpdateHostingStatus(void) { case EHostStatus_t::NOT_HOSTING: { - m_svHostToken.clear(); + std::lock_guard g(m_Mutex); + if (!m_svHostToken.empty()) + { + m_svHostToken.clear(); + } if (ImGui::ColorConvertFloat4ToU32(m_HostRequestMessageColor) == // Only clear if this is green (a valid hosting message). ImGui::ColorConvertFloat4ToU32(ImVec4(0.00f, 1.00f, 0.00f, 1.00f))) @@ -690,7 +694,7 @@ void CBrowser::UpdateHostingStatus(void) break; } - if (*g_nClientRemoteChecksum == NULL) // Check if script checksum is valid yet. + if (*g_nServerRemoteChecksum == NULL) // Check if script checksum is valid yet. { break; } @@ -708,28 +712,33 @@ void CBrowser::UpdateHostingStatus(void) break; } - NetGameServer_t netGameServer // !FIXME: create from main thread. + g_TaskScheduler->Dispatch([this]() { - g_pServerListManager->m_Server.m_svHostName, - g_pServerListManager->m_Server.m_svDescription, - g_pServerListManager->m_Server.m_bHidden, - g_pHostState->m_levelName, - mp_gamemode->GetString(), - hostip->GetString(), - hostport->GetString(), - g_pNetKey->GetBase64NetKey(), - std::to_string(*g_nServerRemoteChecksum), - SDK_VERSION, - std::to_string(g_pServer->GetNumHumanPlayers() + g_pServer->GetNumFakeClients()), - std::to_string(g_ServerGlobalVariables->m_nMaxClients), - std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch() - ).count() - }; + std::lock_guard l(g_pServerListManager->m_Mutex); + NetGameServer_t netGameServer + { + g_pServerListManager->m_Server.m_svHostName, + g_pServerListManager->m_Server.m_svDescription, + g_pServerListManager->m_Server.m_bHidden, + g_pHostState->m_levelName, + mp_gamemode->GetString(), + hostip->GetString(), + hostport->GetString(), + g_pNetKey->GetBase64NetKey(), + std::to_string(*g_nServerRemoteChecksum), + SDK_VERSION, + std::to_string(g_pServer->GetNumHumanPlayers() + g_pServer->GetNumFakeClients()), + std::to_string(g_ServerGlobalVariables->m_nMaxClients), + std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch() + ).count() + }; std::thread post(&CBrowser::SendHostingPostRequest, this, netGameServer); post.detach(); + }, 0); + break; } default: