From: Rudolf Polzer Date: Sun, 19 Feb 2012 18:11:44 +0000 (+0100) Subject: properly report 0 free slots to server browser on restricted servers X-Git-Tag: xonotic-v0.6.0~66^2~5 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=commitdiff_plain;h=00c0fca6ca363959fc18f6348375e05b10bd26b6 properly report 0 free slots to server browser on restricted servers --- diff --git a/qcsrc/server/cl_client.qc b/qcsrc/server/cl_client.qc index ba4249744e..6f7cda2b8c 100644 --- a/qcsrc/server/cl_client.qc +++ b/qcsrc/server/cl_client.qc @@ -2314,7 +2314,7 @@ void ShowRespawnCountdown() .float prevent_join_msgtime; void LeaveSpectatorMode() { - if(nJoinAllowed(1)) { + if(nJoinAllowed(self)) { if(!teamplay || autocvar_g_campaign || autocvar_g_balance_teams || (self.wasplayer && autocvar_g_changeteam_banned) || self.team_forced > 0) { self.classname = "player"; @@ -2364,26 +2364,36 @@ void LeaveSpectatorMode() * it checks whether the number of currently playing players exceeds g_maxplayers. * @return int number of free slots for players, 0 if none */ -float nJoinAllowed(float includeMe) { +float nJoinAllowed(entity ignore) { + if(!ignore) + // this is called that way when checking if anyone may be able to join (to build qcstatus) + // so report 0 free slots if restricted + { + if(autocvar_g_forced_team_otherwise == "spectate") + return 0; + if(autocvar_g_forced_team_otherwise == "spectator") + return 0; + } + if(self.team_forced < 0) - return FALSE; // forced spectators can never join + return 0; // forced spectators can never join // TODO simplify this entity e; - float totalClients; FOR_EACH_CLIENT(e) - totalClients += 1; + if(e != ignore) + totalClients += 1; if (!autocvar_g_maxplayers) - return maxclients - totalClients + includeMe; + return maxclients - totalClients; float currentlyPlaying; FOR_EACH_REALPLAYER(e) currentlyPlaying += 1; if(currentlyPlaying < autocvar_g_maxplayers) - return min(maxclients - totalClients + includeMe, autocvar_g_maxplayers - currentlyPlaying); + return min(maxclients - totalClients, autocvar_g_maxplayers - currentlyPlaying); return 0; } diff --git a/qcsrc/server/command/cmd.qc b/qcsrc/server/command/cmd.qc index b901aca6bc..8a086fcd5a 100644 --- a/qcsrc/server/command/cmd.qc +++ b/qcsrc/server/command/cmd.qc @@ -152,7 +152,7 @@ void ClientCommand_join(float request) { if(self.classname != "player" && !lockteams && !g_arena) { - if(nJoinAllowed(1)) + if(nJoinAllowed(self)) { if(g_ca) { self.caplayer = 1; } if(autocvar_g_campaign) { campaign_bots_may_start = 1; } @@ -732,4 +732,4 @@ void SV_ParseClientCommand(string command) } else clientcommand(self, command); -} \ No newline at end of file +} diff --git a/qcsrc/server/defs.qh b/qcsrc/server/defs.qh index 61e3215e12..e2d4c7ad8c 100644 --- a/qcsrc/server/defs.qh +++ b/qcsrc/server/defs.qh @@ -280,7 +280,7 @@ void checkSpectatorBlock(); .float jointime; // time of joining .float alivetime; // time of being alive -float nJoinAllowed(float includeMe); +float nJoinAllowed(entity ignore); #define PREVENT_JOIN_TEXT "^1You may not join the game at this time.\n\nThe player limit reached maximum capacity." .float spawnshieldtime; diff --git a/qcsrc/server/scores.qc b/qcsrc/server/scores.qc index 3a9a7ada36..a7d325f221 100644 --- a/qcsrc/server/scores.qc +++ b/qcsrc/server/scores.qc @@ -385,7 +385,7 @@ void WinningConditionHelper() s = GetGametype(); s = strcat(s, ":", autocvar_g_xonoticversion); s = strcat(s, ":P", ftos(cvar_purechanges_count)); - s = strcat(s, ":S", ftos(nJoinAllowed(0))); + s = strcat(s, ":S", ftos(nJoinAllowed(world))); s = strcat(s, ":F", ftos(serverflags)); s = strcat(s, ":M", modname); s = strcat(s, "::", GetPlayerScoreString(world, 1)); // make this 1 once we can, note: this doesn't contain any :