From 95346118f0907de9e45912750c25a0e40ac73d20 Mon Sep 17 00:00:00 2001 From: Reason <44870510+reason44@users.noreply.github.com> Date: Thu, 8 Jun 2023 17:33:43 -0400 Subject: [PATCH] Toggle drops. Through txt command in-game, or through the config file. White space fix. Forgot this part. --- src/ChatCommands.cc | 17 +++++++++++++++++ src/ReceiveSubcommands.cc | 9 +++++---- src/ServerState.cc | 8 ++++++++ src/ServerState.hh | 1 + system/config.example.json | 3 +++ 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/ChatCommands.cc b/src/ChatCommands.cc index dde1c41e..0f08b665 100644 --- a/src/ChatCommands.cc +++ b/src/ChatCommands.cc @@ -1123,6 +1123,22 @@ static void proxy_command_switch_assist(shared_ptr, session.options.switch_assist ? "enabled" : "disabled"); } +static void server_command_drop(shared_ptrs, shared_ptr l, + shared_ptr c, const std::u16string&) { + check_is_game(l, true); + check_is_leader(l, c); + if (s->drops_enabled == true) + { + send_text_message(c, u"Drops disabled."); + s->drops_enabled = false; + } + else + { + send_text_message(c, u"Drops enabled."); + s->drops_enabled = true; + } +} + static void server_command_item(shared_ptr, shared_ptr l, shared_ptr c, const std::u16string& args) { check_is_game(l, true); @@ -1262,6 +1278,7 @@ static const unordered_map chat_commands({ {u"$type", {server_command_lobby_type, nullptr, u"Usage:\ntype "}}, {u"$warp", {server_command_warp, proxy_command_warp, u"Usage:\nwarp "}}, {u"$what", {server_command_what, nullptr, u"Usage:\nwhat"}}, + {u"$drop", {server_command_drop, nullptr, u"Usage:\nToggles drops"}}, }); struct SplitCommand { diff --git a/src/ReceiveSubcommands.cc b/src/ReceiveSubcommands.cc index 8b146664..7a510f2d 100644 --- a/src/ReceiveSubcommands.cc +++ b/src/ReceiveSubcommands.cc @@ -953,6 +953,7 @@ static void on_sort_inventory_bb(shared_ptr, // EXP/Drop Item commands static bool drop_item( + std::shared_ptrs, std::shared_ptr l, int64_t enemy_id, uint8_t area, @@ -988,7 +989,7 @@ static bool drop_item( return true; } -static void on_enemy_drop_item_request(shared_ptr, +static void on_enemy_drop_item_request(shared_ptrs, shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, const string& data) { if (!l->is_game()) { @@ -998,12 +999,12 @@ static void on_enemy_drop_item_request(shared_ptr, const auto& cmd = check_size_sc(data, sizeof(G_EnemyDropItemRequest_DC_6x60), sizeof(G_EnemyDropItemRequest_PC_V3_BB_6x60)); - if (!drop_item(l, cmd.enemy_id, cmd.area, cmd.x, cmd.z, cmd.enemy_id)) { + if (!drop_item(s, l, cmd.enemy_id, cmd.area, cmd.x, cmd.z, cmd.enemy_id)) { forward_subcommand(l, c, command, flag, data); } } -static void on_box_drop_item_request(shared_ptr, +static void on_box_drop_item_request(shared_ptrs, shared_ptr l, shared_ptr c, uint8_t command, uint8_t flag, const string& data) { if (!l->is_game()) { @@ -1011,7 +1012,7 @@ static void on_box_drop_item_request(shared_ptr, } const auto& cmd = check_size_sc(data); - if (!drop_item(l, -1, cmd.area, cmd.x, cmd.z, cmd.request_id)) { + if (!drop_item(s, l, -1, cmd.area, cmd.x, cmd.z, cmd.request_id)) { forward_subcommand(l, c, command, flag, data); } } diff --git a/src/ServerState.cc b/src/ServerState.cc index 4a5e7925..6c134564 100644 --- a/src/ServerState.cc +++ b/src/ServerState.cc @@ -23,6 +23,7 @@ ServerState::ServerState(const char* config_filename, bool is_replay) allow_unregistered_users(false), allow_saving(true), item_tracking_enabled(true), + drops_enabled(true), episode_3_send_function_call_enabled(false), enable_dol_compression(false), catch_handler_exceptions(true), @@ -649,6 +650,13 @@ void ServerState::parse_config(shared_ptr config_json) { this->item_tracking_enabled = true; } + try { + this->drops_enabled = d.at("EnableDrops")->as_bool(); + } + catch (const out_of_range&) { + this->drops_enabled = true; + } + try { this->episode_3_send_function_call_enabled = d.at("EnableEpisode3SendFunctionCall")->as_bool(); } catch (const out_of_range&) { diff --git a/src/ServerState.hh b/src/ServerState.hh index aa3b5ea9..228f7a00 100644 --- a/src/ServerState.hh +++ b/src/ServerState.hh @@ -54,6 +54,7 @@ struct ServerState { bool allow_unregistered_users; bool allow_saving; bool item_tracking_enabled; + bool drops_enabled; bool episode_3_send_function_call_enabled; bool enable_dol_compression; bool catch_handler_exceptions; diff --git a/system/config.example.json b/system/config.example.json index f5c04644..2846cad4 100644 --- a/system/config.example.json +++ b/system/config.example.json @@ -361,6 +361,9 @@ // be turned off here. This option has no effect on Blue Burst games - item // tracking is always enabled for them. "EnableItemTracking": true, + + // Disable/Enable drops. + "EnableDrops": true, // Whether to enable certain exception handling. Disabling this causes // newserv to abort when any client causes an exception, which is generally