From 8d03c0628d5f679248e46de22adc17cb27c4cf3c Mon Sep 17 00:00:00 2001 From: terencehill Date: Wed, 18 May 2022 02:42:24 +0200 Subject: [PATCH] Playerstats: fix higher average ping for players who disconnect and reconnect --- qcsrc/common/playerstats.qc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/qcsrc/common/playerstats.qc b/qcsrc/common/playerstats.qc index f8aa2b514..e83305886 100644 --- a/qcsrc/common/playerstats.qc +++ b/qcsrc/common/playerstats.qc @@ -207,7 +207,13 @@ void PlayerStats_GameReport_FinalizePlayer(entity p) { float latency = max(0, CS(p).latency_sum / CS(p).latency_cnt); if(latency) - PlayerStats_GameReport_Event_Player(p, PLAYERSTATS_AVGLATENCY, latency); + { + // if previous average latency exists (player disconnected and reconnected) + // make the average of previous and current average latency + float prev_latency = PlayerStats_GameReport_Event_Player(p, PLAYERSTATS_AVGLATENCY, 0); + float new_latency = !prev_latency ? latency : (prev_latency + latency) / 2; + PlayerStats_GameReport_Event_Player(p, PLAYERSTATS_AVGLATENCY, -prev_latency + new_latency); + } } db_put(PS_GR_OUT_DB, sprintf("%s:_ranked", p.playerstats_id), ftos(CS_CVAR(p).cvar_cl_allow_uidranking)); -- 2.39.2