From c43fa7a40d795d16cad6f34c3ee6e1c4357205d9 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Thu, 22 Sep 2022 22:51:46 -0700 Subject: [PATCH] don't send extra lobbies to v1 clients --- src/ServerState.cc | 29 ++++++++++++++++++++++------- src/ServerState.hh | 3 ++- tests/DCv1-GameSmokeTest.test.txt | 16 ++++------------ 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/ServerState.cc b/src/ServerState.cc index 60b1dd19..bf8f54f2 100644 --- a/src/ServerState.cc +++ b/src/ServerState.cc @@ -25,28 +25,40 @@ ServerState::ServerState() run_shell_behavior(RunShellBehavior::DEFAULT), next_lobby_id(1), pre_lobby_event(0), ep3_menu_song(-1) { + vector> non_v1_only_lobbies; vector> ep3_only_lobbies; for (size_t x = 0; x < 20; x++) { auto lobby_name = decode_sjis(string_printf("LOBBY%zu", x + 1)); + bool is_non_v1_only = (x > 9); bool is_ep3_only = (x > 14); shared_ptr l = this->create_lobby(); - l->flags |= Lobby::Flag::PUBLIC | Lobby::Flag::DEFAULT | Lobby::Flag::PERSISTENT | + l->flags |= + Lobby::Flag::PUBLIC | + Lobby::Flag::DEFAULT | + Lobby::Flag::PERSISTENT | + (is_non_v1_only ? Lobby::Flag::NON_V1_ONLY : 0) | (is_ep3_only ? Lobby::Flag::EPISODE_3_ONLY : 0); l->block = x + 1; l->type = x; l->name = lobby_name; l->max_clients = 12; + if (!is_non_v1_only) { + this->public_lobby_search_order_v1.emplace_back(l); + } if (!is_ep3_only) { - this->public_lobby_search_order.emplace_back(l); + this->public_lobby_search_order_non_v1.emplace_back(l); } else { ep3_only_lobbies.emplace_back(l); } } - this->public_lobby_search_order_ep3 = this->public_lobby_search_order; + // Annoyingly, the CARD lobbies should be searched first, but are sent at the + // end of the lobby list command, so we have to change t he search order + // manually here. + this->public_lobby_search_order_ep3 = this->public_lobby_search_order_non_v1; this->public_lobby_search_order_ep3.insert( this->public_lobby_search_order_ep3.begin(), ep3_only_lobbies.begin(), @@ -67,10 +79,13 @@ void ServerState::add_client_to_available_lobby(shared_ptr c) { } if (!added_to_lobby.get()) { - const auto& search_order = (c->flags & Client::Flag::EPISODE_3) - ? this->public_lobby_search_order_ep3 - : this->public_lobby_search_order; - for (const auto& l : search_order) { + const auto* search_order = &this->public_lobby_search_order_non_v1; + if (c->flags & Client::Flag::IS_DC_V1) { + search_order = &this->public_lobby_search_order_v1; + } else if (c->flags & Client::Flag::IS_EPISODE_3) { + search_order = &this->public_lobby_search_order_ep3; + } + for (const auto& l : *search_order) { try { l->add_client(c); added_to_lobby = l; diff --git a/src/ServerState.hh b/src/ServerState.hh index aae4e5ca..c7c416ab 100644 --- a/src/ServerState.hh +++ b/src/ServerState.hh @@ -84,7 +84,8 @@ struct ServerState { std::u16string bb_patch_server_message; std::map> id_to_lobby; - std::vector> public_lobby_search_order; + std::vector> public_lobby_search_order_v1; + std::vector> public_lobby_search_order_non_v1; std::vector> public_lobby_search_order_ep3; // TODO: Use a free-list instead of an incrementer to prevent wrap-around // behavioral bugs. This... will probably never be an issue for anyone, but we diff --git a/tests/DCv1-GameSmokeTest.test.txt b/tests/DCv1-GameSmokeTest.test.txt index 7cddf721..47e27743 100644 --- a/tests/DCv1-GameSmokeTest.test.txt +++ b/tests/DCv1-GameSmokeTest.test.txt @@ -147,18 +147,14 @@ I 69775 2022-08-27 09:36:31 - [Commands] Sending to C-3 (version=DC command=04 f 0010 | 0E 89 2A 49 14 02 00 00 00 00 00 00 FF FF FF FF | *I 0020 | FF FF FF FF FF FF FF FF FF FF FF FF | I 69775 2022-08-27 09:36:31 - [Commands] Sending to C-3 (version=DC command=83 flag=0F) -0000 | 83 0F B8 00 33 00 00 33 01 00 00 00 00 00 00 00 | 3 3 +0000 | 83 0A 7C 00 33 00 00 33 01 00 00 00 00 00 00 00 | 3 3 0010 | 33 00 00 33 02 00 00 00 00 00 00 00 33 00 00 33 | 3 3 3 3 0020 | 03 00 00 00 00 00 00 00 33 00 00 33 04 00 00 00 | 3 3 0030 | 00 00 00 00 33 00 00 33 05 00 00 00 00 00 00 00 | 3 3 0040 | 33 00 00 33 06 00 00 00 00 00 00 00 33 00 00 33 | 3 3 3 3 0050 | 07 00 00 00 00 00 00 00 33 00 00 33 08 00 00 00 | 3 3 0060 | 00 00 00 00 33 00 00 33 09 00 00 00 00 00 00 00 | 3 3 -0070 | 33 00 00 33 0A 00 00 00 00 00 00 00 33 00 00 33 | 3 3 3 3 -0080 | 0B 00 00 00 00 00 00 00 33 00 00 33 0C 00 00 00 | 3 3 -0090 | 00 00 00 00 33 00 00 33 0D 00 00 00 00 00 00 00 | 3 3 -00A0 | 33 00 00 33 0E 00 00 00 00 00 00 00 33 00 00 33 | 3 3 3 3 -00B0 | 0F 00 00 00 00 00 00 00 | +0070 | 33 00 00 33 0A 00 00 00 00 00 00 00 | 3 3 I 69775 2022-08-27 09:36:31 - [Commands] Sending to C-3 (version=DC command=95 flag=00) 0000 | 95 00 04 00 | I 69775 2022-08-27 09:36:32 - [Commands] Received from C-3 (version=DC command=61 flag=01) @@ -640,18 +636,14 @@ I 69775 2022-08-27 09:37:10 - [Commands] Sending to C-5 (version=DC command=04 f 0010 | 0E 89 2A 49 14 02 00 00 00 00 00 00 FF FF FF FF | *I 0020 | FF FF FF FF FF FF FF FF FF FF FF FF | I 69775 2022-08-27 09:37:10 - [Commands] Sending to C-5 (version=DC command=83 flag=0F) -0000 | 83 0F B8 00 33 00 00 33 01 00 00 00 00 00 00 00 | 3 3 +0000 | 83 0A 7C 00 33 00 00 33 01 00 00 00 00 00 00 00 | 3 3 0010 | 33 00 00 33 02 00 00 00 00 00 00 00 33 00 00 33 | 3 3 3 3 0020 | 03 00 00 00 00 00 00 00 33 00 00 33 04 00 00 00 | 3 3 0030 | 00 00 00 00 33 00 00 33 05 00 00 00 00 00 00 00 | 3 3 0040 | 33 00 00 33 06 00 00 00 00 00 00 00 33 00 00 33 | 3 3 3 3 0050 | 07 00 00 00 00 00 00 00 33 00 00 33 08 00 00 00 | 3 3 0060 | 00 00 00 00 33 00 00 33 09 00 00 00 00 00 00 00 | 3 3 -0070 | 33 00 00 33 0A 00 00 00 00 00 00 00 33 00 00 33 | 3 3 3 3 -0080 | 0B 00 00 00 00 00 00 00 33 00 00 33 0C 00 00 00 | 3 3 -0090 | 00 00 00 00 33 00 00 33 0D 00 00 00 00 00 00 00 | 3 3 -00A0 | 33 00 00 33 0E 00 00 00 00 00 00 00 33 00 00 33 | 3 3 3 3 -00B0 | 0F 00 00 00 00 00 00 00 | +0070 | 33 00 00 33 0A 00 00 00 00 00 00 00 | 3 3 I 69775 2022-08-27 09:37:10 - [Commands] Sending to C-5 (version=DC command=95 flag=00) 0000 | 95 00 04 00 | I 69775 2022-08-27 09:37:10 - [Commands] Received from C-5 (version=DC command=61 flag=01)