From: terencehill Date: Thu, 12 May 2022 00:48:56 +0000 (+0200) Subject: Make bots observers (for one frame) before joining the game and put them in a team... X-Git-Tag: xonotic-v0.8.5~40 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=12e3e2cb5f9d8cdd821a97894223fde2f5e2f816;p=xonotic%2Fxonotic-data.pk3dir.git Make bots observers (for one frame) before joining the game and put them in a team in PutPlayerInServer so that everything gets initialized in the same way as for human players. 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. --- diff --git a/qcsrc/server/bot/default/bot.qc b/qcsrc/server/bot/default/bot.qc index d9585768d..792bde7cd 100644 --- a/qcsrc/server/bot/default/bot.qc +++ b/qcsrc/server/bot/default/bot.qc @@ -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); } diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index cab642e67..7bd24369e 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -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;