send tournament result before battle end command

This commit is contained in:
Martin Michelsen
2023-05-23 21:53:45 -07:00
parent 7ae87f9949
commit 03c26b587a
4 changed files with 14 additions and 2 deletions
+1
View File
@@ -61,6 +61,7 @@ void ServerBase::recreate_server() {
Server::Server(shared_ptr<ServerBase> base) Server::Server(shared_ptr<ServerBase> base)
: w_base(base), : w_base(base),
tournament_match_result_sent(false),
battle_finished(false), battle_finished(false),
battle_in_progress(false), battle_in_progress(false),
round_num(1), round_num(1),
+2
View File
@@ -242,6 +242,8 @@ private:
std::weak_ptr<ServerBase> w_base; std::weak_ptr<ServerBase> w_base;
public: public:
bool tournament_match_result_sent; // Not part of original implementation
uint32_t battle_finished; uint32_t battle_finished;
uint32_t battle_in_progress; uint32_t battle_in_progress;
uint32_t round_num; uint32_t round_num;
+5 -2
View File
@@ -1325,10 +1325,12 @@ static void on_CA_Ep3(shared_ptr<ServerState> s, shared_ptr<Client> c,
} }
} }
l->ep3_server_base->server->on_server_data_input(data); 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(); int8_t winner_team_id = l->ep3_server_base->server->get_winner_team_id();
if (winner_team_id == -1) { 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(); auto tourn = l->tournament_match->tournament.lock();
@@ -1344,6 +1346,7 @@ static void on_CA_Ep3(shared_ptr<ServerState> s, shared_ptr<Client> c,
send_ep3_tournament_match_result(l, l->tournament_match); send_ep3_tournament_match_result(l, l->tournament_match);
on_tournament_bracket_updated(s, tourn); on_tournament_bracket_updated(s, tourn);
l->ep3_server_base->server->tournament_match_result_sent = true;
} }
} }
+6
View File
@@ -2299,6 +2299,12 @@ void send_ep3_tournament_match_result(
set_mask_for_ep3_game_command(&cmd, sizeof(cmd), mask_key); set_mask_for_ep3_game_command(&cmd, sizeof(cmd), mask_key);
} }
send_command_t(l, 0xC9, 0x00, cmd); 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<Lobby> l) { void send_ep3_update_spectator_count(shared_ptr<Lobby> l) {