]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge branch 'bones_was_here/autopause_dedicated' into 'master'
authorbones_was_here <bones_was_here@xonotic.au>
Tue, 9 May 2023 09:09:10 +0000 (09:09 +0000)
committerbones_was_here <bones_was_here@xonotic.au>
Tue, 9 May 2023 09:09:10 +0000 (09:09 +0000)
Autopause for dedicated servers, better autopause for singleplayer/listen

Closes #2670

See merge request xonotic/xonotic-data.pk3dir!1144

qcsrc/server/client.qc
qcsrc/server/main.qc
qcsrc/server/main.qh
qcsrc/server/world.qc
xonotic-client.cfg
xonotic-server.cfg

index 5b7509e484d5fecec7e6f49a852de6ea218e39e9..f78d772c5d0f363a377e86c7650b7f071faaf0eb 100644 (file)
@@ -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");
+       }
 }
 /*
 =============
index 2b29422b8969362356b6a552106158c9b881d0e7..8a2da54aa4a721c2312017b0bd30ae52bd72e561 100644 (file)
@@ -186,20 +186,35 @@ void CreatureFrame_All()
        });
 }
 
-void Pause_TryPause(bool ispaused)
+void Pause_TryPause_Dedicated(entity this)
 {
-       int n = 0;
-       FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
-               if (PHYS_INPUT_BUTTON_CHAT(it) != ispaused) return;
+       if (player_count == 0)
+               setpause(1);
+}
+
+void Pause_TryPause()
+{
+       int n = 0, p = 0;
+       FOREACH_CLIENT(IS_REAL_CLIENT(it), {
+               if (PHYS_INPUT_BUTTON_CHAT(it)) ++p;
                ++n;
        });
        if (!n) return;
-       setpause(ispaused);
+       if (n == p)
+               setpause(1);
+       else
+               setpause(0);
 }
 
 void SV_PausedTic(float elapsedtime)
 {
-       if (!server_is_dedicated) Pause_TryPause(false);
+       if (!server_is_dedicated)
+       {
+               if (autocvar_sv_autopause)
+                       Pause_TryPause();
+               else
+                       setpause(0);
+       }
 }
 
 void dedicated_print(string input)
@@ -268,7 +283,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()
@@ -278,7 +292,7 @@ void StartFrame()
     IL_EACH(g_players, IS_FAKE_CLIENT(it), PlayerPreThink(it));
 
        execute_next_frame();
-       if (autocvar_sv_autopause && !server_is_dedicated) Pause_TryPause(true);
+       if (autocvar_sv_autopause && !server_is_dedicated) Pause_TryPause();
 
        delete_fn = remove_unsafely; // not during spawning!
        serverprevtime = servertime;
index ed095ba485ec56a78b603a59b9919d2e12875adf..30b6864716063cdd5f62c31159ac2e3c71b5c575 100644 (file)
@@ -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 */
index 43758c5f474b72331ccc6cbbdefe73b32b53ab6d..ab5786d6cfec27b1a27e3f24ef488ff3e8977a8b 100644 (file)
@@ -388,6 +388,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");
@@ -1048,6 +1049,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();
 }
index 46149e2d108a9985d25539c76e3fbc858ca0cec8..add42efd325acc0eca59a8606dbbc9b027c42305 100644 (file)
@@ -348,6 +348,8 @@ seta cl_announcer default "name of the announcer you wish to use from data/sound
 seta cl_announcer_antispam 2 "number of seconds before an announcement of the same sound can be played again"
 seta cl_announcer_maptime 3 "play announcer sound telling you the remaining maptime - 0: do not play at all, 1: play at one minute, 2: play at five minutes, 3: play both"
 
+set snd_cdautopause 0
+
 // aliases:
 alias +fire +attack
 alias -fire -attack
index 94532425fecf63013af480dd795a2ada350a446f..03404ebf4555482d04ad7fe4047a7a248f02eb41 100644 (file)
@@ -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 1 "Single player or listen server: pause while all clients have the menu, console or chat 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"