From 4ffdbacc1087b6ac964a72b252a6f92c850afd55 Mon Sep 17 00:00:00 2001 From: Samual Lenks Date: Tue, 18 Sep 2012 18:04:32 -0400 Subject: [PATCH] Implement avglatency field to playerstats --- qcsrc/server/g_world.qc | 13 +++++++++++++ qcsrc/server/playerstats.qc | 9 +++++++-- qcsrc/server/playerstats.qh | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/qcsrc/server/g_world.qc b/qcsrc/server/g_world.qc index 6efe273bd..120fa6716 100644 --- a/qcsrc/server/g_world.qc +++ b/qcsrc/server/g_world.qc @@ -1,3 +1,7 @@ +#define LATENCY_THINKRATE 10 +.float latency_sum; +.float latency_cnt; +.float latency_time; entity pingplreport; void PingPLReport_Think() { @@ -18,6 +22,15 @@ void PingPLReport_Think() WriteShort(MSG_BROADCAST, max(1, e.ping)); WriteByte(MSG_BROADCAST, ceil(e.ping_packetloss * 255)); WriteByte(MSG_BROADCAST, ceil(e.ping_movementloss * 255)); + + // record latency times for clients throughout the match so we can report it to playerstats + if(time > (e.latency_time + LATENCY_THINKRATE)) + { + e.latency_sum += e.ping; + e.latency_cnt += 1; + e.latency_time = time; + //print("sum: ", ftos(e.latency_sum), ", cnt: ", ftos(e.latency_cnt), ", avg: ", ftos(e.latency_sum / e.latency_cnt), ".\n"); + } } else { diff --git a/qcsrc/server/playerstats.qc b/qcsrc/server/playerstats.qc index c94a5f22a..4608b56df 100644 --- a/qcsrc/server/playerstats.qc +++ b/qcsrc/server/playerstats.qc @@ -20,6 +20,7 @@ void PlayerStats_Init() // initiated before InitGameplayMode so that scores are serverflags |= SERVERFLAG_PLAYERSTATS; PlayerStats_AddEvent(PLAYERSTATS_ALIVETIME); + PlayerStats_AddEvent(PLAYERSTATS_AVGLATENCY); PlayerStats_AddEvent(PLAYERSTATS_WINS); PlayerStats_AddEvent(PLAYERSTATS_MATCHES); PlayerStats_AddEvent(PLAYERSTATS_JOINS); @@ -193,6 +194,7 @@ void PlayerStats_TeamScore(float t, string event_id, float value) // TODO: doesn e: followed by an event name, a space, and the event count/score event names can be: alivetime: total playing time of the player + avglatency: average network latency compounded throughout the match wins: number of games won (can only be set if matches is set) matches: number of matches played to the end (not aborted by map switch) joins: number of matches joined (always 1 unless player never played during the match) @@ -236,7 +238,7 @@ void PlayerStats_ready(entity fh, entity pass, float status) switch(status) { case URL_READY_CANWRITE: - url_fputs(fh, "V 4\n"); + url_fputs(fh, "V 5\n"); #ifdef WATERMARK url_fputs(fh, sprintf("R %s\n", WATERMARK())); #endif @@ -389,7 +391,10 @@ void PlayerStats_EndMatch(float finished) if((g_arena || g_lms || g_ca) && (p.alivetime <= 0)) { continue; } else if(p.classname != "player") { continue; } - + + float latency = (p.latency_sum / p.latency_cnt); + if(latency) { PlayerStats_Event(p, PLAYERSTATS_AVGLATENCY, latency); } + PlayerScore_PlayerStats(p); PlayerStats_Event(p, PLAYERSTATS_SCOREBOARD_VALID, 1); if(finished) diff --git a/qcsrc/server/playerstats.qh b/qcsrc/server/playerstats.qh index b99366434..11a311028 100644 --- a/qcsrc/server/playerstats.qh +++ b/qcsrc/server/playerstats.qh @@ -1,5 +1,6 @@ // time the player was alive and kicking string PLAYERSTATS_ALIVETIME = "alivetime"; +string PLAYERSTATS_AVGLATENCY = "avglatency"; string PLAYERSTATS_WINS = "wins"; string PLAYERSTATS_MATCHES = "matches"; string PLAYERSTATS_JOINS = "joins"; -- 2.39.2