]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
add number of free player slots to the statusResponse
authorRudolf Polzer <divverent@alientrap.org>
Fri, 28 Jan 2011 21:13:05 +0000 (22:13 +0100)
committerRudolf Polzer <divverent@alientrap.org>
Fri, 28 Jan 2011 21:21:31 +0000 (22:21 +0100)
qcsrc/server/cl_client.qc
qcsrc/server/clientcommands.qc
qcsrc/server/defs.qh
qcsrc/server/scores.qc

index 36c23473202d47d7f2e094103b0fccda9bfd3e5d..11bff62af1f71256b12f87e0d038f1f6f1815cf0 100644 (file)
@@ -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;
 }
 
 /**
index 9203d87a1ae760f97561fff1dbd9a1fe5b19d60f..226269d41b3605bc87f8e6a9ab417efa0b21621f 100644 (file)
@@ -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;
index 970c86af429ecf3c4ef267ca4ef62b145e1afcad..4a9d6be251e0d2eb1c00fa7d3b27e4a64dd93d0d 100644 (file)
@@ -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)
index 79f2ffc7ce6418fde3634e5ca88fbf51dd368dca..b2b0a138f1d964782c45731c157e7bda15e9a695 100644 (file)
@@ -374,10 +374,18 @@ void WinningConditionHelper()
        entity winnerscorekeeper;
        entity secondscorekeeper;
        entity sk;
+       float slots;
+
+       // format:
+       // gametype:P<pure>:S<slots>::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 :<letter>
 
        fullstatus = autocvar_g_full_getstatus_responses;