add option to set nonzero client IDs by default

This commit is contained in:
Martin Michelsen
2022-03-30 00:51:08 -07:00
parent bcd69bab89
commit 39f8a33588
3 changed files with 25 additions and 14 deletions
+17 -4
View File
@@ -65,8 +65,19 @@ size_t Lobby::count_clients() const {
return ret; return ret;
} }
void Lobby::add_client(shared_ptr<Client> c) { void Lobby::add_client(shared_ptr<Client> c, bool reverse_indexes) {
ssize_t index; ssize_t index;
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++) { for (index = 0; index < max_clients; index++) {
if (!this->clients[index].get()) { if (!this->clients[index].get()) {
this->clients[index] = c; this->clients[index] = c;
@@ -76,13 +87,15 @@ void Lobby::add_client(shared_ptr<Client> c) {
if (index >= max_clients) { if (index >= max_clients) {
throw out_of_range("no space left in lobby"); throw out_of_range("no space left in lobby");
} }
}
c->lobby_client_id = index; c->lobby_client_id = index;
c->lobby_id = this->lobby_id; c->lobby_id = this->lobby_id;
// if there's no one else in the lobby, set the leader id as well // if there's no one else in the lobby, set the leader id as well
if (index == 0) { if (index == (max_clients - 1) * reverse_indexes) {
for (index = 1; index < max_clients; index++) { for (index = 0; index < max_clients; index++) {
if (this->clients[index].get()) { if (this->clients[index].get() && this->clients[index] != c) {
break; break;
} }
} }
+1 -1
View File
@@ -65,7 +65,7 @@ struct Lobby {
size_t count_clients() const; size_t count_clients() const;
bool any_client_loading() const; bool any_client_loading() const;
void add_client(std::shared_ptr<Client> c); void add_client(std::shared_ptr<Client> c, bool reverse_indexes = false);
void remove_client(std::shared_ptr<Client> c); void remove_client(std::shared_ptr<Client> c);
void move_client_to_lobby(std::shared_ptr<Lobby> dest_lobby, void move_client_to_lobby(std::shared_ptr<Lobby> dest_lobby,
-2
View File
@@ -1653,8 +1653,6 @@ shared_ptr<Lobby> create_game_generic(shared_ptr<ServerState> s,
game->min_level = min_level; game->min_level = min_level;
game->max_level = 0xFFFFFFFF; game->max_level = 0xFFFFFFFF;
log(INFO, "[Debug] create game: %p->flags = %08" PRIX32, game.get(), game->flags);
if (game->version == GameVersion::BB) { if (game->version == GameVersion::BB) {
// TODO: cache these somewhere so we don't read the file every time, lolz // 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", game->rare_item_set.reset(new RareItemSet("system/blueburst/ItemRT.rel",