From 51197c5348cfddeb966342b58c20637dfa268532 Mon Sep 17 00:00:00 2001 From: otavepto Date: Mon, 1 Apr 2024 02:36:40 +0200 Subject: [PATCH] allow user_stats to send data immediately via config file --- dll/dll/settings.h | 2 +- dll/steam_user_stats.cpp | 17 ++++++++++++++--- post_build/README.release.md | 5 ++--- .../immediate_gameserver_stats.EXAMPLE.txt | 2 +- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/dll/dll/settings.h b/dll/dll/settings.h index 0a5402d9..4b4d1e48 100644 --- a/dll/dll/settings.h +++ b/dll/dll/settings.h @@ -252,7 +252,7 @@ public: // don't share stats and achievements with the game server bool disable_sharing_stats_with_gameserver = false; - // send user stats/achievements as soon as possible instead of caching them + // synchronize user stats/achievements with game servers as soon as possible instead of caching them. bool immediate_gameserver_stats = false; //overlay diff --git a/dll/steam_user_stats.cpp b/dll/steam_user_stats.cpp index b226cedb..9ccb1acd 100644 --- a/dll/steam_user_stats.cpp +++ b/dll/steam_user_stats.cpp @@ -337,7 +337,7 @@ Steam_User_Stats::InternalSetResult Steam_User_Stats::set_stat_internal( Steam_User_Stats::InternalSetResult result{}; if (!pchName) return result; - std::string stat_name = common_helpers::ascii_to_lowercase(pchName); + std::string stat_name(common_helpers::ascii_to_lowercase(pchName)); const auto &stats_config = settings->getStats(); auto stats_data = stats_config.find(stat_name); @@ -381,7 +381,7 @@ Steam_User_Stats::InternalSetResult> result{}; if (!pchName) return result; - std::string stat_name = common_helpers::ascii_to_lowercase(pchName); + std::string stat_name(common_helpers::ascii_to_lowercase(pchName)); const auto &stats_config = settings->getStats(); auto stats_data = stats_config.find(stat_name); @@ -426,7 +426,7 @@ Steam_User_Stats::InternalSetResult> result{}; if (!pchName) return result; - std::string stat_name = common_helpers::ascii_to_lowercase(pchName); + std::string stat_name(common_helpers::ascii_to_lowercase(pchName)); const auto &stats_config = settings->getStats(); auto stats_data = stats_config.find(stat_name); @@ -758,6 +758,8 @@ bool Steam_User_Stats::SetStat( const char *pchName, int32 nData ) auto &new_stat = (*pending_server_updates.mutable_user_stats())[ret.internal_name]; new_stat.set_stat_type(GameServerStats_Messages::StatInfo::STAT_TYPE_INT); new_stat.set_value_int(ret.current_val); + + if (settings->immediate_gameserver_stats) send_updated_stats(); } return ret.success; @@ -773,6 +775,8 @@ bool Steam_User_Stats::SetStat( const char *pchName, float fData ) auto &new_stat = (*pending_server_updates.mutable_user_stats())[ret.internal_name]; new_stat.set_stat_type(ret.current_val.first); new_stat.set_value_float(ret.current_val.second); + + if (settings->immediate_gameserver_stats) send_updated_stats(); } return ret.success; @@ -788,6 +792,8 @@ bool Steam_User_Stats::UpdateAvgRateStat( const char *pchName, float flCountThis auto &new_stat = (*pending_server_updates.mutable_user_stats())[ret.internal_name]; new_stat.set_stat_type(ret.current_val.first); new_stat.set_value_float(ret.current_val.second); + + if (settings->immediate_gameserver_stats) send_updated_stats(); } return ret.success; @@ -833,6 +839,8 @@ bool Steam_User_Stats::SetAchievement( const char *pchName ) if (ret.success && ret.notify_server) { auto &new_ach = (*pending_server_updates.mutable_user_achievements())[ret.internal_name]; new_ach.set_achieved(ret.current_val); + + if (settings->immediate_gameserver_stats) send_updated_stats(); } return ret.success; @@ -847,6 +855,8 @@ bool Steam_User_Stats::ClearAchievement( const char *pchName ) if (ret.success && ret.notify_server) { auto &new_ach = (*pending_server_updates.mutable_user_achievements())[ret.internal_name]; new_ach.set_achieved(ret.current_val); + + if (settings->immediate_gameserver_stats) send_updated_stats(); } return ret.success; @@ -894,6 +904,7 @@ bool Steam_User_Stats::GetAchievementAndUnlockTime( const char *pchName, bool *p // The stats should be re-iterated to keep in sync. bool Steam_User_Stats::StoreStats() { + // no need to exchange data with gameserver, we already do that in run_callback() and on each stat/ach update (immediate mode) PRINT_DEBUG("Steam_User_Stats::StoreStats\n"); std::lock_guard lock(global_mutex); diff --git a/post_build/README.release.md b/post_build/README.release.md index 653014ce..606bd5d2 100644 --- a/post_build/README.release.md +++ b/post_build/README.release.md @@ -556,9 +556,8 @@ Check the example file in the `steam_settings` folder By default the emu will mutually share stats with game servers, you can disable this behavior by adding the config file `disable_sharing_stats_with_gameserver.txt` inside your `steam_settings` folder, this also disables the interface `ISteamGameServerStats`. -Game servers will not immediately send user stats/achievements whey they're changed, -they'll wait for the next call to `Steam_RunCallbacks()`. -You can make the server eager to send its updated data by creating the config file `immediate_gameserver_stats.txt` inside your `steam_settings` folder. +Game servers and players will not immediately synchronize stats/achievements whey they're changed, they'll wait for the next call to `Steam_RunCallbacks()`. +You can change this behavior and make them eager to send updated data by creating the config file `immediate_gameserver_stats.txt` inside your `steam_settings` folder. Check the example files in the `steam_settings` folder diff --git a/post_build/steam_settings.EXAMPLE/immediate_gameserver_stats.EXAMPLE.txt b/post_build/steam_settings.EXAMPLE/immediate_gameserver_stats.EXAMPLE.txt index 61517b14..7fcef469 100644 --- a/post_build/steam_settings.EXAMPLE/immediate_gameserver_stats.EXAMPLE.txt +++ b/post_build/steam_settings.EXAMPLE/immediate_gameserver_stats.EXAMPLE.txt @@ -1 +1 @@ -Rename this file to immediate_gameserver_stats.txt to make the gameserver send user stats/achievements as soon as possible instead of caching them. \ No newline at end of file +Rename this file to: immediate_gameserver_stats.txt to synchronize user stats/achievements with game servers as soon as possible instead of caching them. \ No newline at end of file