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

This commit is contained in:
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:
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.

View file

@ -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<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;
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()) {

View file

@ -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<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 setAppID(uint32 appid);
void Run();

View file

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

View file

@ -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";

View file

@ -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();