From 0e8f095f9f4e99dd68231a8f24df3f3f36cf6a13 Mon Sep 17 00:00:00 2001 From: z411 Date: Thu, 13 Oct 2022 00:00:30 -0300 Subject: [PATCH] Initial team queue work --- qcsrc/server/client.qc | 38 +++++++++++++++++++++++++++++++++++++- qcsrc/server/client.qh | 2 ++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index eb2ba1dcf..c7fa83be7 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -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; } diff --git a/qcsrc/server/client.qh b/qcsrc/server/client.qh index 56cce52a9..056928958 100644 --- a/qcsrc/server/client.qh +++ b/qcsrc/server/client.qh @@ -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); -- 2.39.2