]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Initial team queue work
authorz411 <z411@omaera.org>
Thu, 13 Oct 2022 03:00:30 +0000 (00:00 -0300)
committerz411 <z411@omaera.org>
Thu, 13 Oct 2022 03:00:30 +0000 (00:00 -0300)
qcsrc/server/client.qc
qcsrc/server/client.qh

index eb2ba1dcf7234831965879998894cedc3b0d13d6..c7fa83be755f9a69d9ebd1953f601f9bcc056da4 100644 (file)
@@ -410,6 +410,8 @@ void PutObserverInServer(entity this, bool is_forced, bool use_spawnpoint)
 
        if (CS(this).just_joined)
                CS(this).just_joined = false;
+       if (CS(this).wants_join)
+               CS(this).wants_join = false;
 }
 
 int player_getspecies(entity this)
@@ -1109,6 +1111,8 @@ void ClientConnect(entity this)
 
        CS(this).just_joined = true;  // stop spamming the eventlog with additional lines when the client connects
 
+       CS(this).wants_join = false;
+
        stuffcmd(this, clientstuff, "\n");
        stuffcmd(this, "cl_particles_reloadeffects\n"); // TODO do we still need this?
 
@@ -1945,11 +1949,29 @@ void ShowRespawnCountdown(entity this)
        }
 }
 
+entity SpectatorWantsJoin(entity this)
+{
+       if(!teamplay) return NULL;
+
+       FOREACH_CLIENT(IS_SPEC(it) || IS_OBSERVER(it), {
+               if(it == this) continue;
+               if(CS(it).wants_join) {
+                       LOG_INFO("Returning entity");
+                       return it;
+               }
+       });
+
+       LOG_INFO("Returning NULL");
+       return NULL;
+}
+
 .bool team_selected;
 bool ShowTeamSelection(entity this)
 {
        if (!teamplay || autocvar_g_campaign || autocvar_g_balance_teams || this.team_selected || (CS(this).wasplayer && autocvar_g_changeteam_banned) || Player_HasRealForcedTeam(this))
                return false;
+       if (SpectatorWantsJoin(this))
+               return false;
        if (frametime) // once per frame is more than enough
                stuffcmd(this, "_scoreboard_team_selection 1\n");
        return true;
@@ -1961,8 +1983,15 @@ void Join(entity this)
 
        TRANSMUTE(Player, this);
 
+       entity to_join = SpectatorWantsJoin(this);
+       if(to_join)
+       {
+               Join(to_join);
+               this.team_selected = false; // Don't let this player select team
+       }
+
        if(!this.team_selected)
-       if(autocvar_g_campaign || autocvar_g_balance_teams)
+       if(autocvar_g_campaign || autocvar_g_balance_teams || to_join)
                TeamBalance_JoinBestTeam(this);
 
        if(autocvar_g_campaign)
@@ -1979,6 +2008,8 @@ void Join(entity this)
        else
                Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_JOIN_PLAY, this.netname);
        this.team_selected = false;
+
+       CS(this).wants_join = false;
 }
 
 int GetPlayerLimit()
@@ -2049,6 +2080,11 @@ bool joinAllowed(entity this)
        if (teamplay && lockteams) return false;
        if (MUTATOR_CALLHOOK(ForbidSpawn, this)) return false;
        if (ShowTeamSelection(this)) return false;
+       if (teamplay && !SpectatorWantsJoin(this))
+       {
+               CS(this).wants_join = true;
+               return false;
+       }
        return true;
 }
 
index 56cce52a996dd338b551cb08441425f32ce957a0..0569289585a47c6fe0e6d80f9bbe0546bb9efca9 100644 (file)
@@ -72,6 +72,7 @@ float autocvar_sv_player_scale;
 .bool zoomstate;
 
 .bool just_joined;
+.bool wants_join;
 
 .int pressedkeys;
 
@@ -160,6 +161,7 @@ CLASS(Client, Object)
     ATTRIB(Client, teamkill_soundsource, entity, this.teamkill_soundsource);
     ATTRIB(Client, usekeypressed, bool, this.usekeypressed);
     ATTRIB(Client, jointime, float, this.jointime);
+    ATTRIB(Client, wants_join, bool, this.wants_join);
     ATTRIB(Client, spectatortime, float, this.spectatortime);
     ATTRIB(Client, startplaytime, float, this.startplaytime);
     ATTRIB(Client, version_nagtime, float, this.version_nagtime);