From 03c26b587ae5f5fc21c0c7d71944e4f75dd2befc Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Tue, 23 May 2023 21:53:45 -0700 Subject: [PATCH] send tournament result before battle end command --- src/Episode3/Server.cc | 1 + src/Episode3/Server.hh | 2 ++ src/ReceiveCommands.cc | 7 +++++-- src/SendCommands.cc | 6 ++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Episode3/Server.cc b/src/Episode3/Server.cc index 659c8379..ff91fe31 100644 --- a/src/Episode3/Server.cc +++ b/src/Episode3/Server.cc @@ -61,6 +61,7 @@ void ServerBase::recreate_server() { Server::Server(shared_ptr base) : w_base(base), + tournament_match_result_sent(false), battle_finished(false), battle_in_progress(false), round_num(1), diff --git a/src/Episode3/Server.hh b/src/Episode3/Server.hh index 7e24ff46..2af9acbb 100644 --- a/src/Episode3/Server.hh +++ b/src/Episode3/Server.hh @@ -242,6 +242,8 @@ private: std::weak_ptr w_base; public: + bool tournament_match_result_sent; // Not part of original implementation + uint32_t battle_finished; uint32_t battle_in_progress; uint32_t round_num; diff --git a/src/ReceiveCommands.cc b/src/ReceiveCommands.cc index 0fc4bab3..c99cf208 100644 --- a/src/ReceiveCommands.cc +++ b/src/ReceiveCommands.cc @@ -1325,10 +1325,12 @@ static void on_CA_Ep3(shared_ptr s, shared_ptr c, } } l->ep3_server_base->server->on_server_data_input(data); - if (l->ep3_server_base->server->battle_finished && l->tournament_match) { + if (l->tournament_match && + l->ep3_server_base->server->setup_phase == Episode3::SetupPhase::BATTLE_ENDED && + !l->ep3_server_base->server->tournament_match_result_sent) { int8_t winner_team_id = l->ep3_server_base->server->get_winner_team_id(); if (winner_team_id == -1) { - throw runtime_error("match concluded, but winner team not specified"); + throw runtime_error("match complete, but winner team not specified"); } auto tourn = l->tournament_match->tournament.lock(); @@ -1344,6 +1346,7 @@ static void on_CA_Ep3(shared_ptr s, shared_ptr c, send_ep3_tournament_match_result(l, l->tournament_match); on_tournament_bracket_updated(s, tourn); + l->ep3_server_base->server->tournament_match_result_sent = true; } } diff --git a/src/SendCommands.cc b/src/SendCommands.cc index 7fb0afe1..9eb483c0 100644 --- a/src/SendCommands.cc +++ b/src/SendCommands.cc @@ -2299,6 +2299,12 @@ void send_ep3_tournament_match_result( set_mask_for_ep3_game_command(&cmd, sizeof(cmd), mask_key); } send_command_t(l, 0xC9, 0x00, cmd); + + if (tourn->get_data_index()->behavior_flags & Episode3::BehaviorFlag::ENABLE_STATUS_MESSAGES) { + send_text_message_printf(l, "$C5TOURN/%02hhX/%zu WIN %c", + tourn->get_number(), match->round_num, + match->winner_team == match->preceding_a->winner_team ? 'A' : 'B'); + } } void send_ep3_update_spectator_count(shared_ptr l) {