Skip to content

Commit 364a199

Browse files
SemphrissSemphrisVankata453
authored
Disable the update checker by default and add option to disable networking (#2376)
This avoids some privacy concerns linked to pinging an external server each time the game is open. It also allows the user to decide whether the game should connect to the internet at all. --------- Co-authored-by: Semphris <[email protected]> Co-authored-by: Vankata453 <[email protected]>
1 parent b59bfd0 commit 364a199

11 files changed

+125
-15
lines changed

src/addon/addon_manager.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,10 @@ AddonManager::request_check_online()
276276
{
277277
empty_cache_directory();
278278

279-
TransferStatusPtr status = m_downloader.request_download(m_repository_url, ADDON_INFO_PATH);
279+
// Since then() may be called immediately if networking is disabled,
280+
// hold the status in a separate variable so that `m_transfer_status = {}`
281+
// below doesn't cause this function to return nullptr.
282+
auto status = m_downloader.request_download(m_repository_url, ADDON_INFO_PATH);
280283
status->then(
281284
[this](bool success)
282285
{

src/addon/downloader.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#endif
3434

3535
#include "physfs/util.hpp"
36+
#include "supertux/gameconfig.hpp"
3637
#include "supertux/globals.hpp"
3738
#include "util/file_system.hpp"
3839
#include "util/log.hpp"
@@ -137,6 +138,7 @@ TransferStatusList::update()
137138
void
138139
TransferStatusList::push(TransferStatusPtr status)
139140
{
141+
assert(!status->parent_list);
140142
status->parent_list = this;
141143

142144
m_transfer_statuses.push_back(status);
@@ -421,6 +423,9 @@ Downloader::download(const std::string& url,
421423
size_t (*write_func)(void* ptr, size_t size, size_t nmemb, void* userdata),
422424
void* userdata)
423425
{
426+
if (g_config->disable_network)
427+
throw std::runtime_error("Networking is disabled");
428+
424429
log_info << "Downloading " << url << std::endl;
425430

426431
#ifndef EMSCRIPTEN
@@ -456,6 +461,9 @@ Downloader::download(const std::string& url,
456461
std::string
457462
Downloader::download(const std::string& url)
458463
{
464+
if (g_config->disable_network)
465+
throw std::runtime_error("Networking is disabled");
466+
459467
std::string result;
460468
download(url, my_curl_string_append, &result);
461469
return result;
@@ -464,6 +472,9 @@ Downloader::download(const std::string& url)
464472
void
465473
Downloader::download(const std::string& url, const std::string& filename)
466474
{
475+
if (g_config->disable_network)
476+
throw std::runtime_error("Networking is disabled");
477+
467478
#ifndef EMSCRIPTEN
468479
log_info << "download: " << url << " to " << filename << std::endl;
469480
std::unique_ptr<PHYSFS_file, int(*)(PHYSFS_File*)> fout(PHYSFS_openWrite(filename.c_str()),
@@ -512,6 +523,31 @@ Downloader::abort(TransferId id)
512523
void
513524
Downloader::update()
514525
{
526+
if (g_config->disable_network)
527+
{
528+
// Remove any on-going transfers
529+
for (const auto& transfer_data : m_transfers)
530+
{
531+
TransferStatusPtr status = transfer_data.second->get_status();
532+
status->error_msg = "Networking is disabled";
533+
for (const auto& callback : status->callbacks)
534+
{
535+
try
536+
{
537+
callback(false);
538+
}
539+
catch(const std::exception& err)
540+
{
541+
log_warning << "Illegal exception in Downloader: " << err.what() << std::endl;
542+
}
543+
}
544+
if (status->parent_list)
545+
status->parent_list->on_transfer_complete(status, false);
546+
}
547+
m_transfers.clear();
548+
return;
549+
}
550+
515551
#ifndef EMSCRIPTEN
516552
// Prevent updating a Downloader multiple times in the same frame.
517553
if (m_last_update_time == g_real_time) return;

src/gui/menu_manager.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ MenuManager::draw(DrawingContext& context)
131131
{
132132
if (m_dialog.has_next) // Has next dialog
133133
{
134-
if (m_dialog.next) m_dialog.next->update();
134+
// Removed to fix a crash with changing dialog in initial next dialog update
135+
//if (m_dialog.next) m_dialog.next->update();
135136

136137
if (m_dialog.current && m_dialog.next)
137138
{

src/supertux/gameconfig.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#endif
3636

3737
Config::Config() :
38+
m_initial(true),
3839
profile(1),
3940
fullscreen_size(0, 0),
4041
fullscreen_refresh_rate(0),
@@ -78,11 +79,8 @@ Config::Config() :
7879
confirmation_dialog(false),
7980
pause_on_focusloss(true),
8081
custom_mouse_cursor(true),
81-
#ifdef __EMSCRIPTEN__
8282
do_release_check(false),
83-
#else
84-
do_release_check(true),
85-
#endif
83+
disable_network(true),
8684
custom_title_levels(true),
8785
#ifdef ENABLE_DISCORD
8886
enable_discord(false),
@@ -155,6 +153,7 @@ Config::load()
155153
config_mapping.get("pause_on_focusloss", pause_on_focusloss);
156154
config_mapping.get("custom_mouse_cursor", custom_mouse_cursor);
157155
config_mapping.get("do_release_check", do_release_check);
156+
config_mapping.get("disable_network", disable_network);
158157
config_mapping.get("custom_title_levels", custom_title_levels);
159158

160159
std::optional<ReaderMapping> config_integrations_mapping;
@@ -351,6 +350,7 @@ Config::load()
351350
}
352351

353352
check_values();
353+
m_initial = false;
354354
}
355355

356356
void
@@ -374,6 +374,7 @@ Config::save()
374374
writer.write("pause_on_focusloss", pause_on_focusloss);
375375
writer.write("custom_mouse_cursor", custom_mouse_cursor);
376376
writer.write("do_release_check", do_release_check);
377+
writer.write("disable_network", disable_network);
377378
writer.write("custom_title_levels", custom_title_levels);
378379

379380
writer.start_list("integrations");

src/supertux/gameconfig.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class Config final
3636

3737
void check_values();
3838

39+
bool is_initial() const { return m_initial; }
40+
41+
private:
42+
bool m_initial;
43+
3944
public:
4045
int profile;
4146

@@ -108,6 +113,7 @@ class Config final
108113
bool pause_on_focusloss;
109114
bool custom_mouse_cursor;
110115
bool do_release_check;
116+
bool disable_network;
111117
bool custom_title_levels;
112118

113119
#ifdef ENABLE_DISCORD

src/supertux/main.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,9 @@ Main::run(int argc, char** argv)
771771
void
772772
Main::release_check()
773773
{
774+
if (g_config->disable_network)
775+
return;
776+
774777
// Detect a potential new release of SuperTux. If a release, other than
775778
// the current one is indicated on the given web file, show a notification on the main menu screen.
776779
const std::string target_file = "ver_info.nfo";

src/supertux/menu/addon_menu.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "gui/dialog.hpp"
2424
#include "gui/menu_item.hpp"
2525
#include "gui/menu_manager.hpp"
26+
#include "supertux/gameconfig.hpp"
27+
#include "supertux/globals.hpp"
2628
#include "supertux/menu/addon_browse_menu.hpp"
2729
#include "supertux/menu/addon_file_install_menu.hpp"
2830
#include "supertux/menu/addon_preview_menu.hpp"
@@ -169,7 +171,10 @@ AddonMenu::menu_action(MenuItem& item)
169171
}
170172
else if (index == MNID_BROWSE)
171173
{
172-
MenuManager::instance().push_menu(std::make_unique<AddonBrowseMenu>(m_langpacks_only, false));
174+
if (g_config->disable_network)
175+
Dialog::show_message(_("To browse through the add-on catalog, you must enable networking."));
176+
else
177+
MenuManager::instance().push_menu(std::make_unique<AddonBrowseMenu>(m_langpacks_only, false));
173178
}
174179
else if (index == MNID_INSTALL_FROM_FILE)
175180
{
@@ -202,17 +207,23 @@ AddonMenu::menu_action(MenuItem& item)
202207
void
203208
AddonMenu::check_for_updates()
204209
{
210+
if (g_config->disable_network)
211+
{
212+
Dialog::show_message(_("To check for add-on updates, you must enable networking."));
213+
return;
214+
}
215+
205216
try
206217
{
207218
TransferStatusPtr status = m_addon_manager.request_check_online();
219+
auto dialog = std::make_unique<DownloadDialog>(status, false);
220+
dialog->set_title(_("Checking for updates..."));
221+
MenuManager::instance().set_dialog(std::move(dialog));
208222
status->then([this](bool success)
209223
{
210224
if (success) refresh();
211225
set_active_item(MNID_CHECK_ONLINE);
212226
});
213-
auto dialog = std::make_unique<DownloadDialog>(status, false);
214-
dialog->set_title(_("Checking for updates..."));
215-
MenuManager::instance().set_dialog(std::move(dialog));
216227
}
217228
catch (std::exception& e)
218229
{

src/supertux/menu/addon_preview_menu.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "addon/addon_manager.hpp"
2323
#include "gui/menu_item.hpp"
2424
#include "gui/menu_manager.hpp"
25+
#include "supertux/gameconfig.hpp"
26+
#include "supertux/globals.hpp"
2527
#include "supertux/menu/download_dialog.hpp"
2628
#include "supertux/resources.hpp"
2729
#include "util/log.hpp"
@@ -147,6 +149,10 @@ AddonPreviewMenu::rebuild_menu()
147149
add_inactive(_("Failed to load all available screenshot previews."));
148150
}
149151
}
152+
else if (g_config->disable_network)
153+
{
154+
add_inactive(_("To fetch add-on screenshots, you must enable networking."));
155+
}
150156
else
151157
{
152158
const std::string show_screenshots_text = _("Show screenshots");

src/supertux/menu/main_menu.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "gui/menu_item.hpp"
2323
#include "gui/menu_manager.hpp"
2424
#include "supertux/fadetoblack.hpp"
25+
#include "supertux/gameconfig.hpp"
2526
#include "supertux/globals.hpp"
2627
#include "supertux/level.hpp"
2728
#include "supertux/level_parser.hpp"
@@ -68,6 +69,24 @@ MainMenu::MainMenu()
6869
#endif
6970

7071
on_window_resize();
72+
73+
#ifndef __EMSCRIPTEN__
74+
// Show network-related confirmation dialogs on first startup
75+
if (g_config->is_initial())
76+
{
77+
Dialog::show_confirmation(_("Would you allow SuperTux to connect to the Internet?\n\nThis enables additional features, such as the in-game add-on catalog."),
78+
[]()
79+
{
80+
g_config->disable_network = false;
81+
82+
Dialog::show_confirmation(_("Would you allow SuperTux to check for new releases on startup?\n\nYou will be notified if any are found."),
83+
[]()
84+
{
85+
g_config->do_release_check = true;
86+
});
87+
}, true);
88+
}
89+
#endif
7190
}
7291

7392
void

src/supertux/menu/options_menu.cpp

+24-5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ OptionsMenu::less_than_volume(const std::string& lhs, const std::string& rhs)
5656
}
5757

5858
OptionsMenu::OptionsMenu(Type type, bool complete) :
59+
m_type(type),
60+
m_complete(complete),
5961
m_magnifications(),
6062
m_aspect_ratios(),
6163
m_window_resolutions(),
@@ -66,13 +68,21 @@ OptionsMenu::OptionsMenu(Type type, bool complete) :
6668
m_flash_intensity_values(),
6769
m_mobile_control_scales()
6870
{
69-
switch (type) // Insert label and menu items, appropriate for the chosen OptionsMenu type
71+
refresh();
72+
}
73+
74+
void
75+
OptionsMenu::refresh()
76+
{
77+
clear();
78+
79+
switch (m_type) // Insert label and menu items, appropriate for the chosen OptionsMenu type
7080
{
7181
case LOCALE: /** LOCALE */
7282
{
7383
insert_label(_("Locale"));
7484

75-
if (complete)
85+
if (m_complete)
7686
{
7787
add_submenu(_("Select Language"), MenuStorage::LANGUAGE_MENU)
7888
.set_help(_("Select a different language to display text in"));
@@ -174,7 +184,7 @@ OptionsMenu::OptionsMenu(Type type, bool complete) :
174184
{
175185
insert_label(_("Extras"));
176186

177-
if (complete)
187+
if (m_complete)
178188
add_submenu(_("Select Profile"), MenuStorage::PROFILE_MENU)
179189
.set_help(_("Select a profile to play with"));
180190

@@ -219,8 +229,12 @@ OptionsMenu::OptionsMenu(Type type, bool complete) :
219229
add_toggle(MNID_CUSTOM_CURSOR, _("Use custom mouse cursor"), &g_config->custom_mouse_cursor).set_help(_("Whether the game renders its own cursor or uses the system's cursor"));
220230

221231
#ifndef __EMSCRIPTEN__
222-
add_toggle(MNID_RELEASE_CHECK, _("Check for new releases"), &g_config->do_release_check)
223-
.set_help(_("Allows the game to perform checks for new SuperTux releases on startup and notify if any found."));
232+
if (!g_config->disable_network)
233+
add_toggle(MNID_RELEASE_CHECK, _("Check for new releases"), &g_config->do_release_check)
234+
.set_help(_("Allows the game to perform checks for new SuperTux releases on startup and notify if any found."));
235+
236+
add_toggle(MNID_DISABLE_NETWORK, _("Disable network"), &g_config->disable_network)
237+
.set_help(_("Prevents the game from connecting online"));
224238
#endif
225239

226240
break;
@@ -767,6 +781,11 @@ OptionsMenu::menu_action(MenuItem& item)
767781
g_config->m_mobile_controls_scale /= 100.0f;
768782
break;
769783

784+
case MNID_DISABLE_NETWORK:
785+
refresh();
786+
set_active_item(MNID_DISABLE_NETWORK);
787+
break;
788+
770789
default:
771790
break;
772791
}

src/supertux/menu/options_menu.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class OptionsMenu final : public Menu
3939
OptionsMenu(Type type, bool complete);
4040
~OptionsMenu() override;
4141

42+
void refresh() override;
4243
void on_window_resize() override;
4344

4445
void menu_action(MenuItem& item) override;
@@ -81,6 +82,7 @@ class OptionsMenu final : public Menu
8182
MNID_PAUSE_ON_FOCUSLOSS,
8283
MNID_CUSTOM_CURSOR,
8384
MNID_RELEASE_CHECK,
85+
MNID_DISABLE_NETWORK,
8486
MNID_MOBILE_CONTROLS,
8587
MNID_MOBILE_CONTROLS_SCALE
8688
};
@@ -92,6 +94,9 @@ class OptionsMenu final : public Menu
9294
};
9395

9496
private:
97+
const Type m_type;
98+
const bool m_complete;
99+
95100
StringOption m_magnifications;
96101
StringOption m_aspect_ratios;
97102
StringOption m_window_resolutions;

0 commit comments

Comments
 (0)