add lobby order option for client customization

This commit is contained in:
Martin Michelsen
2024-06-15 17:25:58 -07:00
parent 5433663866
commit f3f933aaca
4 changed files with 21 additions and 3 deletions
+14 -2
View File
@@ -61,7 +61,7 @@ void ServerState::add_client_to_available_lobby(shared_ptr<Client> c) {
}
if (!added_to_lobby.get()) {
for (const auto& lobby_id : this->public_lobby_search_order(c->version())) {
for (const auto& lobby_id : this->public_lobby_search_order(c)) {
try {
auto l = this->find_lobby(lobby_id);
if (l &&
@@ -317,8 +317,11 @@ const vector<pair<string, uint16_t>>& ServerState::proxy_destinations(Version ve
}
}
const vector<uint32_t> ServerState::public_lobby_search_order(Version version) const {
const vector<uint32_t>& ServerState::public_lobby_search_order(Version version, bool is_client_customization) const {
static_assert(NUM_VERSIONS == 14, "Don\'t forget to update the public lobby search orders in config.json");
if (is_client_customization && !this->client_customization_public_lobby_search_order.empty()) {
return this->client_customization_public_lobby_search_order;
}
return this->public_lobby_search_orders.at(static_cast<size_t>(version));
}
@@ -973,6 +976,7 @@ void ServerState::load_config_early() {
for (auto& order : this->public_lobby_search_orders) {
order.clear();
}
this->client_customization_public_lobby_search_order.clear();
try {
const auto& orders_json = this->config_json->get_list("LobbySearchOrders");
for (size_t v_s = 0; v_s < orders_json.size(); v_s++) {
@@ -984,6 +988,14 @@ void ServerState::load_config_early() {
}
} catch (const out_of_range&) {
}
try {
const auto& order_json = this->config_json->get_list("ClientCustomizationLobbySearchOrder");
auto& order = this->client_customization_public_lobby_search_order;
for (const auto& it : order_json) {
order.emplace_back(it->as_int());
}
} catch (const out_of_range&) {
}
this->pre_lobby_event = 0;
try {
+5 -1
View File
@@ -251,6 +251,7 @@ struct ServerState : public std::enable_shared_from_this<ServerState> {
std::unordered_set<std::shared_ptr<Lobby>> lobbies_to_destroy;
std::shared_ptr<struct event> destroy_lobbies_event;
std::array<std::vector<uint32_t>, NUM_VERSIONS> public_lobby_search_orders;
std::vector<uint32_t> client_customization_public_lobby_search_order;
std::atomic<int32_t> next_lobby_id = 1;
uint8_t pre_lobby_event = 0;
int32_t ep3_menu_song = -1;
@@ -316,7 +317,10 @@ struct ServerState : public std::enable_shared_from_this<ServerState> {
std::string describe_item(Version version, const ItemData& item, bool include_color_codes) const;
ItemData parse_item_description(Version version, const std::string& description) const;
const std::vector<uint32_t> public_lobby_search_order(Version version) const;
const std::vector<uint32_t>& public_lobby_search_order(Version version, bool is_client_customization) const;
inline const std::vector<uint32_t>& public_lobby_search_order(std::shared_ptr<const Client> c) const {
return this->public_lobby_search_order(c->version(), c->config.check_flag(Client::Flag::IS_CLIENT_CUSTOMIZATION));
}
inline uint32_t name_color_for_client(Version v, bool is_client_customization) const {
if (is_client_customization && this->client_customization_name_color) {