From: Rudolf Polzer Date: Fri, 28 Jan 2011 21:13:05 +0000 (+0100) Subject: add number of free player slots to the statusResponse X-Git-Tag: xonotic-v0.5.0~316^2~10 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=5dc0f852515d98eb386a50c5f630cfcb49a664c9;p=xonotic%2Fxonotic-data.pk3dir.git add number of free player slots to the statusResponse --- diff --git a/qcsrc/server/cl_client.qc b/qcsrc/server/cl_client.qc index 36c234732..11bff62af 100644 --- a/qcsrc/server/cl_client.qc +++ b/qcsrc/server/cl_client.qc @@ -2438,7 +2438,7 @@ void ShowRespawnCountdown() void LeaveSpectatorMode() { - if(isJoinAllowed()) { + if(nJoinAllowed(1)) { if(!teams_matter || autocvar_g_campaign || autocvar_g_balance_teams || (self.wasplayer && autocvar_g_changeteam_banned) || self.team_forced > 0) { self.classname = "player"; @@ -2475,25 +2475,30 @@ void LeaveSpectatorMode() * Determines whether the player is allowed to join. This depends on cvar * g_maxplayers, if it isn't used this function always return TRUE, otherwise * it checks whether the number of currently playing players exceeds g_maxplayers. - * @return bool TRUE if the player is allowed to join, false otherwise + * @return int number of free slots for players, 0 if none */ -float isJoinAllowed() { +float nJoinAllowed(float includeMe) { if(self.team_forced < 0) return FALSE; // forced spectators can never join + // TODO simplify this + local entity e; + + local float totalClients; + FOR_EACH_CLIENT(e) + totalClients += 1; + if (!autocvar_g_maxplayers) - return TRUE; + return maxclients - totalClients + includeMe; - local entity e; local float currentlyPlaying; - FOR_EACH_REALPLAYER(e) { - if(e.classname == "player") - currentlyPlaying += 1; - } + FOR_EACH_REALPLAYER(e) + currentlyPlaying += 1; + if(currentlyPlaying < autocvar_g_maxplayers) - return TRUE; + return min(maxclients - totalClients + includeMe, autocvar_g_maxplayers - currentlyPlaying); - return FALSE; + return 0; } /** diff --git a/qcsrc/server/clientcommands.qc b/qcsrc/server/clientcommands.qc index 9203d87a1..226269d41 100644 --- a/qcsrc/server/clientcommands.qc +++ b/qcsrc/server/clientcommands.qc @@ -218,7 +218,7 @@ void SV_ParseClientCommand(string s) { if(!g_arena) if (self.classname != "player" && !lockteams) { - if(isJoinAllowed()) { + if(nJoinAllowed(1)) { self.classname = "player"; if(g_ca) self.caplayer = 1; diff --git a/qcsrc/server/defs.qh b/qcsrc/server/defs.qh index 970c86af4..4a9d6be25 100644 --- a/qcsrc/server/defs.qh +++ b/qcsrc/server/defs.qh @@ -267,7 +267,7 @@ void checkSpectatorBlock(); .float jointime; // time of joining .float alivetime; // time of being alive -float isJoinAllowed(); +float nJoinAllowed(float includeMe); #define PREVENT_JOIN_TEXT "^1You may not join the game at this time.\n\nThe player limit reached maximum capacity." //sv_timeout: pauses the game by setting the gamespeed to a really low value (see TIMEOUT_SLOWMO_VALUE) diff --git a/qcsrc/server/scores.qc b/qcsrc/server/scores.qc index 79f2ffc7c..b2b0a138f 100644 --- a/qcsrc/server/scores.qc +++ b/qcsrc/server/scores.qc @@ -374,10 +374,18 @@ void WinningConditionHelper() entity winnerscorekeeper; entity secondscorekeeper; entity sk; + float slots; + + // format: + // gametype:P:S::plabel,plabel:tlabel,tlabel:teamid:tscore,tscore:teamid:tscore,tscore + // score labels always start with a symbol or with lower case + // so to match pure, match for :P0: + // to match full, match for :S0: 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, "::", GetPlayerScoreString(world, 1)); // make this 1 once we can, note: this doesn't contain any : fullstatus = autocvar_g_full_getstatus_responses;