diff --git a/src/Lobby.cc b/src/Lobby.cc index 9da2bed4..eaeba54f 100644 --- a/src/Lobby.cc +++ b/src/Lobby.cc @@ -65,24 +65,37 @@ size_t Lobby::count_clients() const { return ret; } -void Lobby::add_client(shared_ptr c) { +void Lobby::add_client(shared_ptr c, bool reverse_indexes) { ssize_t index; - for (index = 0; index < max_clients; index++) { - if (!this->clients[index].get()) { - this->clients[index] = c; - break; + if (reverse_indexes) { + for (index = max_clients - 1; index >= 0; index--) { + if (!this->clients[index].get()) { + this->clients[index] = c; + break; + } + } + if (index < 0) { + throw out_of_range("no space left in lobby"); + } + } else { + for (index = 0; index < max_clients; index++) { + if (!this->clients[index].get()) { + this->clients[index] = c; + break; + } + } + if (index >= max_clients) { + throw out_of_range("no space left in lobby"); } } - if (index >= max_clients) { - throw out_of_range("no space left in lobby"); - } + c->lobby_client_id = index; c->lobby_id = this->lobby_id; // if there's no one else in the lobby, set the leader id as well - if (index == 0) { - for (index = 1; index < max_clients; index++) { - if (this->clients[index].get()) { + if (index == (max_clients - 1) * reverse_indexes) { + 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 90182e41..68baa7d2 100644 --- a/src/Lobby.hh +++ b/src/Lobby.hh @@ -65,7 +65,7 @@ struct Lobby { size_t count_clients() const; bool any_client_loading() const; - void add_client(std::shared_ptr c); + void add_client(std::shared_ptr c, bool reverse_indexes = false); void remove_client(std::shared_ptr c); void move_client_to_lobby(std::shared_ptr dest_lobby, diff --git a/src/ReceiveCommands.cc b/src/ReceiveCommands.cc index 87e59642..ad234b56 100644 --- a/src/ReceiveCommands.cc +++ b/src/ReceiveCommands.cc @@ -1653,8 +1653,6 @@ shared_ptr create_game_generic(shared_ptr s, game->min_level = min_level; game->max_level = 0xFFFFFFFF; - log(INFO, "[Debug] create game: %p->flags = %08" PRIX32, game.get(), game->flags); - if (game->version == GameVersion::BB) { // TODO: cache these somewhere so we don't read the file every time, lolz game->rare_item_set.reset(new RareItemSet("system/blueburst/ItemRT.rel",