mirror of
https://github.com/Detanup01/gbe_fork.git
synced 2024-12-26 02:14:15 +08:00
* missing delete for ubc_bridge in steam_client
* Steam_UserStats: use const ref when getting the stats list/map * Steam_UserStats: don't fail in `GetStat()`/`GetAchievement()` if output buffer is null * change datatype for default int stat, should be signed * some logging & comments
This commit is contained in:
parent
2427ee12fd
commit
75bb4ff03d
@ -88,7 +88,7 @@ struct Stat_config {
|
||||
enum Stat_Type type;
|
||||
union {
|
||||
float default_value_float;
|
||||
uint32 default_value_int;
|
||||
int32 default_value_int;
|
||||
};
|
||||
};
|
||||
|
||||
@ -244,7 +244,7 @@ public:
|
||||
std::set<IP_PORT> custom_broadcasts;
|
||||
|
||||
//stats
|
||||
std::map<std::string, Stat_config> getStats() { return stats; }
|
||||
const std::map<std::string, Stat_config>& getStats() { return stats; }
|
||||
void setStatDefiniton(std::string name, struct Stat_config stat_config) {stats[common_helpers::ascii_to_lowercase(name)] = stat_config; }
|
||||
// bypass to make SetAchievement() always return true, prevent some games from breaking
|
||||
bool achievement_bypass = false;
|
||||
|
@ -104,13 +104,17 @@ unsigned int find_leaderboard(std::string name)
|
||||
|
||||
nlohmann::detail::iter_impl<nlohmann::json> defined_achievements_find(const std::string &key)
|
||||
{
|
||||
return std::find_if(defined_achievements.begin(), defined_achievements.end(), [&key](nlohmann::json& item) {
|
||||
std::string name = static_cast<const std::string &>( item.value("name", std::string()) );
|
||||
return key.size() == name.size() && std::equal(
|
||||
name.begin(), name.end(), key.begin(),
|
||||
[](char a, char b) { return std::tolower(a) == std::tolower(b); }
|
||||
);
|
||||
});
|
||||
return std::find_if(
|
||||
defined_achievements.begin(), defined_achievements.end(),
|
||||
[&key](const nlohmann::json& item) {
|
||||
const std::string &name = static_cast<const std::string &>( item.value("name", std::string()) );
|
||||
return key.size() == name.size() &&
|
||||
std::equal(
|
||||
name.begin(), name.end(), key.begin(),
|
||||
[](char a, char b) { return std::tolower(a) == std::tolower(b); }
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void load_achievements_db()
|
||||
@ -298,17 +302,17 @@ bool GetStat( const char *pchName, int32 *pData )
|
||||
PRINT_DEBUG("Steam_User_Stats::GetStat <int32> '%s' %p\n", pchName, pData);
|
||||
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
||||
|
||||
if (!pchName || !pData) return false;
|
||||
if (!pchName) return false;
|
||||
std::string stat_name = common_helpers::ascii_to_lowercase(pchName);
|
||||
|
||||
auto stats_config = settings->getStats();
|
||||
const auto &stats_config = settings->getStats();
|
||||
auto stats_data = stats_config.find(stat_name);
|
||||
if (stats_config.end() == stats_data) return false;
|
||||
if (stats_data->second.type != Stat_Type::STAT_TYPE_INT) return false;
|
||||
|
||||
auto cached_stat = stats_cache_int.find(stat_name);
|
||||
if (cached_stat != stats_cache_int.end()) {
|
||||
*pData = cached_stat->second;
|
||||
if (pData) *pData = cached_stat->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -316,12 +320,12 @@ bool GetStat( const char *pchName, int32 *pData )
|
||||
int read_data = local_storage->get_data(Local_Storage::stats_storage_folder, stat_name, (char* )&output, sizeof(output));
|
||||
if (read_data == sizeof(int32)) {
|
||||
stats_cache_int[stat_name] = output;
|
||||
*pData = output;
|
||||
if (pData) *pData = output;
|
||||
return true;
|
||||
}
|
||||
|
||||
stats_cache_int[stat_name] = stats_data->second.default_value_int;
|
||||
*pData = stats_data->second.default_value_int;
|
||||
if (pData) *pData = stats_data->second.default_value_int;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -330,17 +334,17 @@ bool GetStat( const char *pchName, float *pData )
|
||||
PRINT_DEBUG("Steam_User_Stats::GetStat <float> '%s' %p\n", pchName, pData);
|
||||
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
||||
|
||||
if (!pchName || !pData) return false;
|
||||
if (!pchName) return false;
|
||||
std::string stat_name = common_helpers::ascii_to_lowercase(pchName);
|
||||
|
||||
auto stats_config = settings->getStats();
|
||||
const auto &stats_config = settings->getStats();
|
||||
auto stats_data = stats_config.find(stat_name);
|
||||
if (stats_config.end() == stats_data) return false;
|
||||
if (stats_data->second.type == Stat_Type::STAT_TYPE_INT) return false;
|
||||
|
||||
auto cached_stat = stats_cache_float.find(stat_name);
|
||||
if (cached_stat != stats_cache_float.end()) {
|
||||
*pData = cached_stat->second;
|
||||
if (pData) *pData = cached_stat->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -348,12 +352,12 @@ bool GetStat( const char *pchName, float *pData )
|
||||
int read_data = local_storage->get_data(Local_Storage::stats_storage_folder, stat_name, (char* )&output, sizeof(output));
|
||||
if (read_data == sizeof(float)) {
|
||||
stats_cache_float[stat_name] = output;
|
||||
*pData = output;
|
||||
if (pData) *pData = output;
|
||||
return true;
|
||||
}
|
||||
|
||||
stats_cache_float[stat_name] = stats_data->second.default_value_float;
|
||||
*pData = stats_data->second.default_value_float;
|
||||
if (pData) *pData = stats_data->second.default_value_float;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -367,7 +371,7 @@ bool SetStat( const char *pchName, int32 nData )
|
||||
if (!pchName) return false;
|
||||
std::string stat_name = common_helpers::ascii_to_lowercase(pchName);
|
||||
|
||||
auto stats_config = settings->getStats();
|
||||
const auto &stats_config = settings->getStats();
|
||||
auto stats_data = stats_config.find(stat_name);
|
||||
if (stats_config.end() == stats_data) return false;
|
||||
if (stats_data->second.type != Stat_Type::STAT_TYPE_INT) return false;
|
||||
@ -402,7 +406,7 @@ bool SetStat( const char *pchName, float fData )
|
||||
if (!pchName) return false;
|
||||
std::string stat_name = common_helpers::ascii_to_lowercase(pchName);
|
||||
|
||||
auto stats_config = settings->getStats();
|
||||
const auto &stats_config = settings->getStats();
|
||||
auto stats_data = stats_config.find(stat_name);
|
||||
if (stats_config.end() == stats_data) return false;
|
||||
if (stats_data->second.type == Stat_Type::STAT_TYPE_INT) return false;
|
||||
@ -437,7 +441,7 @@ bool UpdateAvgRateStat( const char *pchName, float flCountThisSession, double dS
|
||||
if (!pchName) return false;
|
||||
std::string stat_name = common_helpers::ascii_to_lowercase(pchName);
|
||||
|
||||
auto stats_config = settings->getStats();
|
||||
const auto &stats_config = settings->getStats();
|
||||
auto stats_data = stats_config.find(stat_name);
|
||||
if (stats_config.end() == stats_data) return false;
|
||||
if (stats_data->second.type == Stat_Type::STAT_TYPE_INT) return false;
|
||||
@ -830,7 +834,7 @@ bool GetUserAchievement( CSteamID steamIDUser, const char *pchName, bool *pbAchi
|
||||
PRINT_DEBUG("Steam_User_Stats::GetUserAchievement %s\n", pchName);
|
||||
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
||||
|
||||
if (pchName == nullptr) return false;
|
||||
if (!pchName) return false;
|
||||
|
||||
if (steamIDUser == settings->get_local_steam_id()) {
|
||||
return GetAchievement(pchName, pbAchieved);
|
||||
|
@ -216,8 +216,8 @@ message Steam_Messages {
|
||||
}
|
||||
|
||||
message Common_Message {
|
||||
uint64 source_id = 1;
|
||||
uint64 dest_id = 2;
|
||||
uint64 source_id = 1; // SteamID64 of the sender
|
||||
uint64 dest_id = 2; // SteamID64 of the target receiver
|
||||
oneof messages {
|
||||
Announce announce = 3;
|
||||
Low_Level low_level = 4;
|
||||
|
@ -536,52 +536,52 @@ std::set<IP_PORT> Networking::resolve_ip(std::string dns)
|
||||
void Networking::do_callbacks_message(Common_Message *msg)
|
||||
{
|
||||
if (msg->has_network() || msg->has_network_old()) {
|
||||
PRINT_DEBUG("has_network\n");
|
||||
PRINT_DEBUG("Networking has_network\n");
|
||||
run_callbacks(CALLBACK_ID_NETWORKING, msg);
|
||||
}
|
||||
|
||||
if (msg->has_lobby()) {
|
||||
PRINT_DEBUG("has_lobby\n");
|
||||
PRINT_DEBUG("Networking has_lobby\n");
|
||||
run_callbacks(CALLBACK_ID_LOBBY, msg);
|
||||
}
|
||||
|
||||
if (msg->has_lobby_messages()) {
|
||||
PRINT_DEBUG("has_lobby_messages\n");
|
||||
PRINT_DEBUG("Networking has_lobby_messages\n");
|
||||
run_callbacks(CALLBACK_ID_LOBBY, msg);
|
||||
}
|
||||
|
||||
if (msg->has_gameserver()) {
|
||||
PRINT_DEBUG("has_gameserver\n");
|
||||
PRINT_DEBUG("Networking has_gameserver\n");
|
||||
run_callbacks(CALLBACK_ID_GAMESERVER, msg);
|
||||
}
|
||||
|
||||
if (msg->has_friend_()) {
|
||||
PRINT_DEBUG("has_friend_\n");
|
||||
PRINT_DEBUG("Networking has_friend_\n");
|
||||
run_callbacks(CALLBACK_ID_FRIEND, msg);
|
||||
}
|
||||
|
||||
if (msg->has_auth_ticket()) {
|
||||
PRINT_DEBUG("has_auth_ticket\n");
|
||||
PRINT_DEBUG("Networking has_auth_ticket\n");
|
||||
run_callbacks(CALLBACK_ID_AUTH_TICKET, msg);
|
||||
}
|
||||
|
||||
if (msg->has_friend_messages()) {
|
||||
PRINT_DEBUG("has_friend_messages\n");
|
||||
PRINT_DEBUG("Networking has_friend_messages\n");
|
||||
run_callbacks(CALLBACK_ID_FRIEND_MESSAGES, msg);
|
||||
}
|
||||
|
||||
if (msg->has_networking_sockets()) {
|
||||
PRINT_DEBUG("has_networking_sockets\n");
|
||||
PRINT_DEBUG("Networking has_networking_sockets\n");
|
||||
run_callbacks(CALLBACK_ID_NETWORKING_SOCKETS, msg);
|
||||
}
|
||||
|
||||
if (msg->has_steam_messages()) {
|
||||
PRINT_DEBUG("has_steam_messages\n");
|
||||
PRINT_DEBUG("Networking has_steam_messages\n");
|
||||
run_callbacks(CALLBACK_ID_STEAM_MESSAGES, msg);
|
||||
}
|
||||
|
||||
if (msg->has_networking_messages()) {
|
||||
PRINT_DEBUG("has_networking_messages\n");
|
||||
PRINT_DEBUG("Networking has_networking_messages\n");
|
||||
run_callbacks(CALLBACK_ID_NETWORKING_MESSAGES, msg);
|
||||
}
|
||||
}
|
||||
|
@ -684,7 +684,7 @@ static void parse_stats(class Settings *settings_client, Settings *settings_serv
|
||||
}
|
||||
|
||||
if (stat_name.size()) {
|
||||
PRINT_DEBUG("Adding stat type: %s|%u|%f|%u\n", stat_name.c_str(), config.type, config.default_value_float, config.default_value_int);
|
||||
PRINT_DEBUG("Adding stat type: %s|%u|%f|%i\n", stat_name.c_str(), config.type, config.default_value_float, config.default_value_int);
|
||||
settings_client->setStatDefiniton(stat_name, config);
|
||||
settings_server->setStatDefiniton(stat_name, config);
|
||||
} else {
|
||||
|
@ -50,6 +50,7 @@ static void background_thread(Steam_Client *client)
|
||||
|
||||
Steam_Client::Steam_Client()
|
||||
{
|
||||
PRINT_DEBUG("Steam_Client init start ----------\n");
|
||||
uint32 appid = create_localstorage_settings(&settings_client, &settings_server, &local_storage);
|
||||
local_storage->update_save_filenames(Local_Storage::remote_storage_folder);
|
||||
|
||||
@ -61,12 +62,13 @@ 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 \n", settings_client->get_local_steam_id().ConvertToUint64(), settings_server->get_local_steam_id().ConvertToUint64(), appid, settings_server->get_port());
|
||||
PRINT_DEBUG("Steam_Client init: id: %llu server id: %llu, appid: %u, port: %u\n", settings_client->get_local_steam_id().ConvertToUint64(), settings_server->get_local_steam_id().ConvertToUint64(), appid, settings_server->get_port());
|
||||
|
||||
if (appid) {
|
||||
set_env_variable("SteamAppId", std::to_string(appid));
|
||||
set_env_variable("SteamGameId", std::to_string(appid));
|
||||
set_env_variable("SteamOverlayGameId", std::to_string(appid));
|
||||
auto appid_str = std::to_string(appid);
|
||||
set_env_variable("SteamAppId", appid_str);
|
||||
set_env_variable("SteamGameId", appid_str);
|
||||
set_env_variable("SteamOverlayGameId", appid_str);
|
||||
}
|
||||
|
||||
steam_overlay = new Steam_Overlay(settings_client, callback_results_client, callbacks_client, run_every_runcb, network);
|
||||
@ -120,13 +122,13 @@ Steam_Client::Steam_Client()
|
||||
steam_gameserver_game_coordinator = new Steam_Game_Coordinator(settings_server, network, callback_results_server, callbacks_server, run_every_runcb);
|
||||
steam_masterserver_updater = new Steam_Masterserver_Updater(settings_server, network, callback_results_server, callbacks_server, run_every_runcb);
|
||||
|
||||
PRINT_DEBUG("client init AppTicket\n");
|
||||
PRINT_DEBUG("Steam_Client init AppTicket\n");
|
||||
steam_app_ticket = new Steam_AppTicket(settings_client);
|
||||
|
||||
gameserver_has_ipv6_functions = false;
|
||||
|
||||
last_cb_run = 0;
|
||||
PRINT_DEBUG("client init end\n");
|
||||
PRINT_DEBUG("Steam_Client init end ----------\n");
|
||||
}
|
||||
|
||||
Steam_Client::~Steam_Client()
|
||||
@ -178,6 +180,8 @@ Steam_Client::~Steam_Client()
|
||||
delete steam_user;
|
||||
delete steam_overlay;
|
||||
|
||||
delete ugc_bridge;
|
||||
|
||||
delete run_every_runcb;
|
||||
delete callbacks_server;
|
||||
delete callbacks_client;
|
||||
|
Loading…
x
Reference in New Issue
Block a user