From 78bb791c2630ad44587ba725dcacabf01ce0335c Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Sun, 29 May 2022 12:43:57 -0700 Subject: [PATCH] make high client ID assignment optional --- src/ChatCommands.cc | 6 ++++++ src/Client.cc | 1 + src/Client.hh | 1 + src/Lobby.cc | 6 +++--- src/Lobby.hh | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ChatCommands.cc b/src/ChatCommands.cc index 1edf1a24..3238ddae 100644 --- a/src/ChatCommands.cc +++ b/src/ChatCommands.cc @@ -142,6 +142,11 @@ static void command_arrow(shared_ptr, shared_ptr l, } } +static void command_dbgid(shared_ptr, shared_ptr, + shared_ptr c, const std::u16string&) { + c->prefer_high_lobby_client_id = !c->prefer_high_lobby_client_id; +} + //////////////////////////////////////////////////////////////////////////////// // Lobby commands @@ -692,6 +697,7 @@ static const unordered_map chat_commands({ {u"$bbchar" , {command_convert_char_to_bb, u"Usage:\nbbchar <1-4>"}}, // {u"$bank", {command_bank , u"Usage:\nbank "}}, {u"$cheat" , {command_cheat , u"Usage:\ncheat"}}, + {u"$dbgid" , {command_dbgid , u"Usage:\ndngid"}}, {u"$edit" , {command_edit , u"Usage:\nedit "}}, {u"$event" , {command_lobby_event , u"Usage:\nevent "}}, {u"$infhp" , {command_infinite_hp , u"Usage:\ninfhp"}}, diff --git a/src/Client.cc b/src/Client.cc index 32247796..fd5c6648 100644 --- a/src/Client.cc +++ b/src/Client.cc @@ -39,6 +39,7 @@ Client::Client( lobby_id(0), lobby_client_id(0), lobby_arrow_color(0), + prefer_high_lobby_client_id(false), next_exp_value(0), override_section_id(-1), infinite_hp(false), diff --git a/src/Client.hh b/src/Client.hh index 7bd489f6..e144189f 100644 --- a/src/Client.hh +++ b/src/Client.hh @@ -90,6 +90,7 @@ struct Client { uint32_t lobby_id; // which lobby is this person in? uint8_t lobby_client_id; // which client number is this person? uint8_t lobby_arrow_color; // lobby arrow color ID + bool prefer_high_lobby_client_id; ClientGameData game_data; // Miscellaneous (used by chat commands) diff --git a/src/Lobby.cc b/src/Lobby.cc index 12602569..cbc8052c 100644 --- a/src/Lobby.cc +++ b/src/Lobby.cc @@ -57,9 +57,9 @@ size_t Lobby::count_clients() const { return ret; } -void Lobby::add_client(shared_ptr c, bool reverse_indexes) { +void Lobby::add_client(shared_ptr c) { ssize_t index; - if (reverse_indexes) { + if (c->prefer_high_lobby_client_id) { for (index = max_clients - 1; index >= 0; index--) { if (!this->clients[index].get()) { this->clients[index] = c; @@ -85,7 +85,7 @@ void Lobby::add_client(shared_ptr c, bool reverse_indexes) { c->lobby_id = this->lobby_id; // If there's no one else in the lobby, set the leader id as well - if (index == (max_clients - 1) * reverse_indexes) { + if (index == (max_clients - 1) * c->prefer_high_lobby_client_id) { for (index = 0; index < max_clients; index++) { if (this->clients[index].get() && this->clients[index] != c) { break; diff --git a/src/Lobby.hh b/src/Lobby.hh index 91e6672c..4bf12e91 100644 --- a/src/Lobby.hh +++ b/src/Lobby.hh @@ -80,7 +80,7 @@ struct Lobby { size_t count_clients() const; bool any_client_loading() const; - void add_client(std::shared_ptr c, bool reverse_indexes = true); + void add_client(std::shared_ptr c); void remove_client(std::shared_ptr c); void move_client_to_lobby(std::shared_ptr dest_lobby,