From 548aca8cc0a4cdd4ae965dc764fcbd660831c78e Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Wed, 6 Sep 2023 16:39:32 -0700 Subject: [PATCH] fix Ep3 card auction --- src/Client.hh | 2 -- src/CommandFormats.hh | 6 +++--- src/ReceiveCommands.cc | 14 +++----------- src/SendCommands.cc | 31 ++----------------------------- src/SendCommands.hh | 5 ++--- 5 files changed, 10 insertions(+), 48 deletions(-) diff --git a/src/Client.hh b/src/Client.hh index e7965dab..bfa043b3 100644 --- a/src/Client.hh +++ b/src/Client.hh @@ -96,8 +96,6 @@ struct Client { LOADING_QUEST = 0x00000040, // Client is loading a joinable quest that has already started LOADING_RUNNING_QUEST = 0x00100000, - // Client is waiting to join an Episode 3 card auction - AWAITING_CARD_AUCTION = 0x00010000, // Client is in the information menu (login server only) IN_INFORMATION_MENU = 0x00000080, // Client is at the welcome message (login server only) diff --git a/src/CommandFormats.hh b/src/CommandFormats.hh index 7bec7927..eb50a011 100644 --- a/src/CommandFormats.hh +++ b/src/CommandFormats.hh @@ -3495,9 +3495,9 @@ struct S_CardTradeComplete_GC_Ep3_EE_FlagD4 { // scrolls to the left. // EF (C->S): Join card auction (Episode 3) -// This command should be treated like AC (quest barrier); that is, when all -// players in the same game have sent an EF command, the server should send an -// EF back to them all at the same time to start the auction. +// When a card auction is ready to begin, the leader sends this command to +// request the card list. The server then sends an EF command to all players +// to start the auction. // EF (S->C): Start card auction (Episode 3) diff --git a/src/ReceiveCommands.cc b/src/ReceiveCommands.cc index 84f3093f..33b14946 100644 --- a/src/ReceiveCommands.cc +++ b/src/ReceiveCommands.cc @@ -28,7 +28,6 @@ using namespace std; const char* BATTLE_TABLE_DISCONNECT_HOOK_NAME = "battle_table_state"; const char* QUEST_BARRIER_DISCONNECT_HOOK_NAME = "quest_barrier"; -const char* CARD_AUCTION_DISCONNECT_HOOK_NAME = "card_auction"; const char* ADD_NEXT_CLIENT_DISCONNECT_HOOK_NAME = "add_next_game_client"; static shared_ptr proxy_options_menu_for_client( @@ -3743,21 +3742,14 @@ static void on_EF_Ep3(shared_ptr s, shared_ptr c, check_size_v(data.size(), 0); if (!(c->flags & Client::Flag::IS_EPISODE_3)) { - throw runtime_error("non-Ep3 client sent card auction join command"); + throw runtime_error("non-Ep3 client sent card auction request"); } auto l = s->find_lobby(c->lobby_id); if (!l->is_game() || !l->is_ep3()) { - throw runtime_error("client sent card auction join command outside of Ep3 game"); + throw runtime_error("client sent card auction request outside of Ep3 game"); } - if (c->flags & Client::Flag::AWAITING_CARD_AUCTION) { - return; - } - c->flags |= Client::Flag::AWAITING_CARD_AUCTION; - c->disconnect_hooks.emplace(CARD_AUCTION_DISCONNECT_HOOK_NAME, [s, l]() -> void { - send_card_auction_if_all_clients_ready(s, l); - }); - send_card_auction_if_all_clients_ready(s, l); + send_ep3_card_auction(s, l); } static void on_xxEA_BB(shared_ptr, shared_ptr c, diff --git a/src/SendCommands.cc b/src/SendCommands.cc index e51cbfb1..aa24d8c8 100644 --- a/src/SendCommands.cc +++ b/src/SendCommands.cc @@ -21,7 +21,6 @@ using namespace std; extern const char* QUEST_BARRIER_DISCONNECT_HOOK_NAME; -extern const char* CARD_AUCTION_DISCONNECT_HOOK_NAME; const unordered_set v2_crypt_initial_client_commands({ 0x00260088, // (17) DCNTE license check @@ -2769,28 +2768,7 @@ bool send_quest_barrier_if_all_clients_ready(shared_ptr l) { return true; } -void send_card_auction_if_all_clients_ready( - shared_ptr s, shared_ptr l) { - // Check if any client is still not ready - size_t x; - for (x = 0; x < l->max_clients; x++) { - if (!l->clients[x]) { - continue; - } - if (!(l->clients[x]->flags & Client::Flag::AWAITING_CARD_AUCTION)) { - break; - } - } - if (x != l->max_clients) { - return; - } - - for (x = 0; x < l->max_clients; x++) { - if (l->clients[x]) { - l->clients[x]->flags &= ~Client::Flag::AWAITING_CARD_AUCTION; - } - } - +void send_ep3_card_auction(shared_ptr s, shared_ptr l) { if ((s->ep3_card_auction_points == 0) || (s->ep3_card_auction_min_size == 0) || (s->ep3_card_auction_max_size == 0)) { @@ -2830,13 +2808,8 @@ void send_card_auction_if_all_clients_ready( } } send_command_t(l, 0xEF, num_cards, cmd); - - for (auto c : l->clients) { - if (c) { - c->disconnect_hooks.erase(CARD_AUCTION_DISCONNECT_HOOK_NAME); - } - } } + void send_server_time(shared_ptr c) { uint64_t t = now(); diff --git a/src/SendCommands.hh b/src/SendCommands.hh index 29fd5faa..5a5df88a 100644 --- a/src/SendCommands.hh +++ b/src/SendCommands.hh @@ -369,6 +369,8 @@ void send_ep3_game_details( void send_ep3_update_spectator_count(std::shared_ptr l); +void send_ep3_card_auction(std::shared_ptr s, std::shared_ptr l); + // Pass mask_key = 0 to unmask the command void set_mask_for_ep3_game_command(void* vdata, size_t size, uint8_t mask_key); @@ -394,9 +396,6 @@ void send_quest_file_chunk( bool is_download_quest); bool send_quest_barrier_if_all_clients_ready(std::shared_ptr l); -void send_card_auction_if_all_clients_ready( - std::shared_ptr s, std::shared_ptr l); - void send_server_time(std::shared_ptr c); void send_change_event(std::shared_ptr c, uint8_t new_event);