allow user_stats to send data immediately via config file

This commit is contained in:
otavepto 2024-04-01 02:36:40 +02:00 committed by otavepto
parent 0ed6dc6808
commit 51197c5348
4 changed files with 18 additions and 8 deletions

View File

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

View File

@ -337,7 +337,7 @@ Steam_User_Stats::InternalSetResult<int32> Steam_User_Stats::set_stat_internal(
Steam_User_Stats::InternalSetResult<int32> 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<std::pair<GameServerStats_Messages::StatInfo
Steam_User_Stats::InternalSetResult<std::pair<GameServerStats_Messages::StatInfo::Stat_Type, float>> 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<std::pair<GameServerStats_Messages::StatInfo
Steam_User_Stats::InternalSetResult<std::pair<GameServerStats_Messages::StatInfo::Stat_Type, float>> 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<std::recursive_mutex> lock(global_mutex);

View File

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

View File

@ -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.
Rename this file to: immediate_gameserver_stats.txt to synchronize user stats/achievements with game servers as soon as possible instead of caching them.