From bd921b09398273050f957a13e4c40a4b5fbc3933 Mon Sep 17 00:00:00 2001 From: Mr_Goldberg Date: Sat, 5 Oct 2019 15:39:50 -0400 Subject: [PATCH] Add a way to disable all the networking functionality in the emulator. --- Readme_release.txt | 4 ++++ dll/network.cpp | 15 +++++++++++++-- dll/network.h | 2 +- dll/settings.h | 3 +++ dll/settings_parser.cpp | 5 +++++ dll/steam_client.cpp | 2 +- 6 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Readme_release.txt b/Readme_release.txt index c0d11e0a..a136aeba 100644 --- a/Readme_release.txt +++ b/Readme_release.txt @@ -60,6 +60,10 @@ The steam appid can also be set using the SteamAppId or SteamGameId env variable Offline mode: Some games that connect to online servers might only work if the steam emu behaves like steam is in offline mode. If you need this create a offline.txt file in the steam_settings folder. +Disable networking: +If for some reason you want to disable all the networking functionality of the emu you can create a disable_networking.txt file in the steam_settings folder. This will of course break all the +networking functionality so games that use networking related functionality like lobbies or those that launch a server in the background will not work. + Custom Broadcast ips: If you want to set custom ips (or domains) which the emulator will send broadcast packets to, make a list of them, one on each line in: Goldberg SteamEmu Saves\settings\custom_broadcasts.txt If the custom ips/domains are specific for one game only you can put the custom_broadcasts.txt in the steam_settings\ folder. diff --git a/dll/network.cpp b/dll/network.cpp index 7b2628ab..e726a5c6 100644 --- a/dll/network.cpp +++ b/dll/network.cpp @@ -706,18 +706,26 @@ bool Networking::handle_low_level_udp(Common_Message *msg, IP_PORT ip_port) #define NUM_TCP_WAITING 128 -Networking::Networking(CSteamID id, uint32 appid, uint16 port, std::set *custom_broadcasts) +Networking::Networking(CSteamID id, uint32 appid, uint16 port, std::set *custom_broadcasts, bool disable_sockets) { - run_at_startup(); tcp_port = udp_port = port; own_ip = 0x7F000001; alive = true; last_run = std::chrono::high_resolution_clock::now(); this->appid = appid; + + if (disable_sockets) { + enabled = false; + udp_socket = -1; + tcp_socket = -1; + return; + } + if (custom_broadcasts) { std::transform(custom_broadcasts->begin(), custom_broadcasts->end(), std::back_inserter(this->custom_broadcasts), [](uint32 ip) {return htonl(ip);}); } + run_at_startup(); sock_t sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); PRINT_DEBUG("UDP socket: %u\n", sock); if (is_socket_valid(sock) && set_socket_nonblocking(sock)) { @@ -1054,6 +1062,7 @@ void Networking::Run() void Networking::addListenId(CSteamID id) { + if (!enabled) return; auto i = std::find(ids.begin(), ids.end(), id); if (i != ids.end()) { return; @@ -1087,6 +1096,8 @@ bool Networking::sendToIPPort(Common_Message *msg, uint32 ip, uint16 port, bool bool Networking::sendTo(Common_Message *msg, bool reliable, Connection *conn) { + if (!enabled) return false; + bool ret = false; CSteamID dest_id((uint64)msg->dest_id()); if (std::find(ids.begin(), ids.end(), dest_id) != ids.end()) { diff --git a/dll/network.h b/dll/network.h index bc0ce910..1a8c064b 100644 --- a/dll/network.h +++ b/dll/network.h @@ -124,7 +124,7 @@ public: //NOTE: for all functions ips/ports are passed/returned in host byte order //ex: 127.0.0.1 should be passed as 0x7F000001 static std::set resolve_ip(std::string dns); - Networking(CSteamID id, uint32 appid, uint16 port, std::set *custom_broadcasts); + Networking(CSteamID id, uint32 appid, uint16 port, std::set *custom_broadcasts, bool disable_sockets); void addListenId(CSteamID id); void setAppID(uint32 appid); void Run(); diff --git a/dll/settings.h b/dll/settings.h index a5efb5b7..cfb06b09 100644 --- a/dll/settings.h +++ b/dll/settings.h @@ -135,6 +135,9 @@ public: //controller struct Controller_Settings controller_settings; + + //networking + bool disable_networking = false; }; #endif diff --git a/dll/settings_parser.cpp b/dll/settings_parser.cpp index 42849d36..ca12e854 100644 --- a/dll/settings_parser.cpp +++ b/dll/settings_parser.cpp @@ -247,6 +247,7 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s } bool steam_offline_mode = false; + bool disable_networking = false; { std::string steam_settings_path = Local_Storage::get_game_settings_path(); @@ -255,6 +256,8 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s PRINT_DEBUG("steam settings path %s\n", p.c_str()); if (p == "offline.txt") { steam_offline_mode = true; + } else if (p == "disable_networking.txt") { + disable_networking = true; } } } @@ -265,6 +268,8 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s settings_server->set_port(port); settings_client->custom_broadcasts = custom_broadcasts; settings_server->custom_broadcasts = custom_broadcasts; + settings_client->disable_networking = disable_networking; + settings_server->disable_networking = disable_networking; { std::string dlc_config_path = Local_Storage::get_game_settings_path() + "DLC.txt"; diff --git a/dll/steam_client.cpp b/dll/steam_client.cpp index d81f90c0..f7b5fe77 100644 --- a/dll/steam_client.cpp +++ b/dll/steam_client.cpp @@ -45,7 +45,7 @@ Steam_Client::Steam_Client() uint32 appid = create_localstorage_settings(&settings_client, &settings_server, &local_storage); std::string items_db_file_path = (Local_Storage::get_game_settings_path() + "items.json"); - network = new Networking(settings_server->get_local_steam_id(), appid, settings_server->get_port(), &(settings_server->custom_broadcasts)); + network = new Networking(settings_server->get_local_steam_id(), appid, settings_server->get_port(), &(settings_server->custom_broadcasts), settings_server->disable_networking); callback_results_client = new SteamCallResults(); callback_results_server = new SteamCallResults();