From f3dfa0989f970fefbf522b0c29638f97401a8f40 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Thu, 22 Dec 2022 22:27:23 -0800 Subject: [PATCH] don't bother with lobby id free list --- src/ServerState.cc | 7 ++++--- src/ServerState.hh | 3 --- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/ServerState.cc b/src/ServerState.cc index 84c2d9c6..f9d22281 100644 --- a/src/ServerState.cc +++ b/src/ServerState.cc @@ -189,10 +189,11 @@ vector> ServerState::all_lobbies() { } shared_ptr ServerState::create_lobby() { - shared_ptr l(new Lobby(this->next_lobby_id++)); - if (!this->id_to_lobby.emplace(l->lobby_id, l).second) { - throw logic_error("lobby already exists with the given id"); + while (this->id_to_lobby.count(this->next_lobby_id)) { + this->next_lobby_id++; } + shared_ptr l(new Lobby(this->next_lobby_id++)); + this->id_to_lobby.emplace(l->lobby_id, l); l->log.info("Created lobby"); return l; } diff --git a/src/ServerState.hh b/src/ServerState.hh index 35398fe9..3b308572 100644 --- a/src/ServerState.hh +++ b/src/ServerState.hh @@ -99,9 +99,6 @@ struct ServerState { 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 - // technically should handle it. std::atomic next_lobby_id; uint8_t pre_lobby_event; int32_t ep3_menu_song;