diff --git a/src/Lobby.hh b/src/Lobby.hh index e77af95c..e38bc6c0 100644 --- a/src/Lobby.hh +++ b/src/Lobby.hh @@ -103,7 +103,7 @@ struct Lobby : public std::enable_shared_from_this { uint8_t leader_id; uint8_t max_clients; uint32_t flags; - std::shared_ptr loading_quest; + std::shared_ptr quest; std::array, 12> clients; // Keys in this map are client_id std::unordered_map> clients_to_add; diff --git a/src/ReceiveCommands.cc b/src/ReceiveCommands.cc index b03b972f..c9060d52 100644 --- a/src/ReceiveCommands.cc +++ b/src/ReceiveCommands.cc @@ -1568,11 +1568,11 @@ static void on_09(shared_ptr s, shared_ptr c, info += "$C4Locked$C7\n"; } - if (game->loading_quest) { + if (game->quest) { if (game->flags & Lobby::Flag::JOINABLE_QUEST_IN_PROGRESS) { - info += "$C6Quest: " + encode_sjis(game->loading_quest->name); + info += "$C6Quest: " + encode_sjis(game->quest->name); } else { - info += "$C4Quest: " + encode_sjis(game->loading_quest->name); + info += "$C4Quest: " + encode_sjis(game->quest->name); } } else if (game->flags & Lobby::Flag::JOINABLE_QUEST_IN_PROGRESS) { info += "$C6Quest in progress"; @@ -2005,7 +2005,7 @@ static void on_10(shared_ptr s, shared_ptr c, } else { l->flags |= Lobby::Flag::QUEST_IN_PROGRESS; } - l->loading_quest = q; + l->quest = q; for (size_t x = 0; x < l->max_clients; x++) { if (!l->clients[x]) { continue; @@ -2337,7 +2337,34 @@ static void on_AC_V3_BB(shared_ptr s, shared_ptr c, } c->flags &= ~Client::Flag::LOADING_QUEST; - send_quest_barrier_if_all_clients_ready(s->find_lobby(c->lobby_id)); + auto l = s->find_lobby(c->lobby_id); + if (!l->quest.get()) { + return; + } + + if (send_quest_barrier_if_all_clients_ready(l) && + (l->version == GameVersion::BB)) { + // TODO: We should replace the game enemies list here. It'll look something + // like this (but the dat format may be different from the existing loader): + // try { + // auto dat_data = prs_decompress(l->quest->dat_contents()); + // game->enemies = parse_map( + // s->battle_params, + // l->flags & Lobby::Flag::SOLO_MODE, + // l->episode, + // l->difficulty, + // dat_data, + // false); + // c->log.info("Replaced enemies list with quest layout (%zu entries)", + // l->enemies.size()); + // for (size_t z = 0; z < l->enemies.size(); z++) { + // string e_str = l->enemies[z].str(); + // l->log.info("(Entry %zX) %s", z, e_str.c_str()); + // } + // } catch (const exception& e) { + // c->log.info("Failed to load quest layout: %s", e.what()); + // } + } } static void on_AA(shared_ptr s, @@ -2349,8 +2376,8 @@ static void on_AA(shared_ptr s, } auto l = s->find_lobby(c->lobby_id); - if (!l || !l->is_game() || !l->loading_quest.get() || - (l->loading_quest->internal_id != cmd.quest_internal_id)) { + if (!l || !l->is_game() || !l->quest.get() || + (l->quest->internal_id != cmd.quest_internal_id)) { return; } diff --git a/src/SendCommands.cc b/src/SendCommands.cc index d64c3209..87e63d7c 100644 --- a/src/SendCommands.cc +++ b/src/SendCommands.cc @@ -2435,9 +2435,9 @@ void send_open_quest_file(shared_ptr c, const string& quest_name, } } -void send_quest_barrier_if_all_clients_ready(shared_ptr l) { +bool send_quest_barrier_if_all_clients_ready(shared_ptr l) { if (!l || !l->is_game()) { - return; + return false; } // Check if any client is still loading @@ -2452,16 +2452,17 @@ void send_quest_barrier_if_all_clients_ready(shared_ptr l) { } // If they're all done, start the quest - if (x == l->max_clients) { - send_command(l, 0xAC, 0x00); + if (x != l->max_clients) { + return false; } - // Check if any client is still loading + send_command(l, 0xAC, 0x00); for (x = 0; x < l->max_clients; x++) { if (l->clients[x]) { l->clients[x]->disconnect_hooks.erase(QUEST_BARRIER_DISCONNECT_HOOK_NAME); } } + return true; } void send_card_auction_if_all_clients_ready( diff --git a/src/SendCommands.hh b/src/SendCommands.hh index 166172a4..0062b428 100644 --- a/src/SendCommands.hh +++ b/src/SendCommands.hh @@ -381,7 +381,7 @@ void send_quest_file_chunk( const void* data, size_t size, bool is_download_quest); -void send_quest_barrier_if_all_clients_ready(std::shared_ptr l); +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);