custom broadcasts file can now contain domains.

custom broadcasts can now be put in the steam_settings folder.
merge-requests/6/head
Mr_Goldberg 2019-05-08 15:43:25 -04:00
parent 106d4025bb
commit 147fc50be1
No known key found for this signature in database
GPG Key ID: 8597D87419DEF278
5 changed files with 53 additions and 47 deletions

View File

@ -52,8 +52,9 @@ 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.
Custom Broadcast ips: Custom Broadcast ips:
If you want to set custom ips 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.
An example is provided in steam_settings.EXAMPLE\custom_broadcasts.EXAMPLE.txt
Support for CPY steam_api(64).dll cracks: See the build in the experimental folder. Support for CPY steam_api(64).dll cracks: See the build in the experimental folder.

View File

@ -30,6 +30,7 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <unistd.h> #include <unistd.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <netdb.h>
#endif #endif
#define MAX_BROADCASTS 16 #define MAX_BROADCASTS 16
@ -467,6 +468,26 @@ static void socket_timeouts(struct TCP_Socket &socket, double extra_time)
} }
} }
std::set<uint32> Networking::resolve_ip(std::string dns)
{
std::set<uint32> ips;
struct addrinfo* result;
if (getaddrinfo(dns.c_str(), NULL, NULL, &result) == 0) {
for (struct addrinfo *res = result; res != NULL; res = res->ai_next) {
PRINT_DEBUG("%u %u\n", res->ai_addrlen, res->ai_family);
if (res->ai_family == AF_INET) {
struct sockaddr_in *ipv4 = (struct sockaddr_in *)res->ai_addr;
uint32 ip;
memcpy(&ip, &ipv4->sin_addr, sizeof(ip));
ips.insert(ntohl(ip));
}
}
}
return ips;
}
void Networking::do_callbacks_message(Common_Message *msg) void Networking::do_callbacks_message(Common_Message *msg)
{ {
if (msg->has_network() || msg->has_network_old()) { if (msg->has_network() || msg->has_network_old()) {
@ -682,7 +703,7 @@ 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::vector<uint32_t> *custom_broadcasts) Networking::Networking(CSteamID id, uint32 appid, uint16 port, std::set<uint32_t> *custom_broadcasts)
{ {
run_at_startup(); run_at_startup();
tcp_port = udp_port = port; tcp_port = udp_port = port;
@ -690,8 +711,9 @@ Networking::Networking(CSteamID id, uint32 appid, uint16 port, std::vector<uint3
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 (custom_broadcasts) if (custom_broadcasts) {
this->custom_broadcasts = *custom_broadcasts; std::transform(custom_broadcasts->begin(), custom_broadcasts->end(), std::back_inserter(this->custom_broadcasts), [](uint32 ip) {return htonl(ip);});
}
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);

View File

@ -121,7 +121,10 @@ class Networking {
Common_Message create_announce(bool request); Common_Message create_announce(bool request);
public: public:
Networking(CSteamID id, uint32 appid, uint16 port, std::vector<uint32_t> *custom_broadcasts); //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);
void addListenId(CSteamID id); void addListenId(CSteamID id);
void setAppID(uint32 appid); void setAppID(uint32 appid);
void Run(); void Run();

View File

@ -38,6 +38,19 @@ static void network_thread(Networking *network)
} }
} }
static void load_custom_broadcasts(std::string broadcasts_filepath, std::set<uint32> &custom_broadcasts)
{
std::ifstream broadcasts_file(broadcasts_filepath);
PRINT_DEBUG("Broadcasts file path: %s\n", broadcasts_filepath.c_str());
if (broadcasts_file.is_open()) {
std::string line;
while (std::getline(broadcasts_file, line)) {
std::set<uint32> ips = Networking::resolve_ip(line);
custom_broadcasts.insert(ips.begin(), ips.end());
}
}
}
Steam_Client::Steam_Client() Steam_Client::Steam_Client()
{ {
std::string program_path = Local_Storage::get_program_path(), save_path = Local_Storage::get_user_appdata_path();; std::string program_path = Local_Storage::get_program_path(), save_path = Local_Storage::get_user_appdata_path();;
@ -124,47 +137,9 @@ Steam_Client::Steam_Client()
} }
// Custom broadcasts // Custom broadcasts
std::vector<uint32_t> custom_broadcasts; std::set<uint32> custom_broadcasts;
std::string broadcasts_filepath = local_storage->get_global_settings_path() + "custom_broadcasts.txt"; load_custom_broadcasts(local_storage->get_global_settings_path() + "custom_broadcasts.txt", custom_broadcasts);
load_custom_broadcasts(Local_Storage::get_game_settings_path() + "custom_broadcasts.txt", custom_broadcasts);
std::ifstream broadcasts_file(broadcasts_filepath);
PRINT_DEBUG("Broadcasts file path: %s\n", broadcasts_filepath.c_str());
if (broadcasts_file.is_open()) {
std::string line;
while (std::getline(broadcasts_file, line)) {
int offset = 0;
size_t pos = 0;
std::string tok;
uint32_t current_ip = 0;
while((pos = line.find(".")) != std::string::npos && offset < 32)
{
tok = line.substr(0, pos);
try
{
current_ip += (std::stoi(tok) << offset);
}
catch(std::invalid_argument ex)
{
offset = -1;
break;
}
line.erase(0, pos+1);
offset += 8;
}
if(pos == std::string::npos && offset != -1)
{
try
{
current_ip += (std::stoi(line) << offset);
custom_broadcasts.push_back(current_ip);
}
catch(std::invalid_argument ex)
{
}
}
}
}
// Acount name // Acount name
char name[32] = {}; char name[32] = {};

View File

@ -0,0 +1,5 @@
192.168.3.255
127.8.9.10
192.168.66.99
192.168.7.99
removethis.test.domain.com