aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/dedicated.cpp
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2022-01-18 21:21:34 +0000
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2022-01-18 21:21:34 +0000
commite614f3797021959b008c2c502f9300501afae3ca (patch)
tree18ef5d5794baad8685f13480c827f9892d4429f5 /NorthstarDedicatedTest/dedicated.cpp
parente512279b5cb47fca0107fb5e80a3d0a468bb5e6f (diff)
downloadNorthstarLauncher-e614f3797021959b008c2c502f9300501afae3ca.tar.gz
NorthstarLauncher-e614f3797021959b008c2c502f9300501afae3ca.zip
improve dedicated startup
Diffstat (limited to 'NorthstarDedicatedTest/dedicated.cpp')
-rw-r--r--NorthstarDedicatedTest/dedicated.cpp29
1 files changed, 13 insertions, 16 deletions
diff --git a/NorthstarDedicatedTest/dedicated.cpp b/NorthstarDedicatedTest/dedicated.cpp
index 641fb42e..e6115415 100644
--- a/NorthstarDedicatedTest/dedicated.cpp
+++ b/NorthstarDedicatedTest/dedicated.cpp
@@ -36,30 +36,28 @@ typedef void(*CHostState__InitType)(CHostState* self);
void RunServer(CDedicatedExports* dedicated)
{
- Sys_Printf(dedicated, "CDedicatedExports::RunServer(): starting");
-
- // init hoststate, if we don't do this, we get a crash later on
- CHostState__InitType CHostState__Init = (CHostState__InitType)((char*)GetModuleHandleA("engine.dll") + 0x16E110);
- CHostState__Init(g_pHostState);
-
- // set host state to allow us to enter CHostState::FrameUpdate, with the state HS_NEW_GAME
- g_pHostState->m_iNextState = HostState_t::HS_NEW_GAME;
- strncpy(g_pHostState->m_levelName, CommandLine()->ParmValue("+map", Cvar_match_defaultMap->m_pszString), sizeof(g_pHostState->m_levelName)); // set map to load into
-
+ spdlog::info("CDedicatedExports::RunServer(): starting");
spdlog::info(CommandLine()->GetCmdLine());
- // run initial 2 ticks, 1 to initialise engine and 1 to load initial map
+ // initialise engine
g_pEngine->Frame();
- // run server autoexec
+ // add +map if not present
+ // don't manually execute this from cbuf as users may have it in their startup args anyway, easier just to run from stuffcmds if present
+ if (!CommandLine()->CheckParm("+map"))
+ CommandLine()->AppendParm("+map", Cvar_match_defaultMap->m_pszString);
+
+ // run server autoexec and re-run commandline
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "exec autoexec_ns_server", cmd_source_t::kCommandSrcCode);
+ Cbuf_AddText(Cbuf_GetCurrentPlayer(), "stuffcmds", cmd_source_t::kCommandSrcCode);
Cbuf_Execute();
- g_pEngine->Frame();
-
- // to fix a bug: set current playlist again, otherwise max_players will be set wrong
+ // ensure playlist initialises right, if we've not explicitly called setplaylist
SetCurrentPlaylist(GetCurrentPlaylistName());
+
+ // 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
+ // main loop
while (g_pEngine->m_nQuitting == EngineQuitState::QUIT_NOTQUITTING)
{
double frameStart = Plat_FloatTime();
@@ -411,7 +409,6 @@ void InitialiseDedicated(HMODULE engineAddress)
CommandLine()->AppendParm("-windowed", 0);
CommandLine()->AppendParm("+host_preload_shaders", "0");
CommandLine()->AppendParm("+net_usesocketsforloopback", "1");
- //CommandLine()->AppendParm("+exec", "autoexec_ns_server");
// Disable Quick Edit mode to reduce chance of user unintentionally hanging their server by selecting something.
if (!CommandLine()->CheckParm("-bringbackquickedit"))