]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Make bots observers (for one frame) before joining the game and put them in a team...
authorterencehill <piuntn@gmail.com>
Thu, 12 May 2022 00:48:56 +0000 (02:48 +0200)
committerterencehill <piuntn@gmail.com>
Thu, 12 May 2022 00:48:56 +0000 (02:48 +0200)
It fixes a bug where bots connecting in the middle of a CA round join a team (with a message announcing it) and immediately leave it because joining a team is not allowed.

qcsrc/server/bot/default/bot.qc
qcsrc/server/client.qc

index d9585768d9fc2f7a606582d4566f67e642d119ce..792bde7cd969c395c6b835f5733fa512f3862d1a 100644 (file)
@@ -448,16 +448,6 @@ void bot_clientconnect(entity this)
                bot_setclientfields(this);
        }
 
-       if (teamplay && Team_IsValidIndex(this.bot_forced_team))
-       {
-               SetPlayerTeam(this, this.bot_forced_team, TEAM_CHANGE_MANUAL);
-       }
-       else
-       {
-               this.bot_forced_team = 0;
-               TeamBalance_JoinBestTeam(this);
-       }
-
        havocbot_setupbot(this);
 }
 
index cab642e67fd9b0f8e65a3eafedb54800e8cc3927..7bd24369e3154c200dc526599a091b1c227f1cbf 100644 (file)
@@ -540,6 +540,14 @@ void PutPlayerInServer(entity this)
        PlayerState_attach(this);
        accuracy_resend(this);
 
+       if (IS_BOT_CLIENT(this))
+       {
+               if (teamplay && Team_IsValidIndex(this.bot_forced_team))
+                       SetPlayerTeam(this, this.bot_forced_team, TEAM_CHANGE_MANUAL);
+               else
+                       this.bot_forced_team = 0;
+       }
+
        if (this.team < 0)
                TeamBalance_JoinBestTeam(this);
 
@@ -810,9 +818,7 @@ void PutPlayerInServer(entity this)
 /** Called when a client spawns in the server */
 void PutClientInServer(entity this)
 {
-       if (IS_BOT_CLIENT(this)) {
-               TRANSMUTE(Player, this);
-       } else if (IS_REAL_CLIENT(this)) {
+       if (IS_REAL_CLIENT(this)) {
                msg_entity = this;
                WriteByte(MSG_ONE, SVC_SETVIEW);
                WriteEntity(MSG_ONE, this);
@@ -2269,6 +2275,14 @@ void ObserverOrSpectatorThink(entity this)
                }
        }
 
+       if (IS_BOT_CLIENT(this) && !CS(this).autojoin_checked)
+       {
+               CS(this).autojoin_checked = true;
+               TRANSMUTE(Player, this);
+               PutClientInServer(this);
+               return;
+       }
+
        if (this.flags & FL_JUMPRELEASED) {
                if (PHYS_INPUT_BUTTON_JUMP(this) && (joinAllowed(this) || time < CS(this).jointime + MIN_SPEC_TIME)) {
                        this.flags &= ~FL_JUMPRELEASED;