Custom broadcasts file is more appropriate in:

Goldberg SteamEmu Saves/settings/custom_broadcasts.txt

Use C++ vector instead of C arrays.
merge-requests/6/head
Mr_Goldberg 2019-05-03 08:50:10 -04:00
parent 3552eed3ec
commit 701eba17e8
No known key found for this signature in database
GPG Key ID: 8597D87419DEF278
7 changed files with 32 additions and 29 deletions

View File

@ -25,8 +25,8 @@ release: CXX_FLAGS += -DNDEBUG -DEMU_RELEASE_BUILD -Ofast
release: LD_FLAGS += -lpthread
release32: CXX_FLAGS += -m32
release32: LD_FLAGS += -m32
debug: CXX_FLAGS += -g3
debug: LD_FLAGS += -lpthread
debug: CXX_FLAGS += -g3 -fsanitize=address
debug: LD_FLAGS += -lasan
release: library
release32: release
debug: library

View File

@ -51,8 +51,13 @@ 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.
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
Support for CPY steam_api(64).dll cracks: See the build in the experimental folder.
Notes:
You must all be on the same LAN for it to work. This is an early work so a lot of games will likely not work.

View File

@ -502,6 +502,11 @@ std::string Local_Storage::get_path(std::string folder)
return path;
}
std::string Local_Storage::get_global_settings_path()
{
return save_directory + SETTINGS_STORAGE_FOLDER + PATH_SEPARATOR;
}
std::vector<std::string> Local_Storage::get_filenames_path(std::string path)
{
if (path.back() != *PATH_SEPARATOR) {
@ -522,7 +527,7 @@ int Local_Storage::store_data(std::string folder, std::string file, char *data,
int Local_Storage::store_data_settings(std::string file, char *data, unsigned int length)
{
return store_file_data(save_directory + SETTINGS_STORAGE_FOLDER, file, data, length);
return store_file_data(get_global_settings_path(), file, data, length);
}
int Local_Storage::get_file_data(std::string full_path, char *data, unsigned int max_length)
@ -554,7 +559,7 @@ int Local_Storage::get_data(std::string folder, std::string file, char *data, un
int Local_Storage::get_data_settings(std::string file, char *data, unsigned int max_length)
{
file = sanitize_file_name(file);
std::string full_path = save_directory + SETTINGS_STORAGE_FOLDER + PATH_SEPARATOR + file;
std::string full_path = get_global_settings_path() + file;
return get_file_data(full_path, data, max_length);
}

View File

@ -54,6 +54,7 @@ public:
unsigned int file_size(std::string folder, std::string file);
bool file_delete(std::string folder, std::string file);
uint64_t file_timestamp(std::string folder, std::string file);
std::string get_global_settings_path();
std::string get_path(std::string folder);
bool update_save_filenames(std::string folder);

View File

@ -280,7 +280,7 @@ static int receive_packet(sock_t sock, IP_PORT *ip_port, char *data, unsigned lo
return -1;
}
static bool send_broadcasts(sock_t sock, uint16 port, char *data, unsigned long length, uint32_t *custom_broadcasts)
static bool send_broadcasts(sock_t sock, uint16 port, char *data, unsigned long length, std::vector<uint32_t> *custom_broadcasts)
{
static std::chrono::high_resolution_clock::time_point last_get_broadcast_info;
if (number_broadcasts < 0 || check_timedout(last_get_broadcast_info, 60.0)) {
@ -311,12 +311,11 @@ static bool send_broadcasts(sock_t sock, uint16 port, char *data, unsigned long
PRINT_DEBUG("start custom broadcasts\n");
IP_PORT custom_targeted_broadcast;
custom_targeted_broadcast.port = port;
for(int i = 0; i < MAX_CUSTOM_BROADCASTS; i++) {
if(custom_broadcasts[i] == 0)
break;
custom_targeted_broadcast.ip = custom_broadcasts[i];
for(auto &ip : *custom_broadcasts) {
custom_targeted_broadcast.ip = ip;
send_packet_to(sock, custom_targeted_broadcast, data, length);
}
PRINT_DEBUG("end custom broadcasts\n");
return true;
@ -683,7 +682,7 @@ 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, uint32_t *custom_broadcasts)
Networking::Networking(CSteamID id, uint32 appid, uint16 port, std::vector<uint32_t> *custom_broadcasts)
{
run_at_startup();
tcp_port = udp_port = port;
@ -691,8 +690,8 @@ Networking::Networking(CSteamID id, uint32 appid, uint16 port, uint32_t *custom_
alive = true;
last_run = std::chrono::high_resolution_clock::now();
this->appid = appid;
for(int i = 0; i < MAX_CUSTOM_BROADCASTS; i++)
this->custom_broadcasts[i] = custom_broadcasts[i];
if (custom_broadcasts)
this->custom_broadcasts = *custom_broadcasts;
sock_t sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
PRINT_DEBUG("UDP socket: %u\n", sock);
@ -802,9 +801,9 @@ void Networking::send_announce_broadcasts()
size_t size = msg.ByteSizeLong();
char *buffer = new char[size];
msg.SerializeToArray(buffer, size);
send_broadcasts(udp_socket, htons(DEFAULT_PORT), buffer, size, this->custom_broadcasts);
send_broadcasts(udp_socket, htons(DEFAULT_PORT), buffer, size, &this->custom_broadcasts);
if (udp_port != DEFAULT_PORT) {
send_broadcasts(udp_socket, htons(udp_port), buffer, size, this->custom_broadcasts);
send_broadcasts(udp_socket, htons(udp_port), buffer, size, &this->custom_broadcasts);
}
delete[] buffer;

View File

@ -20,8 +20,6 @@
#ifndef NETWORK_INCLUDE
#define NETWORK_INCLUDE
#define MAX_CUSTOM_BROADCASTS 128
#include "net.pb.h"
#include <chrono>
@ -108,7 +106,7 @@ class Networking {
std::vector<CSteamID> ids;
uint32 appid;
std::chrono::high_resolution_clock::time_point last_broadcast;
uint32_t custom_broadcasts[MAX_CUSTOM_BROADCASTS];
std::vector<uint32_t> custom_broadcasts;
std::vector<struct TCP_Socket> accepted;
std::recursive_mutex mutex;
@ -123,7 +121,7 @@ class Networking {
Common_Message create_announce(bool request);
public:
Networking(CSteamID id, uint32 appid, uint16 port, uint32_t *custom_broadcasts);
Networking(CSteamID id, uint32 appid, uint16 port, std::vector<uint32_t> *custom_broadcasts);
void addListenId(CSteamID id);
void setAppID(uint32 appid);
void Run();

View File

@ -19,7 +19,6 @@
#include <fstream>
static void network_thread(Networking *network)
{
PRINT_DEBUG("network thread starting\n");
@ -125,17 +124,14 @@ Steam_Client::Steam_Client()
}
// Custom broadcasts
uint32_t custom_broadcasts[MAX_CUSTOM_BROADCASTS] = {0};
int readIP = 0;
std::string broadcasts_filepath = Local_Storage::get_game_settings_path() + "custom_broadcasts.txt";
std::vector<uint32_t> custom_broadcasts;
std::string broadcasts_filepath = local_storage->get_global_settings_path() + "custom_broadcasts.txt";
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) && readIP < MAX_CUSTOM_BROADCASTS) {
while (std::getline(broadcasts_file, line)) {
int offset = 0;
size_t pos = 0;
std::string tok;
@ -160,7 +156,7 @@ Steam_Client::Steam_Client()
try
{
current_ip += (std::stoi(line) << offset);
custom_broadcasts[readIP++] = current_ip;
custom_broadcasts.push_back(current_ip);
}
catch(std::invalid_argument ex)
{
@ -170,7 +166,6 @@ Steam_Client::Steam_Client()
}
}
// Acount name
char name[32] = {};
if (local_storage->get_data_settings("account_name.txt", name, sizeof(name) - 1) <= 0) {
@ -286,7 +281,7 @@ Steam_Client::Steam_Client()
}
}
network = new Networking(settings_server->get_local_steam_id(), appid, port, custom_broadcasts);
network = new Networking(settings_server->get_local_steam_id(), appid, port, &custom_broadcasts);
callback_results_client = new SteamCallResults();
callback_results_server = new SteamCallResults();
@ -294,7 +289,7 @@ Steam_Client::Steam_Client()
callbacks_server = new SteamCallBacks(callback_results_server);
run_every_runcb = new RunEveryRunCB();
PRINT_DEBUG("steam client init: id: %llu server id: %llu appid: %u port: %u custom broadcasts: %u\n", user_id.ConvertToUint64(), settings_server->get_local_steam_id().ConvertToUint64(), appid, port, sizeof(custom_broadcasts));
PRINT_DEBUG("steam client init: id: %llu server id: %llu appid: %u port: %u \n", user_id.ConvertToUint64(), settings_server->get_local_steam_id().ConvertToUint64(), appid, port);
steam_user = new Steam_User(settings_client, local_storage, network, callback_results_client, callbacks_client);
steam_friends = new Steam_Friends(settings_client, network, callback_results_client, callbacks_client, run_every_runcb);