Parameterize changelevel or map in CServerListManager::LaunchServer()

Parameterized; whether or not to drop all clients (map = drop, changelevel = keep).
This commit is contained in:
Kawe Mazidjatari 2023-07-19 02:21:58 +02:00
parent 6cecc3297e
commit 54536a2652
3 changed files with 11 additions and 8 deletions

View File

@ -559,6 +559,9 @@ void CBrowser::HostPanel(void)
} }
ImGui::Spacing(); ImGui::Spacing();
const bool bServerActive = g_pServer->IsActive();
if (!g_pHostState->m_bActiveGame) if (!g_pHostState->m_bActiveGame)
{ {
if (ImGui::Button("Start server", ImVec2(ImGui::GetWindowContentRegionWidth(), 32))) if (ImGui::Button("Start server", ImVec2(ImGui::GetWindowContentRegionWidth(), 32)))
@ -568,7 +571,7 @@ void CBrowser::HostPanel(void)
bool bEnforceField = g_pServerListManager->m_ServerVisibility == EServerVisibility_t::OFFLINE ? true : !g_pServerListManager->m_Server.m_svHostName.empty(); bool bEnforceField = g_pServerListManager->m_ServerVisibility == EServerVisibility_t::OFFLINE ? true : !g_pServerListManager->m_Server.m_svHostName.empty();
if (bEnforceField && !g_pServerListManager->m_Server.m_svPlaylist.empty() && !g_pServerListManager->m_Server.m_svHostMap.empty()) if (bEnforceField && !g_pServerListManager->m_Server.m_svPlaylist.empty() && !g_pServerListManager->m_Server.m_svHostMap.empty())
{ {
g_pServerListManager->LaunchServer(); // Launch server. g_pServerListManager->LaunchServer(bServerActive); // Launch server.
} }
else else
{ {
@ -622,7 +625,7 @@ void CBrowser::HostPanel(void)
{ {
if (!g_pServerListManager->m_Server.m_svHostMap.empty()) if (!g_pServerListManager->m_Server.m_svHostMap.empty())
{ {
g_pServerListManager->LaunchServer(); g_pServerListManager->LaunchServer(bServerActive);
} }
else else
{ {
@ -631,7 +634,7 @@ void CBrowser::HostPanel(void)
} }
} }
if (g_pServer->IsActive()) if (bServerActive)
{ {
ImGui::Spacing(); ImGui::Spacing();
ImGui::Separator(); ImGui::Separator();

View File

@ -55,13 +55,13 @@ void CServerListManager::ClearServerList(void)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: Launch server with given parameters // Purpose: Launch server with given parameters
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void CServerListManager::LaunchServer(void) const void CServerListManager::LaunchServer(const bool bChangeLevel) const
{ {
if (!ThreadInMainThread()) if (!ThreadInMainThread())
{ {
g_TaskScheduler->Dispatch([this]() g_TaskScheduler->Dispatch([this, bChangeLevel]()
{ {
this->LaunchServer(); this->LaunchServer(bChangeLevel);
}, 0); }, 0);
return; return;
} }
@ -77,7 +77,7 @@ void CServerListManager::LaunchServer(void) const
KeyValues::ParsePlaylists(m_Server.m_svPlaylist.c_str()); KeyValues::ParsePlaylists(m_Server.m_svPlaylist.c_str());
mp_gamemode->SetValue(m_Server.m_svPlaylist.c_str()); mp_gamemode->SetValue(m_Server.m_svPlaylist.c_str());
ProcessCommand(Format("%s \"%s\"", g_pServer->IsActive() ? "changelevel" : "map", m_Server.m_svHostMap.c_str()).c_str()); ProcessCommand(Format("%s \"%s\"", bChangeLevel ? "changelevel" : "map", m_Server.m_svHostMap.c_str()).c_str());
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -23,7 +23,7 @@ public:
size_t RefreshServerList(string& svMessage); size_t RefreshServerList(string& svMessage);
void ClearServerList(void); void ClearServerList(void);
void LaunchServer(void) const; void LaunchServer(const bool bChangeLevel) const;
void ConnectToServer(const string& svIp, const string& svPort, const string& svNetKey) const; void ConnectToServer(const string& svIp, const string& svPort, const string& svNetKey) const;
void ConnectToServer(const string& svServer, const string& svNetKey) const; void ConnectToServer(const string& svServer, const string& svNetKey) const;