From: bones_was_here Date: Tue, 14 Mar 2023 11:48:38 +0000 (+1000) Subject: Implement autopause for empty dedicated servers X-Git-Tag: xonotic-v0.8.6~115^2~1 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=8f86210c7c6e19979696907d6fa3b2916cd9043e;p=xonotic%2Fxonotic-data.pk3dir.git Implement autopause for empty dedicated servers --- diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index 5b7509e48..f78d772c5 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -1188,7 +1188,11 @@ void ClientConnect(entity this) MUTATOR_CALLHOOK(ClientConnect, this); if (player_count == 1) + { + if (autocvar_sv_autopause && server_is_dedicated) + setpause(0); localcmd("\nsv_hook_firstjoin\n"); + } } /* ============= diff --git a/qcsrc/server/main.qc b/qcsrc/server/main.qc index 2b29422b8..bb75f5aa2 100644 --- a/qcsrc/server/main.qc +++ b/qcsrc/server/main.qc @@ -186,6 +186,12 @@ void CreatureFrame_All() }); } +void Pause_TryPause_Dedicated(entity this) +{ + if (player_count == 0) + setpause(1); +} + void Pause_TryPause(bool ispaused) { int n = 0; @@ -268,7 +274,6 @@ Called before each frame by the server bool game_delay_last; -bool autocvar_sv_autopause = false; void systems_update(); void sys_phys_update(entity this, float dt); void StartFrame() diff --git a/qcsrc/server/main.qh b/qcsrc/server/main.qh index ed095ba48..30b686471 100644 --- a/qcsrc/server/main.qh +++ b/qcsrc/server/main.qh @@ -16,6 +16,9 @@ bool autocvar_g_balance_falldamage_onlyvertical; #define autocvar_slowmo cvar("slowmo") float autocvar_sys_ticrate; +bool autocvar_sv_autopause; +void Pause_TryPause_Dedicated(entity this); + bool dropclient_schedule(entity this); /** print(), but only print if the server is not local */ diff --git a/qcsrc/server/world.qc b/qcsrc/server/world.qc index c04b188fa..defb079c7 100644 --- a/qcsrc/server/world.qc +++ b/qcsrc/server/world.qc @@ -387,6 +387,7 @@ void cvar_changes_init() BADCVAR("leadlimit_override"); BADCVAR("pausable"); BADCVAR("sv_announcer"); + BADCVAR("sv_autopause"); BADCVAR("sv_checkforpacketsduringsleep"); BADCVAR("sv_damagetext"); BADCVAR("sv_db_saveasdump"); @@ -1043,6 +1044,10 @@ spawnfunc(worldspawn) WinningConditionHelper(this); // set worldstatus + if (autocvar_sv_autopause && server_is_dedicated && !wantrestart) + // INITPRIO_LAST is to soon: bots either didn't join yet or didn't leave yet, see: bot_fixcount() + defer(this, 5, Pause_TryPause_Dedicated); + world_initialized = 1; __spawnfunc_spawn_all(); } diff --git a/xonotic-server.cfg b/xonotic-server.cfg index 82cccae0f..511887ec1 100644 --- a/xonotic-server.cfg +++ b/xonotic-server.cfg @@ -51,6 +51,8 @@ set sv_timeout_number 2 "how many timeouts one player is allowed to call (gets r set sv_timeout_leadtime 4 "how long the players will be informed that a timeout was called before it starts, in seconds" set sv_timeout_resumetime 3 "how long the remaining timeout-time will be after a player called the timein command" +set sv_autopause 0 "Single player: pause while the menu or console is open. Dedicated server: pause after starting a map if the server is empty and unpause when the first player joins the empty server." + set g_telefrags 1 "telefragging, i.e. killing someone who stands in the way of someone who is teleporting" set g_telefrags_teamplay 1 "never telefrag team mates" set g_telefrags_avoid 1 "when teleporters have a random destination, avoid teleporting to locations where a telefrag would happen"