From 84c9d49bbe408b001e8a677f763dc6c8beb1c2e3 Mon Sep 17 00:00:00 2001 From: terencehill Date: Sun, 2 Jan 2022 09:24:52 +0000 Subject: [PATCH] Reset player stats on repeated readyrestart, it fixes #2656 --- qcsrc/common/playerstats.qc | 41 ++++++++++++++++++++++++++++++++++++ qcsrc/common/playerstats.qh | 2 ++ qcsrc/server/command/vote.qc | 4 ++-- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/qcsrc/common/playerstats.qc b/qcsrc/common/playerstats.qc index c11efed8b..e648d2953 100644 --- a/qcsrc/common/playerstats.qc +++ b/qcsrc/common/playerstats.qc @@ -21,6 +21,47 @@ void PlayerStats_Prematch() //foobar } +// Deletes current playerstats DB, creates a new one and fully initializes it +void PlayerStats_GameReport_Reset_All() +{ + strfree(PS_GR_OUT_TL); + strfree(PS_GR_OUT_PL); + strfree(PS_GR_OUT_EVL); + + if (PS_GR_OUT_DB >= 0) + db_close(PS_GR_OUT_DB); + PlayerStats_GameReport_Init(); + if(PS_GR_OUT_DB < 0) + return; + + for (int i = 0; i < 16; i++) + if (teamscorekeepers[i]) + PlayerStats_GameReport_AddTeam(i + 1); + FOREACH_CLIENT(true, { + // NOTE Adding back a player we are applying any cl_allow_uidtracking change + // usually only possible by reconnecting to the server + strfree(it.playerstats_id); + PlayerStats_GameReport_AddEvent(sprintf("kills-%d", it.playerid)); + if (IS_BOT_CLIENT(it) || CS_CVAR(it).cvar_cl_allow_uidtracking) + PlayerStats_GameReport_AddPlayer(it); + }); + FOREACH(Scores, true, { + string label = scores_label(it); + if (label == "") + continue; + PlayerStats_GameReport_AddEvent(strcat(PLAYERSTATS_TOTAL, label)); + PlayerStats_GameReport_AddEvent(strcat(PLAYERSTATS_SCOREBOARD, label)); + }); + for(int i = 0; i < MAX_TEAMSCORE; ++i) + { + string label = teamscores_label(i); + if (label == "") + continue; + PlayerStats_GameReport_AddEvent(strcat(PLAYERSTATS_TOTAL, label)); + PlayerStats_GameReport_AddEvent(strcat(PLAYERSTATS_SCOREBOARD, label)); + } +} + void PlayerStats_GameReport_AddPlayer(entity e) { if((PS_GR_OUT_DB < 0) || (e.playerstats_id)) { return; } diff --git a/qcsrc/common/playerstats.qh b/qcsrc/common/playerstats.qh index d41a097d6..c38406c46 100644 --- a/qcsrc/common/playerstats.qh +++ b/qcsrc/common/playerstats.qh @@ -56,6 +56,8 @@ const string PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM = "achievement-firstvictim"; // delay map switch until this is set bool PlayerStats_GameReport_DelayMapVote; +void PlayerStats_GameReport_Reset_All(); + // call at initialization void PlayerStats_GameReport_Init(); diff --git a/qcsrc/server/command/vote.qc b/qcsrc/server/command/vote.qc index 09e277116..f99c18246 100644 --- a/qcsrc/server/command/vote.qc +++ b/qcsrc/server/command/vote.qc @@ -342,6 +342,8 @@ void reset_map(bool dorespawn) { if (game_stopped) return; + + PlayerStats_GameReport_Reset_All(); if (round_handler_IsActive()) round_handler_Reset(game_starttime); } @@ -448,8 +450,6 @@ void ReadyRestart_force() FOREACH_CLIENT(IS_PLAYER(it), { it.alivetime = 0; CS(it).killcount = 0; - float val = PlayerStats_GameReport_Event_Player(it, PLAYERSTATS_ALIVETIME, 0); - PlayerStats_GameReport_Event_Player(it, PLAYERSTATS_ALIVETIME, -val); }); restart_mapalreadyrestarted = false; // reset this var, needed when cvar sv_ready_restart_repeatable is in use -- 2.39.2