From 85897baaeb4182d43c840f02d1045905e0df11af Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Sat, 23 Sep 2023 09:11:22 -0700 Subject: [PATCH] ignore client rules in tournament matches --- src/Episode3/Server.cc | 14 ++++++++++---- src/Episode3/Server.hh | 5 +++-- src/ReceiveCommands.cc | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Episode3/Server.cc b/src/Episode3/Server.cc index 2c8bc1c5..0a0e4ccf 100644 --- a/src/Episode3/Server.cc +++ b/src/Episode3/Server.cc @@ -29,14 +29,14 @@ Server::Server(shared_ptr lobby, shared_ptr map_index, uint32_t behavior_flags, shared_ptr random_crypt, - shared_ptr map_if_tournament) + shared_ptr tournament) : lobby(lobby), card_index(card_index), map_index(map_index), behavior_flags(behavior_flags), random_crypt(random_crypt), - last_chosen_map(map_if_tournament), - is_tournament(!!map_if_tournament), + last_chosen_map(tournament ? tournament->get_map() : nullptr), + tournament(tournament), tournament_match_result_sent(false), override_environment_number(0xFF), battle_finished(false), @@ -1532,7 +1532,7 @@ G_SetStateFlags_GC_Ep3_6xB4x03 Server::prepare_6xB4x03() const { cmd.state.team_dice_boost[0] = this->team_dice_boost[0]; cmd.state.team_dice_boost[1] = this->team_dice_boost[1]; cmd.state.first_team_turn = this->first_team_turn; - cmd.state.tournament_flag = this->is_tournament ? 1 : 0; + cmd.state.tournament_flag = this->tournament ? 1 : 0; for (size_t z = 0; z < 4; z++) { auto ps = this->player_states[z]; if (!ps) { @@ -1939,6 +1939,12 @@ void Server::handle_CAx13_update_map_during_setup(const string& data) { *this->map_and_rules = in_cmd.map_and_rules_state; this->map_and_rules->rules.def_dice_range = def_dice_range; + // If this match is part of a tournament, ignore the rules sent by the + // client and use the tournament rules instead. + if (this->tournament) { + this->map_and_rules->rules = this->tournament->get_rules(); + } + if (this->override_environment_number != 0xFF) { this->map_and_rules->environment_number = this->override_environment_number; this->override_environment_number = 0xFF; diff --git a/src/Episode3/Server.hh b/src/Episode3/Server.hh index 80ba6981..f538e4cd 100644 --- a/src/Episode3/Server.hh +++ b/src/Episode3/Server.hh @@ -12,6 +12,7 @@ #include "MapState.hh" #include "PlayerState.hh" #include "RulerServer.hh" +#include "Tournament.hh" struct Lobby; @@ -63,7 +64,7 @@ public: std::shared_ptr map_index, uint32_t behavior_flags, std::shared_ptr random_crypt, - std::shared_ptr map_if_tournament); + std::shared_ptr tournament); ~Server() noexcept(false); void init(); @@ -233,7 +234,7 @@ public: uint32_t behavior_flags; std::shared_ptr random_crypt; std::shared_ptr last_chosen_map; - bool is_tournament; + std::shared_ptr tournament; bool tournament_match_result_sent; uint8_t override_environment_number; mutable std::deque logger_stack; diff --git a/src/ReceiveCommands.cc b/src/ReceiveCommands.cc index e7297e87..91f3de22 100644 --- a/src/ReceiveCommands.cc +++ b/src/ReceiveCommands.cc @@ -1275,7 +1275,7 @@ static void on_CA_Ep3(shared_ptr c, uint16_t, uint32_t, const string& da s->ep3_map_index, s->ep3_behavior_flags, l->random_crypt, - tourn ? tourn->get_map() : nullptr); + tourn); l->ep3_server->init(); if (s->ep3_behavior_flags & Episode3::BehaviorFlag::ENABLE_STATUS_MESSAGES) {