fix CPU replacement on player disconnect

This commit is contained in:
Martin Michelsen
2023-09-09 12:47:54 -07:00
parent f12fdaf165
commit 0863c4f27c
4 changed files with 18 additions and 5 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ NameEntry::NameEntry() {
void NameEntry::clear() {
this->client_id = 0xFF;
this->present = 0;
this->unused_by_server = 0;
this->is_cpu_player = 0;
this->unused = 0;
}
+1 -1
View File
@@ -14,7 +14,7 @@ struct NameEntry {
parray<char, 0x10> name;
uint8_t client_id;
uint8_t present;
uint8_t unused_by_server;
uint8_t is_cpu_player;
uint8_t unused;
NameEntry();
+13
View File
@@ -1928,6 +1928,19 @@ void Server::handle_CAx1B_update_player_name(const string& data) {
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();
}
}
G_SetPlayerNames_GC_Ep3_6xB4x1C out_cmd;
for (size_t z = 0; z < 4; z++) {
out_cmd.entries[z] = this->name_entries[z];