Automatically join players 1 second after they connect if they tried to join too...
authorterencehill <piuntn@gmail.com>
Tue, 2 Jun 2020 15:21:44 +0000 (17:21 +0200)
committerterencehill <piuntn@gmail.com>
Tue, 2 Jun 2020 15:22:34 +0000 (17:22 +0200)
qcsrc/server/client.qc
qcsrc/server/client.qh
qcsrc/server/command/cmd.qc

index ce495c3..8c744b1 100644 (file)
@@ -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)
        {
index 2014893..2c1ddab 100644 (file)
@@ -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
 
index ad9cab8..c734735 100644 (file)
@@ -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
                }