* for gameserver_stats & user_stats: distinguish between stats update requests from server and client, avoiding a scenario where a client would overwrite another client's stats

* fixed linux compilation error
This commit is contained in:
otavepto 2024-03-30 09:03:49 +02:00 committed by otavepto
parent 995a296e59
commit caa9401369
3 changed files with 10 additions and 11 deletions

View File

@ -258,7 +258,8 @@ message GameServerStats_Messages {
Request_AllUserStats = 0; Request_AllUserStats = 0;
Response_AllUserStats = 1; Response_AllUserStats = 1;
UpdateUserStats = 2; // sent by both sides UpdateUserStatsFromServer = 2; // sent by Steam_GameServerStats
UpdateUserStatsFromUser = 3; // sent by Steam_User_Stats
} }
Types type = 1; Types type = 1;

View File

@ -392,7 +392,7 @@ void Steam_GameServerStats::collect_and_send_updated_user_stats()
} }
auto gameserverstats_msg = new GameServerStats_Messages(); auto gameserverstats_msg = new GameServerStats_Messages();
gameserverstats_msg->set_type(GameServerStats_Messages::UpdateUserStats); gameserverstats_msg->set_type(GameServerStats_Messages::UpdateUserStatsFromServer);
gameserverstats_msg->set_allocated_update_user_stats(updated_stats_msg); gameserverstats_msg->set_allocated_update_user_stats(updated_stats_msg);
Common_Message msg{}; Common_Message msg{};
@ -521,7 +521,7 @@ void Steam_GameServerStats::network_callback(Common_Message *msg)
break; break;
// user has updated/new stats // user has updated/new stats
case GameServerStats_Messages::UpdateUserStats: case GameServerStats_Messages::UpdateUserStatsFromUser:
network_callback_updated_stats(msg); network_callback_updated_stats(msg);
break; break;

View File

@ -1641,7 +1641,7 @@ void Steam_User_Stats::send_updated_stats()
pending_server_updates.clear_user_achievements(); pending_server_updates.clear_user_achievements();
auto gameserverstats_msg = new GameServerStats_Messages(); auto gameserverstats_msg = new GameServerStats_Messages();
gameserverstats_msg->set_type(GameServerStats_Messages::UpdateUserStats); gameserverstats_msg->set_type(GameServerStats_Messages::UpdateUserStatsFromUser);
gameserverstats_msg->set_allocated_update_user_stats(new_updates_msg); gameserverstats_msg->set_allocated_update_user_stats(new_updates_msg);
Common_Message msg{}; Common_Message msg{};
@ -1750,8 +1750,6 @@ void Steam_User_Stats::network_stats_updated(Common_Message *msg)
return; return;
} }
uint64 server_steamid = msg->source_id();
auto &new_user_data = msg->gameserver_stats_messages().update_user_stats(); auto &new_user_data = msg->gameserver_stats_messages().update_user_stats();
// update our stats // update our stats
@ -1810,7 +1808,7 @@ void Steam_User_Stats::network_callback_stats(Common_Message *msg)
break; break;
// server has updated/new stats // server has updated/new stats
case GameServerStats_Messages::UpdateUserStats: case GameServerStats_Messages::UpdateUserStatsFromServer:
network_stats_updated(msg); network_stats_updated(msg);
break; break;
@ -1829,7 +1827,7 @@ void Steam_User_Stats::network_leaderboard_update_score(Common_Message *msg, Ste
return; return;
} }
CSteamID sender_steamid(msg->source_id()); CSteamID sender_steamid((uint64)msg->source_id());
PRINT_DEBUG( PRINT_DEBUG(
"Steam_User_Stats::network_leaderboard_update_score got score for user %llu on leaderboard '%s' (send our score back=%i)\n", "Steam_User_Stats::network_leaderboard_update_score got score for user %llu on leaderboard '%s' (send our score back=%i)\n",
(uint64)msg->source_id(), board.name.c_str(), (int)send_score_back (uint64)msg->source_id(), board.name.c_str(), (int)send_score_back
@ -1852,7 +1850,7 @@ void Steam_User_Stats::network_leaderboard_update_score(Common_Message *msg, Ste
// someone is requesting our score on a leaderboard // someone is requesting our score on a leaderboard
void Steam_User_Stats::network_leaderboard_send_my_score(Common_Message *msg, const Steam_Leaderboard &board) void Steam_User_Stats::network_leaderboard_send_my_score(Common_Message *msg, const Steam_Leaderboard &board)
{ {
CSteamID sender_steamid(msg->source_id()); CSteamID sender_steamid((uint64)msg->source_id());
PRINT_DEBUG( PRINT_DEBUG(
"Steam_User_Stats::network_leaderboard_send_my_score user %llu requested our score for leaderboard '%s'\n", "Steam_User_Stats::network_leaderboard_send_my_score user %llu requested our score for leaderboard '%s'\n",
(uint64)msg->source_id(), board.name.c_str() (uint64)msg->source_id(), board.name.c_str()
@ -1872,6 +1870,7 @@ void Steam_User_Stats::network_callback_leaderboards(Common_Message *msg)
} }
const auto &board_info_msg = msg->leaderboards_messages().leaderboard_info(); const auto &board_info_msg = msg->leaderboards_messages().leaderboard_info();
PRINT_DEBUG("Steam_User_Stats::network_callback_leaderboards attempting to cache leaderboard '%s'\n", board_info_msg.board_name().c_str()); PRINT_DEBUG("Steam_User_Stats::network_callback_leaderboards attempting to cache leaderboard '%s'\n", board_info_msg.board_name().c_str());
unsigned int board_handle = cache_leaderboard_ifneeded( unsigned int board_handle = cache_leaderboard_ifneeded(
board_info_msg.board_name(), board_info_msg.board_name(),
@ -1906,11 +1905,10 @@ void Steam_User_Stats::network_callback_leaderboards(Common_Message *msg)
// user connect/disconnect // user connect/disconnect
void Steam_User_Stats::network_callback_low_level(Common_Message *msg) void Steam_User_Stats::network_callback_low_level(Common_Message *msg)
{ {
CSteamID steamid(msg->source_id()); CSteamID steamid((uint64)msg->source_id());
// this should never happen, but just in case // this should never happen, but just in case
if (steamid == settings->get_local_steam_id()) return; if (steamid == settings->get_local_steam_id()) return;
switch (msg->low_level().type()) switch (msg->low_level().type())
{ {
case Low_Level::CONNECT: case Low_Level::CONNECT: