From 103e5325a379581e7f2990f42f5c058f0dcb78ef Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Wed, 27 Sep 2023 10:51:18 -0700 Subject: [PATCH] fix CAx1B client ID check --- src/CommandFormats.hh | 19 ++++++++++--------- src/Episode3/Server.cc | 30 ++++++++++++++++-------------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/CommandFormats.hh b/src/CommandFormats.hh index ba5b9327..a456a2f8 100644 --- a/src/CommandFormats.hh +++ b/src/CommandFormats.hh @@ -5146,15 +5146,16 @@ struct G_CardBattleCommandHeader { // The 6xB3 subcommand has a longer header than 6xB4 and 6xB5. This header is // common to all 6xB3x (CAx) subcommands. struct G_CardServerDataCommandHeader { - uint8_t subcommand = 0xB3; - uint8_t size = 0x00; - le_uint16_t unused1 = 0x0000; - uint8_t subsubcommand = 0x00; // See 6xBx subcommand table (after this table) - uint8_t sender_client_id = 0x00; - uint8_t mask_key = 0x00; // Same meaning as in G_CardBattleCommandHeader - uint8_t unused2 = 0x00; - be_uint32_t sequence_num; - be_uint32_t context_token; + /* 00 */ uint8_t subcommand = 0xB3; + /* 01 */ uint8_t size = 0x00; + /* 02 */ le_uint16_t unused1 = 0x0000; + /* 04 */ uint8_t subsubcommand = 0x00; // See 6xBx subcommand table (after this table) + /* 05 */ uint8_t sender_client_id = 0x00; + /* 06 */ uint8_t mask_key = 0x00; // Same meaning as in G_CardBattleCommandHeader + /* 07 */ uint8_t unused2 = 0x00; + /* 08 */ be_uint32_t sequence_num; + /* 0C */ be_uint32_t context_token; + /* 10 */ } __packed__; // 6xB4: Unknown (XBOX; voice chat) diff --git a/src/Episode3/Server.cc b/src/Episode3/Server.cc index 46a35585..167e44dc 100644 --- a/src/Episode3/Server.cc +++ b/src/Episode3/Server.cc @@ -2034,21 +2034,23 @@ void Server::handle_CAx1B_update_player_name(const string& data) { this->send_debug_command_received_message( in_cmd.entry.client_id, in_cmd.header.subsubcommand, "UPDATE NAME"); - if (!this->is_registration_complete() && (in_cmd.entry.client_id < 4)) { - this->name_entries[in_cmd.entry.client_id] = in_cmd.entry; - this->name_entries_valid[in_cmd.entry.client_id] = false; - } + if (in_cmd.entry.client_id < 4) { + if (!this->is_registration_complete()) { + this->name_entries[in_cmd.entry.client_id] = in_cmd.entry; + this->name_entries_valid[in_cmd.entry.client_id] = false; + } - // Note: This check is not part of the original code. This replaces a - // disconnecting player with a CPU if the battle is in progress. - auto l = this->lobby.lock(); - if (l && !l->clients[in_cmd.entry.client_id]) { - this->name_entries[in_cmd.entry.client_id].is_cpu_player = 1; - this->presence_entries[in_cmd.entry.client_id].is_cpu_player = 1; - auto ps = this->player_states[in_cmd.entry.client_id]; - if (ps && ps->hand_and_equip && !ps->hand_and_equip->is_cpu_player) { - ps->hand_and_equip->is_cpu_player = 1; - this->send_6xB4x02_for_all_players_if_needed(); + // Note: This check is not part of the original code. This replaces a + // disconnecting player with a CPU if the battle is in progress. + auto l = this->lobby.lock(); + if (l && !l->clients[in_cmd.entry.client_id]) { + this->name_entries[in_cmd.entry.client_id].is_cpu_player = 1; + this->presence_entries[in_cmd.entry.client_id].is_cpu_player = 1; + auto ps = this->player_states[in_cmd.entry.client_id]; + if (ps && ps->hand_and_equip && !ps->hand_and_equip->is_cpu_player) { + ps->hand_and_equip->is_cpu_player = 1; + this->send_6xB4x02_for_all_players_if_needed(); + } } }