]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/playerstats.qc
Merge branch 'martin-t/units' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / playerstats.qc
index 4dab61164e4b3f7e94b6a2880df0f1d232269e9d..4165115d8d85202c67eb4d78fd1475bd9536fbce 100644 (file)
@@ -5,9 +5,10 @@
     #include "constants.qh"
     #include "util.qh"
     #include <common/weapons/_all.qh>
-    #include "../server/weapons/accuracy.qh"
+    #include "../server/anticheat.qh"
     #include "../server/defs.qh"
     #include "../server/scores.qh"
+    #include "../server/weapons/accuracy.qh"
 #endif
 
 #ifdef SVQC
@@ -21,7 +22,7 @@ void PlayerStats_GameReport_AddPlayer(entity e)
        if((PS_GR_OUT_DB < 0) || (e.playerstats_id)) { return; }
 
        // set up player identification
-       string s = string_null;
+       string s = "";
 
        if((e.crypto_idfp != "") && (e.cvar_cl_allow_uidtracking == 1))
                { s = e.crypto_idfp; }
@@ -107,7 +108,7 @@ float PlayerStats_GameReport_Event(string prefix, string event_id, float value)
 void PlayerStats_GameReport_Accuracy(entity p)
 {
        #define ACCMAC(suffix, field) \
-               PS_GR_P_ADDVAL(p, sprintf("acc-%s-%s", it.netname, suffix), p.accuracy.(field[i-1]));
+               PS_GR_P_ADDVAL(p, sprintf("acc-%s-%s", it.netname, suffix), CS(p).accuracy.(field[i-1]));
        FOREACH(Weapons, it != WEP_Null, {
                ACCMAC("hit", accuracy_hit)
                ACCMAC("fired", accuracy_fired)
@@ -132,7 +133,7 @@ void PlayerStats_GameReport_FinalizePlayer(entity p)
        db_put(PS_GR_OUT_DB, sprintf("%s:_playerid", p.playerstats_id), ftos(p.playerid));
 
        if(p.cvar_cl_allow_uid2name == 1 || IS_BOT_CLIENT(p))
-               db_put(PS_GR_OUT_DB, sprintf("%s:_netname", p.playerstats_id), p.netname);
+               db_put(PS_GR_OUT_DB, sprintf("%s:_netname", p.playerstats_id), playername(p, false));
 
        if(teamplay)
                db_put(PS_GR_OUT_DB, sprintf("%s:_team", p.playerstats_id), ftos(p.team));
@@ -141,12 +142,13 @@ void PlayerStats_GameReport_FinalizePlayer(entity p)
                PS_GR_P_ADDVAL(p, PLAYERSTATS_JOINS, 1);
 
        PlayerStats_GameReport_Accuracy(p);
+       anticheat_report_to_playerstats(p);
 
        if(IS_REAL_CLIENT(p))
        {
-               if(p.latency_cnt)
+               if(CS(p).latency_cnt)
                {
-                       float latency = (p.latency_sum / p.latency_cnt);
+                       float latency = (CS(p).latency_sum / CS(p).latency_cnt);
                        if(latency) { PS_GR_P_ADDVAL(p, PLAYERSTATS_AVGLATENCY, latency); }
                }
        }
@@ -249,10 +251,26 @@ void PlayerStats_GameReport_Init() // initiated before InitGameplayMode so that
                PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_BOTLIKE);
                PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD);
                PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM);
+
+               anticheat_register_to_playerstats();
        }
        else { PlayerStats_GameReport_DelayMapVote = false; }
 }
 
+// this... is a hack, a temporary one until we get a proper duel gametype
+string PlayerStats_GetGametype()
+{
+       if(IS_GAMETYPE(DEATHMATCH) && autocvar_g_maxplayers == 2)
+       {
+               // probably duel, but let's make sure
+               int plcount = 0;
+               FOREACH_CLIENT(IS_PLAYER(it), ++plcount);
+               if(plcount <= 2)
+                       return "duel";
+       }
+       return GetGametype();
+}
+
 void PlayerStats_GameReport_Handler(entity fh, entity pass, float status)
 {
        string t, tn;
@@ -309,7 +327,7 @@ void PlayerStats_GameReport_Handler(entity fh, entity pass, float status)
                        #ifdef WATERMARK
                        url_fputs(fh, sprintf("R %s\n", WATERMARK));
                        #endif
-                       url_fputs(fh, sprintf("G %s\n", GetGametype()));
+                       url_fputs(fh, sprintf("G %s\n", PlayerStats_GetGametype()));
                        url_fputs(fh, sprintf("O %s\n", modname));
                        url_fputs(fh, sprintf("M %s\n", GetMapname()));
                        url_fputs(fh, sprintf("I %s\n", matchid));
@@ -552,7 +570,7 @@ void PlayerStats_PlayerBasic_Handler(entity fh, entity p, float status)
                     case "e":
                         LOG_TRACE("G: ", gt);
                         LOG_TRACE("e: ", data);
-                        if (gt == GetGametype()) {
+                        if (gt == PlayerStats_GetGametype()) {
                             handled = true;
                             float e = stof(data);
                             PlayerScore_Add(p, SP_ELO, +1 + e);