2022-02-06 16:48:52 +01:00
|
|
|
//=============================================================================//
|
|
|
|
//
|
2022-02-14 23:16:24 +01:00
|
|
|
// Purpose: Runs the state machine for the host & server.
|
2022-02-06 16:48:52 +01:00
|
|
|
//
|
|
|
|
//=============================================================================//
|
2023-03-18 17:36:09 +01:00
|
|
|
// host_state.cpp:.
|
2022-05-20 20:14:39 +02:00
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
2021-12-25 22:36:38 +01:00
|
|
|
#include "core/stdafx.h"
|
2022-05-04 02:25:27 +02:00
|
|
|
#include "tier0/jobthread.h"
|
2022-01-10 02:47:19 +01:00
|
|
|
#include "tier0/commandline.h"
|
2022-03-25 02:30:36 +01:00
|
|
|
#include "tier0/fasttimer.h"
|
2022-04-09 16:16:40 +02:00
|
|
|
#include "tier1/cmd.h"
|
|
|
|
#include "tier1/cvar.h"
|
2023-01-29 15:12:27 +01:00
|
|
|
#include "tier1/NetAdr.h"
|
2022-02-06 16:48:52 +01:00
|
|
|
#include "tier2/socketcreator.h"
|
2022-03-26 00:24:13 +01:00
|
|
|
#include "vpc/keyvalues.h"
|
2022-04-29 05:30:06 +02:00
|
|
|
#include "datacache/mdlcache.h"
|
2023-01-29 16:07:02 +01:00
|
|
|
#ifndef CLIENT_DLL
|
2022-05-20 11:52:19 +02:00
|
|
|
#include "engine/server/sv_rcon.h"
|
2023-01-29 16:07:02 +01:00
|
|
|
#endif // !CLIENT_DLL
|
|
|
|
#ifndef DEDICATED
|
2022-05-20 11:52:19 +02:00
|
|
|
#include "engine/client/cl_rcon.h"
|
|
|
|
#include "engine/client/cl_main.h"
|
2022-11-10 11:47:02 +01:00
|
|
|
#include "engine/client/clientstate.h"
|
2022-02-08 16:32:00 +01:00
|
|
|
#endif // DEDICATED
|
2022-04-02 02:48:54 +02:00
|
|
|
#include "engine/net.h"
|
2022-03-01 02:39:46 +01:00
|
|
|
#include "engine/gl_screen.h"
|
2022-04-12 02:48:46 +02:00
|
|
|
#include "engine/host.h"
|
|
|
|
#include "engine/host_cmd.h"
|
2022-02-19 02:31:16 +01:00
|
|
|
#include "engine/host_state.h"
|
2022-03-01 02:39:46 +01:00
|
|
|
#include "engine/sys_engine.h"
|
2022-04-12 02:48:46 +02:00
|
|
|
#include "engine/modelloader.h"
|
2022-03-01 02:39:46 +01:00
|
|
|
#include "engine/cmodel_bsp.h"
|
2022-03-27 22:17:30 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2022-05-20 11:52:19 +02:00
|
|
|
#include "engine/server/server.h"
|
2022-03-27 22:17:30 +02:00
|
|
|
#endif // !CLIENT_DLL
|
2022-03-01 02:39:46 +01:00
|
|
|
#include "rtech/rtech_game.h"
|
2022-03-28 18:47:11 +02:00
|
|
|
#include "rtech/rtech_utils.h"
|
2022-04-12 02:48:46 +02:00
|
|
|
#include "rtech/stryder/stryder.h"
|
2022-02-19 02:31:16 +01:00
|
|
|
#ifndef DEDICATED
|
|
|
|
#include "vgui/vgui_baseui_interface.h"
|
2022-04-02 12:27:35 +02:00
|
|
|
#include "client/vengineclient_impl.h"
|
2022-08-17 02:04:01 +02:00
|
|
|
#endif // DEDICATED
|
2022-02-19 02:31:16 +01:00
|
|
|
#include "networksystem/pylon.h"
|
2022-09-01 01:32:32 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2022-08-09 17:34:10 +02:00
|
|
|
#include "networksystem/bansystem.h"
|
2022-09-01 01:32:32 +02:00
|
|
|
#endif // !CLIENT_DLL
|
2022-08-27 23:45:58 +02:00
|
|
|
#include "networksystem/listmanager.h"
|
2022-08-09 17:18:07 +02:00
|
|
|
#include "public/edict.h"
|
2022-03-27 22:17:30 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2022-02-24 01:51:11 +01:00
|
|
|
#include "game/server/gameinterface.h"
|
2022-03-27 22:17:30 +02:00
|
|
|
#endif // !CLIENT_DLL
|
2023-05-06 16:23:56 +02:00
|
|
|
#include "game/shared/vscript_shared.h"
|
2022-01-09 14:35:43 +01:00
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: state machine's main processing loop
|
|
|
|
//-----------------------------------------------------------------------------
|
2023-03-18 17:36:09 +01:00
|
|
|
void CHostState::FrameUpdate(CHostState* pHostState, double flCurrentTime, float flFrameTime)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
|
|
|
static bool bInitialized = false;
|
2022-09-14 21:51:15 +02:00
|
|
|
static bool bResetIdleName = false;
|
2021-12-25 22:36:38 +01:00
|
|
|
if (!bInitialized)
|
|
|
|
{
|
2022-02-19 02:31:16 +01:00
|
|
|
g_pHostState->Setup();
|
2021-12-25 22:36:38 +01:00
|
|
|
bInitialized = true;
|
|
|
|
}
|
2022-08-27 23:45:58 +02:00
|
|
|
|
|
|
|
g_pHostState->Think();
|
2023-01-29 16:07:02 +01:00
|
|
|
#ifndef CLIENT_DLL
|
2022-07-25 19:35:08 +02:00
|
|
|
RCONServer()->RunFrame();
|
2023-01-29 16:07:02 +01:00
|
|
|
#endif // !CLIENT_DLL
|
|
|
|
#ifndef DEDICATED
|
2022-07-25 19:35:08 +02:00
|
|
|
RCONClient()->RunFrame();
|
2023-01-29 16:07:02 +01:00
|
|
|
#endif // !DEDICATED
|
2022-02-06 16:48:52 +01:00
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
HostStates_t oldState{};
|
2023-04-03 14:55:16 +02:00
|
|
|
|
|
|
|
// Disable "warning C4611: interaction between '_setjmp' and C++ object destruction is non-portable"
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable : 4611)
|
2022-04-12 02:48:46 +02:00
|
|
|
if (setjmp(*host_abortserver))
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-04-12 02:48:46 +02:00
|
|
|
g_pHostState->Init();
|
2021-12-25 22:36:38 +01:00
|
|
|
return;
|
|
|
|
}
|
2023-04-03 14:55:16 +02:00
|
|
|
#pragma warning(pop)
|
2021-12-25 22:36:38 +01:00
|
|
|
else
|
|
|
|
{
|
2022-03-27 22:17:30 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2022-04-12 02:48:46 +02:00
|
|
|
*g_bAbortServerSet = true;
|
2022-03-27 22:17:30 +02:00
|
|
|
#endif // !CLIENT_DLL
|
2021-12-25 22:36:38 +01:00
|
|
|
do
|
|
|
|
{
|
2022-02-19 02:31:16 +01:00
|
|
|
Cbuf_Execute();
|
2021-12-25 22:36:38 +01:00
|
|
|
oldState = g_pHostState->m_iCurrentState;
|
2022-01-05 19:23:53 +01:00
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
switch (g_pHostState->m_iCurrentState)
|
|
|
|
{
|
|
|
|
case HostStates_t::HS_NEW_GAME:
|
|
|
|
{
|
2022-02-19 02:31:16 +01:00
|
|
|
g_pHostState->State_NewGame();
|
2021-12-25 22:36:38 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case HostStates_t::HS_CHANGE_LEVEL_SP:
|
|
|
|
{
|
2022-02-19 02:31:16 +01:00
|
|
|
g_pHostState->State_ChangeLevelSP();
|
2021-12-25 22:36:38 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case HostStates_t::HS_CHANGE_LEVEL_MP:
|
|
|
|
{
|
2022-02-19 02:31:16 +01:00
|
|
|
g_pHostState->State_ChangeLevelMP();
|
2021-12-25 22:36:38 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case HostStates_t::HS_RUN:
|
|
|
|
{
|
2022-09-14 21:51:15 +02:00
|
|
|
if (!g_pHostState->m_bActiveGame)
|
|
|
|
{
|
|
|
|
if (bResetIdleName)
|
|
|
|
{
|
|
|
|
g_pHostState->ResetLevelName();
|
|
|
|
bResetIdleName = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // Reset idle name the next non-active frame.
|
|
|
|
{
|
|
|
|
bResetIdleName = true;
|
|
|
|
}
|
|
|
|
|
2022-07-17 12:16:31 +02:00
|
|
|
CHostState_State_Run(&g_pHostState->m_iCurrentState, flCurrentTime, flFrameTime);
|
2021-12-25 22:36:38 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case HostStates_t::HS_GAME_SHUTDOWN:
|
|
|
|
{
|
2023-01-31 14:31:17 +01:00
|
|
|
DevMsg(eDLL_T::ENGINE, "%s: Shutdown host game\n", __FUNCTION__);
|
2022-04-14 19:18:59 +02:00
|
|
|
CHostState_State_GameShutDown(g_pHostState);
|
2021-12-25 22:36:38 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case HostStates_t::HS_RESTART:
|
|
|
|
{
|
2023-01-31 14:31:17 +01:00
|
|
|
DevMsg(eDLL_T::ENGINE, "%s: Restarting state machine\n", __FUNCTION__);
|
2022-02-19 02:31:16 +01:00
|
|
|
#ifndef DEDICATED
|
2022-04-12 02:48:46 +02:00
|
|
|
CL_EndMovie();
|
2022-02-19 02:31:16 +01:00
|
|
|
#endif // !DEDICATED
|
2022-04-12 02:48:46 +02:00
|
|
|
Stryder_SendOfflineRequest(); // We have hostnames nulled anyway.
|
2022-08-09 11:53:33 +02:00
|
|
|
g_pEngine->SetNextState(IEngine::DLL_RESTART);
|
2021-12-25 22:36:38 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case HostStates_t::HS_SHUTDOWN:
|
|
|
|
{
|
2023-01-31 14:31:17 +01:00
|
|
|
DevMsg(eDLL_T::ENGINE, "%s: Shutdown state machine\n", __FUNCTION__);
|
2022-02-19 02:31:16 +01:00
|
|
|
#ifndef DEDICATED
|
2022-04-12 02:48:46 +02:00
|
|
|
CL_EndMovie();
|
2022-02-19 02:31:16 +01:00
|
|
|
#endif // !DEDICATED
|
2022-04-12 02:48:46 +02:00
|
|
|
Stryder_SendOfflineRequest(); // We have hostnames nulled anyway.
|
2022-08-09 11:53:33 +02:00
|
|
|
g_pEngine->SetNextState(IEngine::DLL_CLOSE);
|
2021-12-25 22:36:38 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-08 19:00:28 +02:00
|
|
|
} while ((oldState != HostStates_t::HS_RUN || (g_pHostState->m_iNextState == HostStates_t::HS_LOAD_GAME && single_frame_shutdown_for_reload->GetBool()))
|
2021-12-25 22:36:38 +01:00
|
|
|
&& oldState != HostStates_t::HS_SHUTDOWN
|
|
|
|
&& oldState != HostStates_t::HS_RESTART);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-19 02:31:16 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-04-12 02:48:46 +02:00
|
|
|
// Purpose: state machine initialization
|
|
|
|
//-----------------------------------------------------------------------------
|
2023-03-18 17:36:09 +01:00
|
|
|
void CHostState::Init(void)
|
2022-04-12 02:48:46 +02:00
|
|
|
{
|
|
|
|
if (m_iNextState != HostStates_t::HS_SHUTDOWN)
|
|
|
|
{
|
|
|
|
if (m_iNextState == HostStates_t::HS_GAME_SHUTDOWN)
|
|
|
|
{
|
2022-04-14 19:18:59 +02:00
|
|
|
CHostState_State_GameShutDown(this);
|
2022-04-12 02:48:46 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_iCurrentState = HostStates_t::HS_RUN;
|
|
|
|
if (m_iNextState != HostStates_t::HS_SHUTDOWN || !single_frame_shutdown_for_reload->GetInt())
|
|
|
|
m_iNextState = HostStates_t::HS_RUN;
|
|
|
|
}
|
|
|
|
}
|
2022-08-27 23:45:58 +02:00
|
|
|
m_flShortFrameTime = 1.0f;
|
2023-02-18 19:18:00 +01:00
|
|
|
m_bActiveGame = false;
|
|
|
|
m_bRememberLocation = false;
|
|
|
|
m_bBackgroundLevel = false;
|
|
|
|
m_bWaitingForConnection = false;
|
2022-04-12 02:48:46 +02:00
|
|
|
m_levelName[0] = 0;
|
|
|
|
m_landMarkName[0] = 0;
|
|
|
|
m_mapGroupName[0] = 0;
|
2023-02-18 19:18:00 +01:00
|
|
|
m_bSplitScreenConnect = false;
|
|
|
|
m_bGameHasShutDownAndFlushedMemory = true;
|
2022-04-12 02:48:46 +02:00
|
|
|
m_vecLocation.Init();
|
|
|
|
m_angLocation.Init();
|
2023-02-18 19:18:00 +01:00
|
|
|
m_iServerState = HostStates_t::HS_NEW_GAME;
|
2022-04-12 02:48:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: state machine setup
|
2022-02-19 02:31:16 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2023-03-18 17:36:09 +01:00
|
|
|
void CHostState::Setup(void)
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
|
|
|
g_pHostState->LoadConfig();
|
2022-09-01 01:32:32 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2022-08-30 12:07:09 +02:00
|
|
|
g_pBanSystem->Load();
|
2022-09-01 01:32:32 +02:00
|
|
|
#endif // !CLIENT_DLL
|
2022-11-18 22:10:20 +01:00
|
|
|
ConVar::PurgeHostNames();
|
2022-02-19 02:31:16 +01:00
|
|
|
|
2023-04-30 11:39:20 +02:00
|
|
|
#ifndef CLIENT_DLL
|
|
|
|
RCONServer()->Init();
|
|
|
|
#endif // !CLIENT_DLL
|
|
|
|
#ifndef DEDICATED
|
|
|
|
RCONClient()->Init();
|
|
|
|
#endif // !DEDICATED
|
|
|
|
|
2022-04-27 18:22:08 +02:00
|
|
|
if (net_useRandomKey->GetBool())
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
2022-04-02 02:48:54 +02:00
|
|
|
NET_GenerateKey();
|
2022-02-19 02:31:16 +01:00
|
|
|
}
|
2023-04-16 11:57:45 +02:00
|
|
|
#if !defined (DEDICATED) && !defined (CLIENT_DLL)
|
|
|
|
// Parallel processing of 'C_BaseAnimating::SetupBones()' is currently
|
|
|
|
// not supported on listen servers running the local client due to an
|
|
|
|
// engine bug specific to S3 that still needs to be addressed. Remove
|
|
|
|
// this once the issue has been solved:
|
|
|
|
if (cl_threaded_bone_setup->GetBool())
|
|
|
|
{
|
|
|
|
cl_threaded_bone_setup->SetValue(false);
|
|
|
|
}
|
|
|
|
#endif // !DEDICATED && !CLIENT_DLL
|
|
|
|
|
2022-05-04 02:25:27 +02:00
|
|
|
ResetLevelName();
|
2022-02-19 02:31:16 +01:00
|
|
|
}
|
|
|
|
|
2022-02-27 19:47:29 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: think
|
|
|
|
//-----------------------------------------------------------------------------
|
2023-03-18 17:36:09 +01:00
|
|
|
void CHostState::Think(void) const
|
2022-02-27 19:47:29 +01:00
|
|
|
{
|
2023-04-10 23:11:52 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2022-03-26 01:19:02 +01:00
|
|
|
static bool bInitialized = false;
|
2023-04-10 23:11:52 +02:00
|
|
|
static CFastTimer statsTimer;
|
2022-03-25 02:30:36 +01:00
|
|
|
static CFastTimer banListTimer;
|
2023-04-10 23:11:52 +02:00
|
|
|
#ifdef DEDICATED
|
2022-03-25 02:30:36 +01:00
|
|
|
static CFastTimer pylonTimer;
|
2023-04-10 23:11:52 +02:00
|
|
|
#endif // DEDICATED
|
2022-03-25 02:30:36 +01:00
|
|
|
|
2022-08-27 23:45:58 +02:00
|
|
|
if (!bInitialized) // Initialize clocks.
|
2022-03-26 00:24:13 +01:00
|
|
|
{
|
2023-04-10 23:11:52 +02:00
|
|
|
statsTimer.Start();
|
2022-08-27 23:45:58 +02:00
|
|
|
banListTimer.Start();
|
2022-03-26 18:06:54 +01:00
|
|
|
#ifdef DEDICATED
|
2022-08-27 23:45:58 +02:00
|
|
|
pylonTimer.Start();
|
2022-03-26 18:06:54 +01:00
|
|
|
#endif // DEDICATED
|
2022-08-27 23:45:58 +02:00
|
|
|
bInitialized = true;
|
|
|
|
}
|
2023-04-10 23:11:52 +02:00
|
|
|
if (sv_autoReloadRate->GetBool())
|
|
|
|
{
|
|
|
|
if (g_ServerGlobalVariables->m_flCurTime > sv_autoReloadRate->GetDouble())
|
|
|
|
{
|
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "reload\n", cmd_source_t::kCommandSrcCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (statsTimer.GetDurationInProgress().GetSeconds() > sv_statusRefreshRate->GetDouble())
|
|
|
|
{
|
|
|
|
SetConsoleTitleA(Format("%s - %d/%d Players (%s on %s)",
|
|
|
|
hostname->GetString(), g_pServer->GetNumClients(),
|
|
|
|
g_ServerGlobalVariables->m_nMaxClients, KeyValues_GetCurrentPlaylist(), m_levelName).c_str());
|
|
|
|
|
|
|
|
statsTimer.Start();
|
|
|
|
}
|
2023-04-28 23:47:58 +02:00
|
|
|
if (sv_globalBanlist->GetBool() &&
|
|
|
|
banListTimer.GetDurationInProgress().GetSeconds() > sv_banlistRefreshRate->GetDouble())
|
2022-08-27 23:45:58 +02:00
|
|
|
{
|
2023-04-28 23:47:58 +02:00
|
|
|
SV_CheckForBan();
|
2022-08-27 23:45:58 +02:00
|
|
|
banListTimer.Start();
|
|
|
|
}
|
2022-03-26 18:06:54 +01:00
|
|
|
#ifdef DEDICATED
|
2022-09-22 00:22:43 +02:00
|
|
|
if (pylonTimer.GetDurationInProgress().GetSeconds() > sv_pylonRefreshRate->GetDouble())
|
2022-08-27 23:45:58 +02:00
|
|
|
{
|
|
|
|
const NetGameServer_t netGameServer
|
2022-03-26 18:06:54 +01:00
|
|
|
{
|
2022-08-27 23:45:58 +02:00
|
|
|
hostname->GetString(),
|
|
|
|
hostdesc->GetString(),
|
|
|
|
sv_pylonVisibility->GetInt() == EServerVisibility_t::HIDDEN,
|
|
|
|
g_pHostState->m_levelName,
|
|
|
|
mp_gamemode->GetString(),
|
|
|
|
hostip->GetString(),
|
|
|
|
hostport->GetString(),
|
2023-02-12 11:49:39 +01:00
|
|
|
g_pNetKey->GetBase64NetKey(),
|
2022-08-27 23:45:58 +02:00
|
|
|
std::to_string(*g_nServerRemoteChecksum),
|
|
|
|
SDK_VERSION,
|
2023-02-12 15:21:33 +01:00
|
|
|
std::to_string(g_pServer->GetNumClients()),
|
2022-08-27 23:45:58 +02:00
|
|
|
std::to_string(g_ServerGlobalVariables->m_nMaxClients),
|
|
|
|
std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
|
|
std::chrono::system_clock::now().time_since_epoch()
|
|
|
|
).count()
|
|
|
|
};
|
|
|
|
|
2022-08-30 12:07:09 +02:00
|
|
|
std::thread(&CPylon::KeepAlive, g_pMasterServer, netGameServer).detach();
|
2022-08-27 23:45:58 +02:00
|
|
|
pylonTimer.Start();
|
|
|
|
}
|
2022-03-26 18:06:54 +01:00
|
|
|
#endif // DEDICATED
|
2022-08-27 23:45:58 +02:00
|
|
|
#endif // !CLIENT_DLL
|
2022-02-27 19:47:29 +01:00
|
|
|
}
|
|
|
|
|
2022-02-19 02:31:16 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-02-19 02:43:20 +01:00
|
|
|
// Purpose: load and execute configuration files
|
2022-02-19 02:31:16 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2023-03-18 17:36:09 +01:00
|
|
|
void CHostState::LoadConfig(void) const
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
2022-05-25 12:07:08 +02:00
|
|
|
if (CommandLine()->ParmValue("-launcher", 0) < 1) // Launcher level 1 indicates everything is handled from the commandline/launcher.
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
2022-05-24 02:23:37 +02:00
|
|
|
if (!CommandLine()->CheckParm("-devsdk"))
|
|
|
|
{
|
2023-04-30 11:39:20 +02:00
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec.cfg\"", cmd_source_t::kCommandSrcCode);
|
2022-03-28 12:02:11 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2022-05-24 02:23:37 +02:00
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec_server.cfg\"", cmd_source_t::kCommandSrcCode);
|
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"rcon_server.cfg\"", cmd_source_t::kCommandSrcCode);
|
2022-03-28 12:02:11 +02:00
|
|
|
#endif //!CLIENT_DLL
|
2022-02-19 02:31:16 +01:00
|
|
|
#ifndef DEDICATED
|
2022-05-24 02:23:37 +02:00
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec_client.cfg\"", cmd_source_t::kCommandSrcCode);
|
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"rcon_client.cfg\"", cmd_source_t::kCommandSrcCode);
|
2022-02-19 02:31:16 +01:00
|
|
|
#endif // !DEDICATED
|
2022-05-24 02:23:37 +02:00
|
|
|
}
|
|
|
|
else // Development configs.
|
|
|
|
{
|
2023-04-30 11:39:20 +02:00
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec_dev.cfg\"", cmd_source_t::kCommandSrcCode);
|
2022-03-28 12:02:11 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2022-05-24 02:23:37 +02:00
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec_server_dev.cfg\"", cmd_source_t::kCommandSrcCode);
|
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"rcon_server_dev.cfg\"", cmd_source_t::kCommandSrcCode);
|
2022-03-28 12:02:11 +02:00
|
|
|
#endif //!CLIENT_DLL
|
2022-02-19 02:31:16 +01:00
|
|
|
#ifndef DEDICATED
|
2022-05-24 02:23:37 +02:00
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"autoexec_client_dev.cfg\"", cmd_source_t::kCommandSrcCode);
|
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"rcon_client_dev.cfg\"", cmd_source_t::kCommandSrcCode);
|
2022-02-19 02:31:16 +01:00
|
|
|
#endif // !DEDICATED
|
2022-05-24 02:23:37 +02:00
|
|
|
}
|
2022-11-10 15:42:27 +01:00
|
|
|
#ifndef DEDICATED
|
|
|
|
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec \"bind.cfg\"", cmd_source_t::kCommandSrcCode);
|
|
|
|
#endif // !DEDICATED
|
2022-02-19 02:31:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-01 02:39:46 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: shutdown active game
|
|
|
|
//-----------------------------------------------------------------------------
|
2023-03-18 17:36:09 +01:00
|
|
|
void CHostState::GameShutDown(void)
|
2022-03-01 02:39:46 +01:00
|
|
|
{
|
|
|
|
if (m_bActiveGame)
|
|
|
|
{
|
2022-03-27 22:17:30 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2022-03-01 02:39:46 +01:00
|
|
|
g_pServerGameDLL->GameShutdown();
|
2022-03-27 22:17:30 +02:00
|
|
|
#endif // !CLIENT_DLL
|
2022-09-18 13:55:44 +02:00
|
|
|
m_bActiveGame = false;
|
2022-09-14 21:59:32 +02:00
|
|
|
ResetLevelName();
|
2022-03-01 02:39:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-19 02:31:16 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-02-19 02:43:20 +01:00
|
|
|
// Purpose: initialize new game
|
2022-02-19 02:31:16 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2023-03-18 17:36:09 +01:00
|
|
|
void CHostState::State_NewGame(void)
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
2023-01-31 14:31:17 +01:00
|
|
|
DevMsg(eDLL_T::ENGINE, "%s: Loading level: '%s'\n", __FUNCTION__, g_pHostState->m_levelName);
|
2022-12-22 00:44:53 +01:00
|
|
|
|
2022-04-12 02:48:46 +02:00
|
|
|
LARGE_INTEGER time{};
|
2023-02-18 19:18:00 +01:00
|
|
|
bool bSplitScreenConnect = m_bSplitScreenConnect;
|
|
|
|
m_bSplitScreenConnect = 0;
|
2022-05-12 19:39:55 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2022-04-12 02:48:46 +02:00
|
|
|
if (!g_pServerGameClients) // Init Game if it ain't valid.
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
2022-04-12 02:48:46 +02:00
|
|
|
SV_InitGameDLL();
|
2022-02-19 02:31:16 +01:00
|
|
|
}
|
2022-05-12 19:39:55 +02:00
|
|
|
#endif // !CLIENT_DLL
|
2022-02-19 02:31:16 +01:00
|
|
|
|
2022-05-12 19:39:55 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2022-04-12 02:48:46 +02:00
|
|
|
if (!CModelLoader__Map_IsValid(g_pModelLoader, m_levelName) // Check if map is valid and if we can start a new game.
|
2023-04-10 19:14:59 +02:00
|
|
|
|| !v_Host_NewGame(m_levelName, nullptr, m_bBackgroundLevel, bSplitScreenConnect, time) || !g_pServerGameClients)
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
2023-04-30 11:39:20 +02:00
|
|
|
Error(eDLL_T::ENGINE, NO_ERROR, "%s: Level not valid\n", __FUNCTION__);
|
2022-02-19 02:31:16 +01:00
|
|
|
#ifndef DEDICATED
|
|
|
|
SCR_EndLoadingPlaque();
|
|
|
|
#endif // !DEDICATED
|
|
|
|
GameShutDown();
|
|
|
|
}
|
2022-05-12 19:39:55 +02:00
|
|
|
#endif // !CLIENT_DLL
|
2022-02-19 02:31:16 +01:00
|
|
|
|
|
|
|
m_iCurrentState = HostStates_t::HS_RUN; // Set current state to run.
|
|
|
|
|
|
|
|
// If our next state isn't a shutdown or its a forced shutdown then set next state to run.
|
2022-04-14 19:18:59 +02:00
|
|
|
if (m_iNextState != HostStates_t::HS_SHUTDOWN || !host_hasIrreversibleShutdown->GetBool())
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
|
|
|
m_iNextState = HostStates_t::HS_RUN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-02-19 02:43:20 +01:00
|
|
|
// Purpose: change singleplayer level
|
2022-02-19 02:31:16 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2023-03-18 17:36:09 +01:00
|
|
|
void CHostState::State_ChangeLevelSP(void)
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
2023-01-31 14:31:17 +01:00
|
|
|
DevMsg(eDLL_T::ENGINE, "%s: Changing singleplayer level to: '%s'\n", __FUNCTION__, m_levelName);
|
2022-02-19 02:31:16 +01:00
|
|
|
m_flShortFrameTime = 1.5; // Set frame time.
|
|
|
|
|
2022-04-12 02:48:46 +02:00
|
|
|
if (CModelLoader__Map_IsValid(g_pModelLoader, m_levelName)) // Check if map is valid and if we can start a new game.
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
2023-04-10 19:14:59 +02:00
|
|
|
v_Host_ChangeLevel(true, m_levelName, m_mapGroupName); // Call change level as singleplayer level.
|
2022-02-19 02:31:16 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-04-30 11:39:20 +02:00
|
|
|
Error(eDLL_T::ENGINE, NO_ERROR, "%s: Unable to find level: '%s'\n", __FUNCTION__, m_levelName);
|
2022-02-19 02:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
m_iCurrentState = HostStates_t::HS_RUN; // Set current state to run.
|
|
|
|
|
|
|
|
// If our next state isn't a shutdown or its a forced shutdown then set next state to run.
|
2022-04-14 19:18:59 +02:00
|
|
|
if (m_iNextState != HostStates_t::HS_SHUTDOWN || !host_hasIrreversibleShutdown->GetBool())
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
|
|
|
m_iNextState = HostStates_t::HS_RUN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-02-19 02:43:20 +01:00
|
|
|
// Purpose: change multiplayer level
|
2022-02-19 02:31:16 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2023-03-18 17:36:09 +01:00
|
|
|
void CHostState::State_ChangeLevelMP(void)
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
2023-01-31 14:31:17 +01:00
|
|
|
DevMsg(eDLL_T::ENGINE, "%s: Changing multiplayer level to: '%s'\n", __FUNCTION__, m_levelName);
|
2022-02-19 02:31:16 +01:00
|
|
|
m_flShortFrameTime = 0.5; // Set frame time.
|
|
|
|
|
2022-03-27 22:17:30 +02:00
|
|
|
#ifndef CLIENT_DLL
|
2022-02-24 01:51:11 +01:00
|
|
|
g_pServerGameDLL->LevelShutdown();
|
2022-03-27 22:17:30 +02:00
|
|
|
#endif // !CLIENT_DLL
|
2022-04-12 02:48:46 +02:00
|
|
|
if (CModelLoader__Map_IsValid(g_pModelLoader, m_levelName)) // Check if map is valid and if we can start a new game.
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
|
|
|
#ifndef DEDICATED
|
2022-04-18 03:35:08 +02:00
|
|
|
g_pEngineVGui->EnabledProgressBarForNextLoad();
|
2022-02-19 02:31:16 +01:00
|
|
|
#endif // !DEDICATED
|
2023-04-10 19:14:59 +02:00
|
|
|
v_Host_ChangeLevel(false, m_levelName, m_mapGroupName); // Call change level as multiplayer level.
|
2022-02-19 02:31:16 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-04-30 11:39:20 +02:00
|
|
|
Error(eDLL_T::ENGINE, NO_ERROR, "%s: Unable to find level: '%s'\n", __FUNCTION__, m_levelName);
|
2022-02-19 02:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
m_iCurrentState = HostStates_t::HS_RUN; // Set current state to run.
|
|
|
|
|
|
|
|
// If our next state isn't a shutdown or its a forced shutdown then set next state to run.
|
2022-04-14 19:18:59 +02:00
|
|
|
if (m_iNextState != HostStates_t::HS_SHUTDOWN || !host_hasIrreversibleShutdown->GetBool())
|
2022-02-19 02:31:16 +01:00
|
|
|
{
|
|
|
|
m_iNextState = HostStates_t::HS_RUN;
|
|
|
|
}
|
2022-05-04 02:25:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: resets the level name
|
|
|
|
//-----------------------------------------------------------------------------
|
2023-03-18 17:36:09 +01:00
|
|
|
void CHostState::ResetLevelName(void)
|
2022-05-04 02:25:27 +02:00
|
|
|
{
|
2023-02-26 19:44:16 +01:00
|
|
|
static const char* szNoMap = "no_map";
|
2023-04-08 19:14:00 +02:00
|
|
|
Q_snprintf(const_cast<char*>(m_levelName), sizeof(m_levelName), "%s", szNoMap);
|
2022-05-04 02:25:27 +02:00
|
|
|
}
|
|
|
|
|
2023-01-25 02:26:52 +01:00
|
|
|
void VHostState::Attach(void) const
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-11-10 11:47:02 +01:00
|
|
|
DetourAttach(&CHostState_FrameUpdate, &CHostState::FrameUpdate);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
2023-01-25 02:26:52 +01:00
|
|
|
void VHostState::Detach(void) const
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-11-10 11:47:02 +01:00
|
|
|
DetourDetach(&CHostState_FrameUpdate, &CHostState::FrameUpdate);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
|
2022-02-19 02:31:16 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2022-04-12 02:48:46 +02:00
|
|
|
CHostState* g_pHostState = nullptr;
|