]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Reset player stats on repeated readyrestart, it fixes #2656
authorterencehill <piuntn@gmail.com>
Sun, 2 Jan 2022 09:24:52 +0000 (09:24 +0000)
committerterencehill <piuntn@gmail.com>
Sun, 2 Jan 2022 09:24:52 +0000 (09:24 +0000)
qcsrc/common/playerstats.qc
qcsrc/common/playerstats.qh
qcsrc/server/command/vote.qc

index c11efed8b78af9868d79c635bc0761fe483e7c62..e648d29538ce507d0f524b780bc941b5e4e6f09f 100644 (file)
@@ -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; }
index d41a097d6d642419ecd4f8218e071774ca516f47..c38406c4674ea4a760f448d75fff6f1e14c2a904 100644 (file)
@@ -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();
 
index 09e277116a9efcc8c180355a9ee836a0eac9a039..f99c182466a535ba0273044045344df0ba748b7b 100644 (file)
@@ -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