add option to set nonzero client IDs by default
This commit is contained in:
+24
-11
@@ -65,24 +65,37 @@ size_t Lobby::count_clients() const {
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Lobby::add_client(shared_ptr<Client> c) {
|
||||
void Lobby::add_client(shared_ptr<Client> 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;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ struct Lobby {
|
||||
size_t count_clients() 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 move_client_to_lobby(std::shared_ptr<Lobby> dest_lobby,
|
||||
|
||||
@@ -1653,8 +1653,6 @@ shared_ptr<Lobby> create_game_generic(shared_ptr<ServerState> 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",
|
||||
|
||||
Reference in New Issue
Block a user