From 7716f00d0c63fe71ac8759049d8093919026d9aa Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 25 Jun 2016 09:39:53 +1000 Subject: [PATCH] Implement sv_maxidle_slots --- defaultXonotic.cfg | 2 ++ qcsrc/server/cl_client.qc | 13 ++++++++++++- qcsrc/server/defs.qh | 2 ++ qcsrc/server/miscfunctions.qh | 2 ++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/defaultXonotic.cfg b/defaultXonotic.cfg index dea35012a..0c280744a 100644 --- a/defaultXonotic.cfg +++ b/defaultXonotic.cfg @@ -1005,6 +1005,8 @@ seta menu_cdtrack "rising-of-the-phoenix" set sv_maxidle 0 "kick players idle for more than this amount of time in seconds" set sv_maxidle_spectatorsareidle 0 "when sv_maxidle is not 0, assume spectators are idle too" +set sv_maxidle_slots 0 "when not 0, only kick idlers when this many or less player slots are available" +set sv_maxidle_slots_countbots 1 "count bots as player slots" // these entities are not referenced by anything directly, they just represent // teams and are found by find() when needed diff --git a/qcsrc/server/cl_client.qc b/qcsrc/server/cl_client.qc index 3ba72b815..733b09355 100644 --- a/qcsrc/server/cl_client.qc +++ b/qcsrc/server/cl_client.qc @@ -2420,7 +2420,18 @@ void PlayerPostThink (entity this) if (IS_REAL_CLIENT(this)) if (IS_PLAYER(this) || sv_maxidle_spectatorsareidle) { - if (time - this.parm_idlesince < 1) // instead of (time == this.parm_idlesince) to support sv_maxidle <= 10 + int totalClients = 0; + if(sv_maxidle_slots > 0) + { + FOREACH_CLIENT(IS_REAL_CLIENT(it) || sv_maxidle_slots_countbots, + { + ++totalClients; + }); + } + + if (sv_maxidle_slots > 0 && (maxclients - totalClients) > sv_maxidle_slots) + { /* do nothing */ } + else if (time - this.parm_idlesince < 1) // instead of (time == this.parm_idlesince) to support sv_maxidle <= 10 { if (this.idlekick_lasttimeleft) { diff --git a/qcsrc/server/defs.qh b/qcsrc/server/defs.qh index 8eea0dc20..d4aace83b 100644 --- a/qcsrc/server/defs.qh +++ b/qcsrc/server/defs.qh @@ -253,6 +253,8 @@ float lockteams; .float parm_idlesince; float sv_maxidle; float sv_maxidle_spectatorsareidle; +int sv_maxidle_slots; +bool sv_maxidle_slots_countbots; float tracebox_hits_trigger_hurt(vector start, vector mi, vector ma, vector end); diff --git a/qcsrc/server/miscfunctions.qh b/qcsrc/server/miscfunctions.qh index 7cd8c7012..b6ddd3c6a 100644 --- a/qcsrc/server/miscfunctions.qh +++ b/qcsrc/server/miscfunctions.qh @@ -256,6 +256,8 @@ void readlevelcvars() g_jetpack = cvar("g_jetpack"); sv_maxidle = cvar("sv_maxidle"); sv_maxidle_spectatorsareidle = cvar("sv_maxidle_spectatorsareidle"); + sv_maxidle_slots = cvar("sv_maxidle_slots"); + sv_maxidle_slots_countbots = cvar("sv_maxidle_slots_countbots"); sv_autotaunt = cvar("sv_autotaunt"); sv_taunt = cvar("sv_taunt"); -- 2.39.2