Add a way to disable all the networking functionality in the emulator.

merge-requests/23/merge
Mr_Goldberg 2019-10-05 15:39:50 -04:00
parent 787cac47db
commit bd921b0939
No known key found for this signature in database
GPG Key ID: 8597D87419DEF278
6 changed files with 27 additions and 4 deletions

View File

@ -60,6 +60,10 @@ The steam appid can also be set using the SteamAppId or SteamGameId env variable
Offline mode: 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. 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: 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 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. If the custom ips/domains are specific for one game only you can put the custom_broadcasts.txt in the steam_settings\ folder.

View File

@ -706,18 +706,26 @@ bool Networking::handle_low_level_udp(Common_Message *msg, IP_PORT ip_port)
#define NUM_TCP_WAITING 128 #define NUM_TCP_WAITING 128
Networking::Networking(CSteamID id, uint32 appid, uint16 port, std::set<uint32_t> *custom_broadcasts) Networking::Networking(CSteamID id, uint32 appid, uint16 port, std::set<uint32_t> *custom_broadcasts, bool disable_sockets)
{ {
run_at_startup();
tcp_port = udp_port = port; tcp_port = udp_port = port;
own_ip = 0x7F000001; own_ip = 0x7F000001;
alive = true; alive = true;
last_run = std::chrono::high_resolution_clock::now(); last_run = std::chrono::high_resolution_clock::now();
this->appid = appid; this->appid = appid;
if (disable_sockets) {
enabled = false;
udp_socket = -1;
tcp_socket = -1;
return;
}
if (custom_broadcasts) { if (custom_broadcasts) {
std::transform(custom_broadcasts->begin(), custom_broadcasts->end(), std::back_inserter(this->custom_broadcasts), [](uint32 ip) {return htonl(ip);}); 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); sock_t sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
PRINT_DEBUG("UDP socket: %u\n", sock); PRINT_DEBUG("UDP socket: %u\n", sock);
if (is_socket_valid(sock) && set_socket_nonblocking(sock)) { if (is_socket_valid(sock) && set_socket_nonblocking(sock)) {
@ -1054,6 +1062,7 @@ void Networking::Run()
void Networking::addListenId(CSteamID id) void Networking::addListenId(CSteamID id)
{ {
if (!enabled) return;
auto i = std::find(ids.begin(), ids.end(), id); auto i = std::find(ids.begin(), ids.end(), id);
if (i != ids.end()) { if (i != ids.end()) {
return; 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) bool Networking::sendTo(Common_Message *msg, bool reliable, Connection *conn)
{ {
if (!enabled) return false;
bool ret = false; bool ret = false;
CSteamID dest_id((uint64)msg->dest_id()); CSteamID dest_id((uint64)msg->dest_id());
if (std::find(ids.begin(), ids.end(), dest_id) != ids.end()) { if (std::find(ids.begin(), ids.end(), dest_id) != ids.end()) {

View File

@ -124,7 +124,7 @@ public:
//NOTE: for all functions ips/ports are passed/returned in host byte order //NOTE: for all functions ips/ports are passed/returned in host byte order
//ex: 127.0.0.1 should be passed as 0x7F000001 //ex: 127.0.0.1 should be passed as 0x7F000001
static std::set<uint32> resolve_ip(std::string dns); static std::set<uint32> resolve_ip(std::string dns);
Networking(CSteamID id, uint32 appid, uint16 port, std::set<uint32_t> *custom_broadcasts); Networking(CSteamID id, uint32 appid, uint16 port, std::set<uint32_t> *custom_broadcasts, bool disable_sockets);
void addListenId(CSteamID id); void addListenId(CSteamID id);
void setAppID(uint32 appid); void setAppID(uint32 appid);
void Run(); void Run();

View File

@ -135,6 +135,9 @@ public:
//controller //controller
struct Controller_Settings controller_settings; struct Controller_Settings controller_settings;
//networking
bool disable_networking = false;
}; };
#endif #endif

View File

@ -247,6 +247,7 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s
} }
bool steam_offline_mode = false; bool steam_offline_mode = false;
bool disable_networking = false;
{ {
std::string steam_settings_path = Local_Storage::get_game_settings_path(); 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()); PRINT_DEBUG("steam settings path %s\n", p.c_str());
if (p == "offline.txt") { if (p == "offline.txt") {
steam_offline_mode = true; 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_server->set_port(port);
settings_client->custom_broadcasts = custom_broadcasts; settings_client->custom_broadcasts = custom_broadcasts;
settings_server->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"; std::string dlc_config_path = Local_Storage::get_game_settings_path() + "DLC.txt";

View File

@ -45,7 +45,7 @@ Steam_Client::Steam_Client()
uint32 appid = create_localstorage_settings(&settings_client, &settings_server, &local_storage); 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"); 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_client = new SteamCallResults();
callback_results_server = new SteamCallResults(); callback_results_server = new SteamCallResults();