]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/playerstats.qc
Transifex autosync
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / playerstats.qc
index 3d0ca1ee6d6154f731f4eff2884522d7b5091552..c2adabb1b601c415710a4768bbead49959c32934 100644 (file)
        #include <server/world.qh>
 #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, {
@@ -192,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));
@@ -239,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();
@@ -267,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);
@@ -343,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
@@ -382,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)