]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge branch 'divVerent/anticheat-playerstats'
authorRudolf Polzer <divVerent@xonotic.org>
Tue, 15 Nov 2016 15:45:22 +0000 (10:45 -0500)
committerRudolf Polzer <divVerent@xonotic.org>
Tue, 15 Nov 2016 15:45:22 +0000 (10:45 -0500)
qcsrc/common/playerstats.qc
qcsrc/common/playerstats.qh
qcsrc/common/state.qc
qcsrc/server/anticheat.qc
qcsrc/server/anticheat.qh
qcsrc/server/command/sv_cmd.qc

index 4dab61164e4b3f7e94b6a2880df0f1d232269e9d..b879b63b09587a8846ec9bf910154b796c4cfab3 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
@@ -141,6 +142,7 @@ 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))
        {
@@ -249,6 +251,8 @@ 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; }
 }
index 73496ba7639bd1b168b54c60fce009e2dbdd9916..1fafb13978dc9c43c1467ff3accb10089c55b6ad 100644 (file)
@@ -40,6 +40,7 @@ const string PLAYERSTATS_SCOREBOARD_POS = "scoreboardpos";
 
 const string PLAYERSTATS_TOTAL = "total-";
 const string PLAYERSTATS_SCOREBOARD = "scoreboard-";
+const string PLAYERSTATS_ANTICHEAT = "anticheat-";
 
 const string PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_3 = "achievement-kill-spree-3";
 const string PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_5 = "achievement-kill-spree-5";
index 891461c6a4dd24f92886c1c89522af11e67f2093..1a2fb1e7bfb171bb0405c1f8a02f83f09bde43dd 100644 (file)
@@ -63,7 +63,7 @@ void ClientState_attach(entity this)
 
 void bot_clientdisconnect(entity this);
 void W_HitPlotClose(entity this);
-void anticheat_report(entity this);
+void anticheat_report_to_eventlog(entity this);
 void playerdemo_shutdown(entity this);
 void entcs_detach(entity this);
 void accuracy_free(entity this);
@@ -80,7 +80,7 @@ void ClientState_detach(entity this)
     bot_clientdisconnect(this);
 
     W_HitPlotClose(this);
-    anticheat_report(this);
+    anticheat_report_to_eventlog(this);
     playerdemo_shutdown(this);
     entcs_detach(this);
     accuracy_free(this);
index 4861fe2a79c25cb75ca100e3ddc6b1545870d863..85bed044fb171d7569ecc0c8ed396b8991da24d9 100644 (file)
@@ -6,6 +6,7 @@
 #include "miscfunctions.qh"
 
 #include "command/common.qh"
+#include <common/playerstats.qh>
 #include <common/state.qh>
 
 .float anticheat_jointime;
@@ -158,67 +159,68 @@ void anticheat_prethink(entity this)
        CS(this).anticheat_div0_evade_offset = 0;
 }
 
-string anticheat_display(float f, float tmin, float mi, float ma)
+string anticheat_display(float f, float t, float tmin, float mi, float ma)
 {
        string s;
        s = ftos(f);
-       if(f <= mi)
-               return strcat(s, ":N");
-       if(f >= ma)
-               return strcat(s, ":Y");
+       if (t >= tmin) {
+               if(f <= mi)
+                       return strcat(s, ":N");
+               if(f >= ma)
+                       return strcat(s, ":Y");
+       }
        return strcat(s, ":-");
 }
 
-void anticheat_report(entity this)
-{
+#define ANTICHEATS(this, f) \
+       f(this, "speedhack", MEAN_EVALUATE(CS(this), anticheat_speedhack), 240, 0, 9999); /* Actually this one seems broken. */ \
+       f(this, "speedhack_m1", MEAN_EVALUATE(CS(this), anticheat_speedhack_m1), 240, 1.01, 1.25); \
+       f(this, "speedhack_m2", MEAN_EVALUATE(CS(this), anticheat_speedhack_m2), 240, 1.01, 1.25); \
+       f(this, "speedhack_m3", MEAN_EVALUATE(CS(this), anticheat_speedhack_m3), 240, 1.01, 1.25); \
+       f(this, "speedhack_m4", MEAN_EVALUATE(CS(this), anticheat_speedhack_m4), 240, 1.01, 1.25); \
+       f(this, "speedhack_m5", MEAN_EVALUATE(CS(this), anticheat_speedhack_m5), 240, 1.01, 1.25); \
+       f(this, "div0_strafebot_old", MEAN_EVALUATE(CS(this), anticheat_div0_strafebot_old), 120, 0.15, 0.4); \
+       f(this, "div0_strafebot_new", MEAN_EVALUATE(CS(this), anticheat_div0_strafebot_new), 120, 0.25, 0.8); \
+       f(this, "div0_evade", MEAN_EVALUATE(CS(this), anticheat_div0_evade), 120, 0.2, 0.5); \
+       f(this, "idle_snapaim", MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_signal) - MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_noise), 120, 0, 9999); \
+       f(this, "idle_snapaim_signal", MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_signal), 120, 0, 9999); \
+       f(this, "idle_snapaim_noise", MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_noise), 120, 0, 9999); \
+       f(this, "idle_snapaim_m2", MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_m2), 120, 0, 9999); \
+       f(this, "idle_snapaim_m3", MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_m3), 120, 0, 9999); \
+       f(this, "idle_snapaim_m4", MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_m4), 120, 0, 9999); \
+       f(this, "idle_snapaim_m7", MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_m7), 120, 0, 9999); \
+       f(this, "idle_snapaim_m10", MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_m10), 120, 0, 9999)
+
+void anticheat_report_one_to_eventlog(entity this, string name, float f, float tmin, float mi, float ma) {
+       GameLogEcho(strcat(":anticheat:", name, ":", anticheat_display(f, servertime - CS(this).anticheat_jointime, tmin, mi, ma)));
+}
+
+void anticheat_report_to_eventlog(entity this) {
        if(!autocvar_sv_eventlog)
                return;
-       // TODO(divVerent): Use xonstat to acquire good thresholds.
        GameLogEcho(strcat(":anticheat:_time:", ftos(this.playerid), ":", ftos(servertime - CS(this).anticheat_jointime)));
-       GameLogEcho(strcat(":anticheat:speedhack:", ftos(this.playerid), ":", anticheat_display(MEAN_EVALUATE(CS(this), anticheat_speedhack), 240, 0, 9999))); // Actually this one seems broken.
-       GameLogEcho(strcat(":anticheat:speedhack_m1:", ftos(this.playerid), ":", anticheat_display(MEAN_EVALUATE(CS(this), anticheat_speedhack_m1), 240, 1.01, 1.25)));
-       GameLogEcho(strcat(":anticheat:speedhack_m2:", ftos(this.playerid), ":", anticheat_display(MEAN_EVALUATE(CS(this), anticheat_speedhack_m2), 240, 1.01, 1.25)));
-       GameLogEcho(strcat(":anticheat:speedhack_m3:", ftos(this.playerid), ":", anticheat_display(MEAN_EVALUATE(CS(this), anticheat_speedhack_m3), 240, 1.01, 1.25)));
-       GameLogEcho(strcat(":anticheat:speedhack_m4:", ftos(this.playerid), ":", anticheat_display(MEAN_EVALUATE(CS(this), anticheat_speedhack_m4), 240, 1.01, 1.25)));
-       GameLogEcho(strcat(":anticheat:speedhack_m5:", ftos(this.playerid), ":", anticheat_display(MEAN_EVALUATE(CS(this), anticheat_speedhack_m5), 240, 1.01, 1.25)));
-       GameLogEcho(strcat(":anticheat:div0_strafebot_old:", ftos(this.playerid), ":", anticheat_display(MEAN_EVALUATE(CS(this), anticheat_div0_strafebot_old), 120, 0.15, 0.4)));
-       GameLogEcho(strcat(":anticheat:div0_strafebot_new:", ftos(this.playerid), ":", anticheat_display(MEAN_EVALUATE(CS(this), anticheat_div0_strafebot_new), 120, 0.25, 0.8)));
-       GameLogEcho(strcat(":anticheat:div0_evade:", ftos(this.playerid), ":", anticheat_display(MEAN_EVALUATE(CS(this), anticheat_div0_evade), 120, 0.2, 0.5)));
-       GameLogEcho(strcat(":anticheat:idle_snapaim:", ftos(this.playerid), ":", anticheat_display(MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_signal) - MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_noise), 120, 0, 9999)));
-       GameLogEcho(strcat(":anticheat:idle_snapaim_signal:", ftos(this.playerid), ":", anticheat_display(MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_signal), 120, 0, 9999)));
-       GameLogEcho(strcat(":anticheat:idle_snapaim_noise:", ftos(this.playerid), ":", anticheat_display(MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_noise), 120, 0, 9999)));
-       GameLogEcho(strcat(":anticheat:idle_snapaim_m2:", ftos(this.playerid), ":", anticheat_display(MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_m2), 120, 0, 9999)));
-       GameLogEcho(strcat(":anticheat:idle_snapaim_m3:", ftos(this.playerid), ":", anticheat_display(MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_m3), 120, 0, 9999)));
-       GameLogEcho(strcat(":anticheat:idle_snapaim_m4:", ftos(this.playerid), ":", anticheat_display(MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_m4), 120, 0, 9999)));
-       GameLogEcho(strcat(":anticheat:idle_snapaim_m7:", ftos(this.playerid), ":", anticheat_display(MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_m7), 120, 0, 9999)));
-       GameLogEcho(strcat(":anticheat:idle_snapaim_m10:", ftos(this.playerid), ":", anticheat_display(MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_m10), 120, 0, 9999)));
+       ANTICHEATS(this, anticheat_report_one_to_eventlog);
 }
 
-float anticheat_getvalue(entity this, string id)
-{
-       switch(id) {
-               case "_time": return servertime - CS(this).anticheat_jointime;
-               case "speedhack": return MEAN_EVALUATE(CS(this), anticheat_speedhack);
-               case "speedhack_m1": return MEAN_EVALUATE(CS(this), anticheat_speedhack_m1);
-               case "speedhack_m2": return MEAN_EVALUATE(CS(this), anticheat_speedhack_m2);
-               case "speedhack_m3": return MEAN_EVALUATE(CS(this), anticheat_speedhack_m3);
-               case "speedhack_m4": return MEAN_EVALUATE(CS(this), anticheat_speedhack_m4);
-               case "speedhack_m5": return MEAN_EVALUATE(CS(this), anticheat_speedhack_m5);
-               case "div0_strafebot_old": return MEAN_EVALUATE(CS(this), anticheat_div0_strafebot_old);
-               case "div0_strafebot_new": return MEAN_EVALUATE(CS(this), anticheat_div0_strafebot_new);
-               case "div0_evade": return MEAN_EVALUATE(CS(this), anticheat_div0_evade);
-               case "idle_snapaim": return MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_signal) - MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_noise);
-               case "idle_snapaim_signal": return MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_signal);
-               case "idle_snapaim_noise": return MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_noise);
-               case "idle_snapaim_m2": return MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_m2);
-               case "idle_snapaim_m3": return MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_m3);
-               case "idle_snapaim_m4": return MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_m4);
-               case "idle_snapaim_m7": return MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_m7);
-               case "idle_snapaim_m10": return MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_m10);
-       }
-       return -1;
+void anticheat_report_one_to_playerstats(entity this, string name, float f, float tmin, float mi, float ma) {
+       PS_GR_P_ADDVAL(this, strcat(PLAYERSTATS_ANTICHEAT, name), f);
 }
 
+void anticheat_report_to_playerstats(entity this) {
+       PS_GR_P_ADDVAL(this, strcat(PLAYERSTATS_ANTICHEAT, "_time"), servertime - CS(this).anticheat_jointime);
+       ANTICHEATS(this, anticheat_report_one_to_playerstats);
+}
+
+#define ANTICHEAT_REGISTER_ONE_TO_PLAYERSTATS(unused_this, name, unused_f, unused_tmin, unused_mi, unused_ma) \
+       PlayerStats_GameReport_AddEvent(strcat(PLAYERSTATS_ANTICHEAT, name))
+void anticheat_register_to_playerstats() {
+       PlayerStats_GameReport_AddEvent(strcat(PLAYERSTATS_ANTICHEAT, "_time"));
+       ANTICHEATS(world, ANTICHEAT_REGISTER_ONE_TO_PLAYERSTATS);
+}
+
+#undef ANTICHEAT_REGISTER_ONE_TO_PLAYERSTATS
+#undef ANTICHEATS
+
 void anticheat_startframe()
 {
        anticheat_div0_evade_evasion_delta += frametime * (0.5 + random());
index 2b0522b991fb25747ce48c06003cf4433c74e30d..dd870dd397ceee549e4786adc25478f3fbb6e92e 100644 (file)
@@ -1,14 +1,14 @@
 #pragma once
 
 void anticheat_init(entity this);
-void anticheat_report(entity this);
+void anticheat_report_to_eventlog(entity this);
+void anticheat_report_to_playerstats(entity this);
+void anticheat_register_to_playerstats();
 
 void anticheat_physics(entity this);
 void anticheat_spectatecopy(entity this, entity spectatee);
 void anticheat_prethink(entity this);
 
-float anticheat_getvalue(entity this, string name);
-
 void anticheat_startframe();
 void anticheat_endframe();
 
index cbc65680a0aed6dcf309bd88ebd5069c61f87b5e..f2be14b60042e02acac01829225186c89989c9c5 100644 (file)
@@ -226,7 +226,7 @@ void GameCommand_anticheat(float request, float argc)
 
                        if (accepted > 0)
                        {
-                               anticheat_report(client);
+                               anticheat_report_to_eventlog(client);
                                return;
                        }
                        else