X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fcommon%2Fplayerstats.qc;h=17c76461fd3516a72b5355a39f906846cfe9f205;hp=e648d29538ce507d0f524b780bc941b5e4e6f09f;hb=HEAD;hpb=5d79f5e9f45a507f057f1615ffe4c3f824eebc58 diff --git a/qcsrc/common/playerstats.qc b/qcsrc/common/playerstats.qc index e648d2953..c2adabb1b 100644 --- a/qcsrc/common/playerstats.qc +++ b/qcsrc/common/playerstats.qc @@ -15,6 +15,17 @@ #include #endif + +#ifdef GAMEQC +REPLICATE(cvar_cl_allow_uid2name, int, "cl_allow_uid2name"); +REPLICATE(cvar_cl_allow_uidranking, bool, "cl_allow_uidranking"); +REPLICATE(cvar_cl_allow_uidtracking, int, "cl_allow_uidtracking"); +#endif + +#ifdef SVQC +REPLICATE_APPLYCHANGE("cl_allow_uidtracking", { PlayerStats_GameReport_AddPlayer(this); }); +#endif + #ifdef SVQC void PlayerStats_Prematch() { @@ -29,12 +40,14 @@ void PlayerStats_GameReport_Reset_All() strfree(PS_GR_OUT_EVL); if (PS_GR_OUT_DB >= 0) + { db_close(PS_GR_OUT_DB); - PlayerStats_GameReport_Init(); + PlayerStats_GameReport_Init(); + } if(PS_GR_OUT_DB < 0) return; - for (int i = 0; i < 16; i++) + for (int i = 0; i < 16; ++i) if (teamscorekeepers[i]) PlayerStats_GameReport_AddTeam(i + 1); FOREACH_CLIENT(true, { @@ -42,8 +55,7 @@ void PlayerStats_GameReport_Reset_All() // 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); + PlayerStats_GameReport_AddPlayer(it); }); FOREACH(Scores, true, { string label = scores_label(it); @@ -193,9 +205,15 @@ void PlayerStats_GameReport_FinalizePlayer(entity p) { if(CS(p).latency_cnt) { - float latency = (CS(p).latency_sum / CS(p).latency_cnt); + 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)); @@ -240,26 +258,28 @@ void PlayerStats_GameReport(bool finished) PlayerStats_GameReport_FinalizePlayer(it); }); - if(autocvar_g_playerstats_gamereport_uri != "") - { - PlayerStats_GameReport_DelayMapVote = true; - url_multi_fopen( - autocvar_g_playerstats_gamereport_uri, - FILE_APPEND, - PlayerStats_GameReport_Handler, - NULL - ); - } - else + if(autocvar_g_playerstats_gamereport_uri == "" || warmup_stage) { PlayerStats_GameReport_DelayMapVote = false; db_close(PS_GR_OUT_DB); PS_GR_OUT_DB = -1; + return; } + + PlayerStats_GameReport_DelayMapVote = true; + url_multi_fopen( + autocvar_g_playerstats_gamereport_uri, + FILE_APPEND, + PlayerStats_GameReport_Handler, + NULL + ); } void PlayerStats_GameReport_Init() // initiated before InitGameplayMode so that scores are added properly { + serverflags &= ~SERVERFLAG_PLAYERSTATS; + serverflags &= ~SERVERFLAG_PLAYERSTATS_CUSTOM; + if(autocvar_g_playerstats_gamereport_uri == "") { return; } PS_GR_OUT_DB = db_create(); @@ -268,7 +288,11 @@ void PlayerStats_GameReport_Init() // initiated before InitGameplayMode so that { PlayerStats_GameReport_DelayMapVote = true; - serverflags |= SERVERFLAG_PLAYERSTATS; + if(autocvar_g_playerstats_gamereport_uri != cvar_defstring("g_playerstats_gamereport_uri")) + serverflags |= SERVERFLAG_PLAYERSTATS | SERVERFLAG_PLAYERSTATS_CUSTOM; + else if(checkextension("DP_CRYPTO") && checkextension("DP_QC_URI_POST")) + // XonStat submission requires player and server IDs, and HTTPS POST + serverflags |= SERVERFLAG_PLAYERSTATS; PlayerStats_GameReport_AddEvent(PLAYERSTATS_ALIVETIME); PlayerStats_GameReport_AddEvent(PLAYERSTATS_AVGLATENCY); @@ -344,12 +368,14 @@ void PlayerStats_GameReport_Handler(entity fh, entity pass, float status) * C: number of "unpure" cvar changes * U: UDP port number of the server * D: duration of the match + * RP: number of rounds played * L: "ladder" in which the server is participating in * P: player ID of an existing player; this also sets the owner for all following "n", "e" and "t" lines (lower case!) * Q: team number of an existing team (format: team#NN); this also sets the owner for all following "e" lines (lower case!) * i: player index * n: nickname of the player (optional) * t: team ID + * r: player ranking enabled / disabled * e: followed by an event name, a space, and the event count/score * event names can be: * alivetime: total playing time of the player @@ -383,7 +409,10 @@ void PlayerStats_GameReport_Handler(entity fh, entity pass, float status) url_fputs(fh, sprintf("C %d\n", cvar_purechanges_count)); url_fputs(fh, sprintf("U %d\n", cvar("port"))); url_fputs(fh, sprintf("D %f\n", max(0, time - game_starttime))); - url_fputs(fh, sprintf("L %s\n", autocvar_g_playerstats_gamereport_ladder)); + if (rounds_played > 0) + url_fputs(fh, sprintf("RP %d\n", rounds_played)); + if (autocvar_g_playerstats_gamereport_ladder != "") + url_fputs(fh, sprintf("L %s\n", autocvar_g_playerstats_gamereport_ladder)); // TEAMS if(teamplay)