From cf2f1ef5291c17ffae3ca74373181644a84cc1ec Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Tue, 13 Dec 2022 23:53:06 -0800 Subject: [PATCH] add option to disable save_files globally --- README.md | 1 + src/Main.cc | 6 ++++++ src/ReceiveCommands.cc | 14 ++++++++------ src/ServerState.cc | 5 ++++- src/ServerState.hh | 2 ++ system/config.example.json | 6 ++++++ 6 files changed, 27 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ecea1f6c..e0212e71 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ Current known issues / missing features / things to do: - Code style - The internal menu abstraction is ugly and hard to work with. Rewrite it. - Add default values for all commands (like we use for Episode 3 battle commands). + - Clean up the way proxy session options are passed to the session from the client object (and add user-settable options for e.g. chat filter, which currently doesn't appear in the menu). - Episode 3 bugs - Disconnecting during a match turns you into a COM if there are other humans in the match, even if the match is part of a tournament. This may be incorrect behavior for tournaments. - Disconnecting during a tournament when there are no other humans in the match simply cancels the match (so it can be replayed) instead of forfeiting, which is almost certainly incorrect behavior. (Then again, no one likes losing tournaments to COMs...) diff --git a/src/Main.cc b/src/Main.cc index 70c2e8f9..9e556f6c 100644 --- a/src/Main.cc +++ b/src/Main.cc @@ -154,6 +154,12 @@ void populate_state_from_config(shared_ptr s, s->catch_handler_exceptions = true; } + try { + s->proxy_allow_save_files = d.at("ProxyAllowSaveFiles")->as_bool(); + } catch (const out_of_range&) { + s->proxy_allow_save_files = true; + } + try { s->ep3_behavior_flags = d.at("Episode3BehaviorFlags")->as_int(); } catch (const out_of_range&) { diff --git a/src/ReceiveCommands.cc b/src/ReceiveCommands.cc index e57ea651..de198c78 100644 --- a/src/ReceiveCommands.cc +++ b/src/ReceiveCommands.cc @@ -81,7 +81,7 @@ static const unordered_map proxy_options_menu_descrip }); static vector proxy_options_menu_for_client( - shared_ptr c) { + shared_ptr s, shared_ptr c) { vector ret; // Note: The descriptions are instead in the map above, because this menu is // dynamically created every time it's sent to the client. This is just one @@ -100,8 +100,10 @@ static vector proxy_options_menu_for_client( c->proxy_block_events ? u"Block events ON" : u"Block events OFF", u"", 0); ret.emplace_back(ProxyOptionsMenuItemID::BLOCK_PATCHES, c->proxy_block_function_calls ? u"Block patches ON" : u"Block patches OFF", u"", 0); - ret.emplace_back(ProxyOptionsMenuItemID::SAVE_FILES, - c->proxy_save_files ? u"Save files ON" : u"Save files OFF", u"", 0); + if (s->proxy_allow_save_files) { + ret.emplace_back(ProxyOptionsMenuItemID::SAVE_FILES, + c->proxy_save_files ? u"Save files ON" : u"Save files OFF", u"", 0); + } ret.emplace_back(ProxyOptionsMenuItemID::SUPPRESS_LOGIN, c->proxy_suppress_remote_login ? u"Skip login ON" : u"Skip login OFF", u"", 0); ret.emplace_back(ProxyOptionsMenuItemID::SKIP_CARD, @@ -131,7 +133,7 @@ static void send_client_to_proxy_server(shared_ptr s, shared_ptrinfinite_hp = c->infinite_hp; session->infinite_tp = c->infinite_tp; session->switch_assist = c->switch_assist; - session->save_files = c->proxy_save_files; + session->save_files = s->proxy_allow_save_files && c->proxy_save_files; session->suppress_remote_login = c->proxy_suppress_remote_login; if (c->proxy_block_events) { session->override_lobby_event = 0; @@ -1682,7 +1684,7 @@ static void on_menu_selection(shared_ptr s, shared_ptr c, c->proxy_zero_remote_guild_card = !c->proxy_zero_remote_guild_card; resend_proxy_options_menu: send_menu(c, s->name.c_str(), MenuID::PROXY_OPTIONS, - proxy_options_menu_for_client(c)); + proxy_options_menu_for_client(s, c)); break; default: send_message_box(c, u"Incorrect menu item ID."); @@ -1697,7 +1699,7 @@ static void on_menu_selection(shared_ptr s, shared_ptr c, } else if (item_id == ProxyDestinationsMenuItemID::OPTIONS) { send_menu(c, s->name.c_str(), MenuID::PROXY_OPTIONS, - proxy_options_menu_for_client(c)); + proxy_options_menu_for_client(s, c)); } else { const pair* dest = nullptr; diff --git a/src/ServerState.cc b/src/ServerState.cc index 67af79d0..21462d43 100644 --- a/src/ServerState.cc +++ b/src/ServerState.cc @@ -31,7 +31,10 @@ ServerState::ServerState() ep3_card_auction_max_size(0), next_lobby_id(1), pre_lobby_event(0), - ep3_menu_song(-1) { + ep3_menu_song(-1), + local_address(0), + external_address(0), + proxy_allow_save_files(true) { vector> non_v1_only_lobbies; vector> ep3_only_lobbies; diff --git a/src/ServerState.hh b/src/ServerState.hh index f2442dfa..b58a4001 100644 --- a/src/ServerState.hh +++ b/src/ServerState.hh @@ -110,6 +110,8 @@ struct ServerState { uint32_t local_address; uint32_t external_address; + bool proxy_allow_save_files; + std::shared_ptr proxy_server; std::shared_ptr game_server; std::shared_ptr client_options_cache; diff --git a/system/config.example.json b/system/config.example.json index 15f8aa2b..0bf7cfee 100644 --- a/system/config.example.json +++ b/system/config.example.json @@ -123,6 +123,12 @@ // connect to newserv will be proxied to this destination. // "ProxyDestination-BB": "", + // There is a proxy option that allows users to save copies of various game + // files on the server side. If you have external clients connecting to your + // server, you can disable this option to prevent clients from generating + // files on the server side which they will never be able to access. + "ProxyAllowSaveFiles": true, + // By default, the interactive shell runs if stdin is a terminal, and doesn't // run if it's not. This option, if present, overrides that behavior. // "RunInteractiveShell": false,