From 33b95015a240990e7ed61d9243857fc14dc8fc1b Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Wed, 6 Mar 2024 12:48:54 -0800 Subject: [PATCH] add option to override name colors by game version --- src/ReceiveSubcommands.cc | 6 ++++++ src/SendCommands.cc | 35 +++++++++++++++++++++++++++++++---- src/ServerState.cc | 14 ++++++++++++++ src/ServerState.hh | 5 +++++ src/Version.hh | 2 ++ system/config.example.json | 19 +++++++++++++++++++ 6 files changed, 77 insertions(+), 4 deletions(-) diff --git a/src/ReceiveSubcommands.cc b/src/ReceiveSubcommands.cc index a4b381d2..fc73a4be 100644 --- a/src/ReceiveSubcommands.cc +++ b/src/ReceiveSubcommands.cc @@ -846,6 +846,12 @@ static void on_sync_joining_player_disp_and_inventory( parsed->transcode_inventory_items(c_v, target_v, s->item_parameter_table_for_encode(target_v)); parsed->visual.enforce_lobby_join_limits_for_version(target_v); + if (s->version_name_colors) { + parsed->visual.name_color = s->name_color_for_version(c_v); + if (is_v1_or_v2(c_v)) { + parsed->visual.compute_name_color_checksum(); + } + } switch (target_v) { case Version::DC_NTE: diff --git a/src/SendCommands.cc b/src/SendCommands.cc index c66f7e9c..39881b12 100644 --- a/src/SendCommands.cc +++ b/src/SendCommands.cc @@ -1703,6 +1703,11 @@ static void send_join_spectator_team(shared_ptr c, shared_ptr l) : wc_p->disp.stats.level.load(); e.name_color = wc_p->disp.visual.name_color; + if (s->version_name_colors) { + p.disp.visual.name_color = s->name_color_for_version(wc->version()); + e.name_color = p.disp.visual.name_color; + } + player_count++; } @@ -1766,6 +1771,11 @@ static void send_join_spectator_team(shared_ptr c, shared_ptr l) : other_p->disp.stats.level.load(); cmd_e.name_color = other_p->disp.visual.name_color; + if (s->version_name_colors) { + cmd_p.disp.visual.name_color = s->name_color_for_version(other_c->version()); + cmd_e.name_color = cmd_p.disp.visual.name_color; + } + player_count++; } } @@ -1867,10 +1877,14 @@ void send_join_game(shared_ptr c, shared_ptr l) { for (size_t x = 0; x < 4; x++) { if (l->clients[x]) { auto other_p = l->clients[x]->character(); - cmd.players_ep3[x].inventory = other_p->inventory; - cmd.players_ep3[x].inventory.encode_for_client(c); - cmd.players_ep3[x].disp = convert_player_disp_data(other_p->disp, c->language(), other_p->inventory.language); - cmd.players_ep3[x].disp.enforce_lobby_join_limits_for_version(c->version()); + auto& cmd_p = cmd.players_ep3[x]; + cmd_p.inventory = other_p->inventory; + cmd_p.inventory.encode_for_client(c); + cmd_p.disp = convert_player_disp_data(other_p->disp, c->language(), other_p->inventory.language); + cmd_p.disp.enforce_lobby_join_limits_for_version(c->version()); + if (s->version_name_colors) { + cmd_p.disp.visual.name_color = s->name_color_for_version(l->clients[x]->version()); + } } } send_command_t(c, 0x64, player_count, cmd); @@ -1987,6 +2001,12 @@ void send_join_lobby_t(shared_ptr c, shared_ptr l, shared_ptr(lp->disp, c->language(), lp->inventory.language); e.disp.enforce_lobby_join_limits_for_version(c->version()); + if (s->version_name_colors) { + e.disp.visual.name_color = s->name_color_for_version(lc->version()); + if (is_v1_or_v2(c->version())) { + e.disp.visual.compute_name_color_checksum(); + } + } } } @@ -2053,6 +2073,9 @@ void send_join_lobby_xb(shared_ptr c, shared_ptr l, shared_ptr(lp->disp, c->language(), lp->inventory.language); e.disp.enforce_lobby_join_limits_for_version(c->version()); + if (s->version_name_colors) { + e.disp.visual.name_color = s->name_color_for_version(lc->version()); + } } send_command(c, command, used_entries, &cmd, cmd.size(used_entries)); @@ -2101,6 +2124,10 @@ void send_join_lobby_dc_nte(shared_ptr c, shared_ptr l, } else { e.disp = convert_player_disp_data(lp->disp, c->language(), lp->inventory.language); e.disp.enforce_lobby_join_limits_for_version(c->version()); + if (s->version_name_colors) { + e.disp.visual.name_color = s->name_color_for_version(lc->version()); + e.disp.visual.compute_name_color_checksum(); + } } } diff --git a/src/ServerState.cc b/src/ServerState.cc index ad41e412..6f17eeeb 100644 --- a/src/ServerState.cc +++ b/src/ServerState.cc @@ -888,6 +888,20 @@ void ServerState::load_config_early() { this->allow_gc_xb_games = this->config_json->get_bool("AllowGCXBGames", true); this->enable_chat_commands = this->config_json->get_bool("EnableChatCommands", true); + this->version_name_colors.reset(); + try { + const auto& colors_json = this->config_json->get_list("VersionNameColors"); + if (colors_json.size() != NUM_NON_PATCH_VERSIONS) { + throw runtime_error("VersionNameColors list length is incorrect"); + } + auto new_colors = make_unique>(); + for (size_t z = 0; z < NUM_NON_PATCH_VERSIONS; z++) { + new_colors->at(z) = colors_json.at(z)->as_int(); + } + this->version_name_colors = std::move(new_colors); + } catch (const out_of_range&) { + } + for (auto& order : this->public_lobby_search_orders) { order.clear(); } diff --git a/src/ServerState.hh b/src/ServerState.hh index a0a980f6..bb8a1b81 100644 --- a/src/ServerState.hh +++ b/src/ServerState.hh @@ -91,6 +91,7 @@ struct ServerState : public std::enable_shared_from_this { bool allow_dc_pc_games = true; bool allow_gc_xb_games = true; bool enable_chat_commands = true; + std::unique_ptr> version_name_colors; uint8_t allowed_drop_modes_v1_v2_normal = 0x1F; uint8_t allowed_drop_modes_v1_v2_battle = 0x07; uint8_t allowed_drop_modes_v1_v2_challenge = 0x07; @@ -293,6 +294,10 @@ struct ServerState : public std::enable_shared_from_this { const std::vector public_lobby_search_order(Version version) const; + inline uint32_t name_color_for_version(Version v) const { + return this->version_name_colors ? this->version_name_colors->at(static_cast(v) - NUM_PATCH_VERSIONS) : 0; + } + std::shared_ptr> information_contents_for_client(std::shared_ptr c) const; std::shared_ptr quest_index(Version version) const; diff --git a/src/Version.hh b/src/Version.hh index 0839eadb..5580414e 100644 --- a/src/Version.hh +++ b/src/Version.hh @@ -28,6 +28,8 @@ constexpr size_t NUM_VERSIONS = static_cast(Version::BB_V4) + 1; constexpr size_t NUM_PATCH_VERSIONS = static_cast(Version::BB_PATCH) + 1; constexpr size_t NUM_NON_PATCH_VERSIONS = NUM_VERSIONS - NUM_PATCH_VERSIONS; +static_assert(NUM_NON_PATCH_VERSIONS == 12, "Don't forget to update VersionNameColors in config.json"); + template <> const char* name_for_enum(Version v); template <> diff --git a/system/config.example.json b/system/config.example.json index 77830415..a9a804e1 100644 --- a/system/config.example.json +++ b/system/config.example.json @@ -963,6 +963,25 @@ "AllowDCPCGames": false, "AllowGCXBGames": true, + // This option causes the server to override name colors for all players based + // on which version of the game they're using. If this option is missing or + // commented out (the default), the server does not override any name colors. + // There must be 12 entries in this list, and colors are specified as ARGB32. + // "VersionNameColors": [ + // 0xFFBBBBBB, // DC NTE + // 0xFF666666, // DC 11/2000 + // 0xFFFFFFFF, // DC v1 + // 0xFFFFAE35, // DC v2 + // 0xFF875C1C, // PC NTE + // 0xFFFFAE35, // PC v2 + // 0xFF663366, // GC NTE + // 0xFFFFBBFF, // GC + // 0xFF666600, // Ep3 NTE + // 0xFFDFF56E, // Ep3 + // 0xFFBBFFBB, // Xbox + // 0xFF55FDE3, // BB (the official Episode 4 color is probably 0xFFC69141) + // ], + // These options control which item drop modes are used by default, and which // can be chosen by the player. The AllowedDropModes fields are a bitmask // specifying which modes players can choose with the $dropmode command. The