From 68dd7951896cdad48c83fa9930bfe7b00b0c074f Mon Sep 17 00:00:00 2001 From: terencehill Date: Tue, 2 Jun 2020 17:21:44 +0200 Subject: [PATCH] Automatically join players 1 second after they connect if they tried to join too early --- qcsrc/server/client.qc | 20 +++++++++++++------- qcsrc/server/client.qh | 2 +- qcsrc/server/command/cmd.qc | 11 +++++++---- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index ce495c3470..8c744b17dd 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -2279,7 +2279,7 @@ void ObserverThink(entity this) } if (this.flags & FL_JUMPRELEASED) { - if (PHYS_INPUT_BUTTON_JUMP(this) && joinAllowed(this)) { + if (PHYS_INPUT_BUTTON_JUMP(this) && (joinAllowed(this) || time < CS(this).jointime + MIN_SPEC_TIME)) { this.flags &= ~FL_JUMPRELEASED; this.flags |= FL_SPAWNING; } else if(PHYS_INPUT_BUTTON_ATCK(this) && !CS(this).version_mismatch || this.would_spectate) { @@ -2299,6 +2299,8 @@ void ObserverThink(entity this) this.flags &= ~FL_SPAWNING; if(joinAllowed(this)) Join(this); + else if(time < CS(this).jointime + MIN_SPEC_TIME) + CS(this).autojoin_checked = -1; return; } } @@ -2321,7 +2323,7 @@ void SpectatorThink(entity this) } if (this.flags & FL_JUMPRELEASED) { - if (PHYS_INPUT_BUTTON_JUMP(this) && joinAllowed(this)) { + if (PHYS_INPUT_BUTTON_JUMP(this) && (joinAllowed(this) || time < CS(this).jointime + MIN_SPEC_TIME)) { this.flags &= ~FL_JUMPRELEASED; this.flags |= FL_SPAWNING; } else if(PHYS_INPUT_BUTTON_ATCK(this) || CS(this).impulse == 10 || CS(this).impulse == 15 || CS(this).impulse == 18 || (CS(this).impulse >= 200 && CS(this).impulse <= 209)) { @@ -2365,6 +2367,8 @@ void SpectatorThink(entity this) this.flags &= ~FL_SPAWNING; if(joinAllowed(this)) Join(this); + else if(time < CS(this).jointime + MIN_SPEC_TIME) + CS(this).autojoin_checked = -1; return; } } @@ -2569,17 +2573,19 @@ void PlayerPreThink (entity this) IntermissionThink(this); return; } - else if (IS_REAL_CLIENT(this) && !CS(this).autojoin_checked && time >= CS(this).jointime + MIN_SPEC_TIME) + else if (IS_REAL_CLIENT(this) && CS(this).autojoin_checked <= 0 && time >= CS(this).jointime + MIN_SPEC_TIME) { - CS(this).autojoin_checked = true; + bool early_join_requested = (CS(this).autojoin_checked < 0); + CS(this).autojoin_checked = 1; // don't do this in ClientConnect // many things can go wrong if a client is spawned as player on connection - if (MUTATOR_CALLHOOK(AutoJoinOnConnection, this) + if (early_join_requested || MUTATOR_CALLHOOK(AutoJoinOnConnection, this) || (!(autocvar_sv_spectate || autocvar_g_campaign || (Player_GetForcedTeamIndex(this) == TEAM_FORCE_SPECTATOR)) && (!teamplay || autocvar_g_balance_teams))) { campaign_bots_may_start = true; - Join(this); + if(joinAllowed(this)) + Join(this); return; } } @@ -2601,7 +2607,7 @@ void PlayerPreThink (entity this) wep_zoomed += thiswep.wr_zoom(thiswep, this); } SetZoomState(this, PHYS_INPUT_BUTTON_ZOOM(this) || PHYS_INPUT_BUTTON_ZOOMSCRIPT(this) || wep_zoomed); - } + } if (CS(this).teamkill_soundtime && time > CS(this).teamkill_soundtime) { diff --git a/qcsrc/server/client.qh b/qcsrc/server/client.qh index 20148933cb..2c1ddab13d 100644 --- a/qcsrc/server/client.qh +++ b/qcsrc/server/client.qh @@ -114,7 +114,7 @@ CLASS(Client, Object) ATTRIB(Client, cmd_floodtime, float, this.cmd_floodtime); ATTRIB(Client, wasplayer, bool, this.wasplayer); ATTRIB(Client, weaponorder_byimpulse, string, this.weaponorder_byimpulse); - ATTRIB(Client, autojoin_checked, bool, this.wasplayer); + ATTRIB(Client, autojoin_checked, int, this.wasplayer); // networked cvars diff --git a/qcsrc/server/command/cmd.qc b/qcsrc/server/command/cmd.qc index ad9cab8e72..c734735344 100644 --- a/qcsrc/server/command/cmd.qc +++ b/qcsrc/server/command/cmd.qc @@ -285,10 +285,13 @@ void ClientCommand_join(entity caller, int request) { case CMD_REQUEST_COMMAND: { - if (!game_stopped) - if (IS_CLIENT(caller) && !IS_PLAYER(caller)) - if (joinAllowed(caller)) - Join(caller); + if (!game_stopped && IS_CLIENT(caller) && !IS_PLAYER(caller)) + { + if (joinAllowed(caller)) + Join(caller); + else if(time < CS(caller).jointime + MIN_SPEC_TIME) + CS(caller).autojoin_checked = -1; + } return; // never fall through to usage } -- 2.39.2