X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fserver%2Fanticheat.qc;h=9327a203416598b10e37229d7909f3e34f0eb86d;hp=6647633ff9c9eec920d6f24d8ea73e9f55ca2e80;hb=e0012447bfce1b551df3dc01b043655aa93dafad;hpb=5f591ed9737ba08832475c1c324f91721e76bdf7 diff --git a/qcsrc/server/anticheat.qc b/qcsrc/server/anticheat.qc index 6647633ff9..9327a20341 100644 --- a/qcsrc/server/anticheat.qc +++ b/qcsrc/server/anticheat.qc @@ -5,11 +5,9 @@ #include "defs.qh" #include "miscfunctions.qh" -#include "../dpdefs/progsdefs.qh" -#include "../dpdefs/dpextensions.qh" - - #include "command/common.qh" +#include +#include .float anticheat_jointime; @@ -62,39 +60,39 @@ float movement_oddity(vector m0, vector m1) // returns 0 for: -1, -sqrt(0.5), 0 (angles that commonly happen with kbd) } -void anticheat_physics() +void anticheat_physics(entity this) { float f; // div0_evade -> SPECTATORS - makevectors(self.v_angle); - if(self.anticheat_div0_evade_offset == 0) + makevectors(this.v_angle); + if(CS(this).anticheat_div0_evade_offset == 0) { f = fabs(anticheat_div0_evade_evasion_delta - floor(anticheat_div0_evade_evasion_delta) - 0.5) * 2; // triangle function - self.anticheat_div0_evade_offset = servertime + sys_frametime * (3 * f - 1); - self.anticheat_div0_evade_v_angle = self.v_angle; - self.anticheat_div0_evade_forward_initial = v_forward; - MEAN_ACCUMULATE(anticheat_div0_evade, 0, 1); + CS(this).anticheat_div0_evade_offset = servertime + sys_frametime * (3 * f - 1); + CS(this).anticheat_div0_evade_v_angle = this.v_angle; + CS(this).anticheat_div0_evade_forward_initial = v_forward; + MEAN_ACCUMULATE(CS(this), anticheat_div0_evade, 0, 1); } else { - if(time < self.anticheat_div0_evade_offset) - self.anticheat_div0_evade_v_angle = self.v_angle; - MEAN_ACCUMULATE(anticheat_div0_evade, 0.5 - 0.5 * (self.anticheat_div0_evade_forward_initial * v_forward), 1); + if(time < CS(this).anticheat_div0_evade_offset) + CS(this).anticheat_div0_evade_v_angle = this.v_angle; + MEAN_ACCUMULATE(CS(this), anticheat_div0_evade, 0.5 - 0.5 * (CS(this).anticheat_div0_evade_forward_initial * v_forward), 1); } - MEAN_ACCUMULATE(anticheat_div0_strafebot_old, movement_oddity(self.movement, self.anticheat_div0_strafebot_movement_prev), 1); - self.anticheat_div0_strafebot_movement_prev = self.movement; + MEAN_ACCUMULATE(CS(this), anticheat_div0_strafebot_old, movement_oddity(CS(this).movement, CS(this).anticheat_div0_strafebot_movement_prev), 1); + CS(this).anticheat_div0_strafebot_movement_prev = CS(this).movement; // Note: this actually tries to detect snap-aim. - if(vlen(self.anticheat_div0_strafebot_forward_prev) && time > self.anticheat_fixangle_endtime) { - float cosangle = self.anticheat_div0_strafebot_forward_prev * v_forward; + if(CS(this).anticheat_div0_strafebot_forward_prev && time > CS(this).anticheat_fixangle_endtime) { + float cosangle = CS(this).anticheat_div0_strafebot_forward_prev * v_forward; float angle = cosangle < -1 ? M_PI : cosangle > 1 ? 0 : acos(cosangle); /* if (angle >= 10 * M_PI / 180) - printf("SNAP %s: %f for %f, %f since fixangle\n", self.netname, angle * 180 / M_PI, cosangle, time - self.anticheat_fixangle_endtime); + printf("SNAP %s: %f for %f, %f since fixangle\n", this.netname, angle * 180 / M_PI, cosangle, time - CS(this).anticheat_fixangle_endtime); */ - MEAN_ACCUMULATE(anticheat_div0_strafebot_new, angle / M_PI, 1); + MEAN_ACCUMULATE(CS(this), anticheat_div0_strafebot_new, angle / M_PI, 1); if (autocvar_slowmo > 0) { // Technically this is a NOP, as the engine should be ensuring @@ -103,151 +101,143 @@ void anticheat_physics() float dt = max(0.001, frametime) / autocvar_slowmo; float anglespeed = angle / dt; - MEAN_ACCUMULATE(anticheat_idle_snapaim_signal, anglespeed, dt); - MEAN_ACCUMULATE(anticheat_idle_snapaim_noise, anglespeed, dt); - MEAN_ACCUMULATE(anticheat_idle_snapaim_m2, anglespeed, dt); - MEAN_ACCUMULATE(anticheat_idle_snapaim_m3, anglespeed, dt); - MEAN_ACCUMULATE(anticheat_idle_snapaim_m4, anglespeed, dt); - MEAN_ACCUMULATE(anticheat_idle_snapaim_m7, anglespeed, dt); - MEAN_ACCUMULATE(anticheat_idle_snapaim_m10, anglespeed, dt); + MEAN_ACCUMULATE(CS(this), anticheat_idle_snapaim_signal, anglespeed, dt); + MEAN_ACCUMULATE(CS(this), anticheat_idle_snapaim_noise, anglespeed, dt); + MEAN_ACCUMULATE(CS(this), anticheat_idle_snapaim_m2, anglespeed, dt); + MEAN_ACCUMULATE(CS(this), anticheat_idle_snapaim_m3, anglespeed, dt); + MEAN_ACCUMULATE(CS(this), anticheat_idle_snapaim_m4, anglespeed, dt); + MEAN_ACCUMULATE(CS(this), anticheat_idle_snapaim_m7, anglespeed, dt); + MEAN_ACCUMULATE(CS(this), anticheat_idle_snapaim_m10, anglespeed, dt); } } - self.anticheat_div0_strafebot_forward_prev = v_forward; + CS(this).anticheat_div0_strafebot_forward_prev = v_forward; // generic speedhack detection: correlate anticheat_speedhack_movetime (UPDATED BEFORE THIS) and server time - self.anticheat_speedhack_movetime_frac += frametime; - f = floor(self.anticheat_speedhack_movetime_frac); - self.anticheat_speedhack_movetime_frac -= f; - self.anticheat_speedhack_movetime_count += f; - self.anticheat_speedhack_movetime = self.anticheat_speedhack_movetime_frac + self.anticheat_speedhack_movetime_count; - f = self.anticheat_speedhack_movetime - servertime; - if(self.anticheat_speedhack_offset == 0) - self.anticheat_speedhack_offset = f; + CS(this).anticheat_speedhack_movetime_frac += frametime; + f = floor(CS(this).anticheat_speedhack_movetime_frac); + CS(this).anticheat_speedhack_movetime_frac -= f; + CS(this).anticheat_speedhack_movetime_count += f; + CS(this).anticheat_speedhack_movetime = CS(this).anticheat_speedhack_movetime_frac + CS(this).anticheat_speedhack_movetime_count; + f = CS(this).anticheat_speedhack_movetime - servertime; + if(CS(this).anticheat_speedhack_offset == 0) + CS(this).anticheat_speedhack_offset = f; else { - MEAN_ACCUMULATE(anticheat_speedhack, max(0, f - self.anticheat_speedhack_offset), 1); - self.anticheat_speedhack_offset += (f - self.anticheat_speedhack_offset) * frametime * 0.1; + MEAN_ACCUMULATE(CS(this), anticheat_speedhack, max(0, f - CS(this).anticheat_speedhack_offset), 1); + CS(this).anticheat_speedhack_offset += (f - CS(this).anticheat_speedhack_offset) * frametime * 0.1; } // new generic speedhack detection - if (self.anticheat_speedhack_lasttime > 0) { - float dt = servertime - self.anticheat_speedhack_lasttime; + if (CS(this).anticheat_speedhack_lasttime > 0) { + float dt = servertime - CS(this).anticheat_speedhack_lasttime; const float falloff = 0.2; - self.anticheat_speedhack_accu *= exp(-dt * falloff); - self.anticheat_speedhack_accu += frametime * falloff; + CS(this).anticheat_speedhack_accu *= exp(-dt * falloff); + CS(this).anticheat_speedhack_accu += frametime * falloff; // NOTE: at cl_netfps x, this actually averages not to 1, but to 1/x * falloff / (1 - exp(-1/x * falloff)) // For 15 netfps (absolute minimum bearable), and 0.2 falloff, this is: 1.0067 - self.anticheat_speedhack_lasttime = servertime; - MEAN_ACCUMULATE(anticheat_speedhack_m1, self.anticheat_speedhack_accu, frametime); - MEAN_ACCUMULATE(anticheat_speedhack_m2, self.anticheat_speedhack_accu, frametime); - MEAN_ACCUMULATE(anticheat_speedhack_m3, self.anticheat_speedhack_accu, frametime); - MEAN_ACCUMULATE(anticheat_speedhack_m4, self.anticheat_speedhack_accu, frametime); - MEAN_ACCUMULATE(anticheat_speedhack_m5, self.anticheat_speedhack_accu, frametime); + CS(this).anticheat_speedhack_lasttime = servertime; + MEAN_ACCUMULATE(CS(this), anticheat_speedhack_m1, CS(this).anticheat_speedhack_accu, frametime); + MEAN_ACCUMULATE(CS(this), anticheat_speedhack_m2, CS(this).anticheat_speedhack_accu, frametime); + MEAN_ACCUMULATE(CS(this), anticheat_speedhack_m3, CS(this).anticheat_speedhack_accu, frametime); + MEAN_ACCUMULATE(CS(this), anticheat_speedhack_m4, CS(this).anticheat_speedhack_accu, frametime); + MEAN_ACCUMULATE(CS(this), anticheat_speedhack_m5, CS(this).anticheat_speedhack_accu, frametime); } else { - self.anticheat_speedhack_accu = 1; - self.anticheat_speedhack_lasttime = servertime; + CS(this).anticheat_speedhack_accu = 1; + CS(this).anticheat_speedhack_lasttime = servertime; } } -void anticheat_spectatecopy(entity spectatee) +void anticheat_spectatecopy(entity this, entity spectatee) { // div0_evade -> SPECTATORS - self.angles = spectatee.anticheat_div0_evade_v_angle; + this.angles = CS(spectatee).anticheat_div0_evade_v_angle; } -void anticheat_prethink() +void anticheat_prethink(entity this) { // div0_evade -> SPECTATORS - self.anticheat_div0_evade_offset = 0; + 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() -{ +#define ANTICHEATS(ANTICHEAT) \ + ANTICHEAT("speedhack", MEAN_EVALUATE(CS(this), anticheat_speedhack), 240, 0, 9999); /* Actually this one seems broken. */ \ + ANTICHEAT("speedhack_m1", MEAN_EVALUATE(CS(this), anticheat_speedhack_m1), 240, 1.01, 1.25); \ + ANTICHEAT("speedhack_m2", MEAN_EVALUATE(CS(this), anticheat_speedhack_m2), 240, 1.01, 1.25); \ + ANTICHEAT("speedhack_m3", MEAN_EVALUATE(CS(this), anticheat_speedhack_m3), 240, 1.01, 1.25); \ + ANTICHEAT("speedhack_m4", MEAN_EVALUATE(CS(this), anticheat_speedhack_m4), 240, 1.01, 1.25); \ + ANTICHEAT("speedhack_m5", MEAN_EVALUATE(CS(this), anticheat_speedhack_m5), 240, 1.01, 1.25); \ + ANTICHEAT("div0_strafebot_old", MEAN_EVALUATE(CS(this), anticheat_div0_strafebot_old), 120, 0.15, 0.4); \ + ANTICHEAT("div0_strafebot_new", MEAN_EVALUATE(CS(this), anticheat_div0_strafebot_new), 120, 0.25, 0.8); \ + ANTICHEAT("div0_evade", MEAN_EVALUATE(CS(this), anticheat_div0_evade), 120, 0.2, 0.5); \ + ANTICHEAT("idle_snapaim", MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_signal) - MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_noise), 120, 0, 9999); \ + ANTICHEAT("idle_snapaim_signal", MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_signal), 120, 0, 9999); \ + ANTICHEAT("idle_snapaim_noise", MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_noise), 120, 0, 9999); \ + ANTICHEAT("idle_snapaim_m2", MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_m2), 120, 0, 9999); \ + ANTICHEAT("idle_snapaim_m3", MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_m3), 120, 0, 9999); \ + ANTICHEAT("idle_snapaim_m4", MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_m4), 120, 0, 9999); \ + ANTICHEAT("idle_snapaim_m7", MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_m7), 120, 0, 9999); \ + ANTICHEAT("idle_snapaim_m10", MEAN_EVALUATE(CS(this), anticheat_idle_snapaim_m10), 120, 0, 9999) + +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(self.playerid), ":", ftos(servertime - self.anticheat_jointime))); - GameLogEcho(strcat(":anticheat:speedhack:", ftos(self.playerid), ":", anticheat_display(MEAN_EVALUATE(anticheat_speedhack), 240, 0, 9999))); // Actually this one seems broken. - GameLogEcho(strcat(":anticheat:speedhack_m1:", ftos(self.playerid), ":", anticheat_display(MEAN_EVALUATE(anticheat_speedhack_m1), 240, 1.01, 1.25))); - GameLogEcho(strcat(":anticheat:speedhack_m2:", ftos(self.playerid), ":", anticheat_display(MEAN_EVALUATE(anticheat_speedhack_m2), 240, 1.01, 1.25))); - GameLogEcho(strcat(":anticheat:speedhack_m3:", ftos(self.playerid), ":", anticheat_display(MEAN_EVALUATE(anticheat_speedhack_m3), 240, 1.01, 1.25))); - GameLogEcho(strcat(":anticheat:speedhack_m4:", ftos(self.playerid), ":", anticheat_display(MEAN_EVALUATE(anticheat_speedhack_m4), 240, 1.01, 1.25))); - GameLogEcho(strcat(":anticheat:speedhack_m5:", ftos(self.playerid), ":", anticheat_display(MEAN_EVALUATE(anticheat_speedhack_m5), 240, 1.01, 1.25))); - GameLogEcho(strcat(":anticheat:div0_strafebot_old:", ftos(self.playerid), ":", anticheat_display(MEAN_EVALUATE(anticheat_div0_strafebot_old), 120, 0.15, 0.4))); - GameLogEcho(strcat(":anticheat:div0_strafebot_new:", ftos(self.playerid), ":", anticheat_display(MEAN_EVALUATE(anticheat_div0_strafebot_new), 120, 0.25, 0.8))); - GameLogEcho(strcat(":anticheat:div0_evade:", ftos(self.playerid), ":", anticheat_display(MEAN_EVALUATE(anticheat_div0_evade), 120, 0.2, 0.5))); - GameLogEcho(strcat(":anticheat:idle_snapaim:", ftos(self.playerid), ":", anticheat_display(MEAN_EVALUATE(anticheat_idle_snapaim_signal) - MEAN_EVALUATE(anticheat_idle_snapaim_noise), 120, 0, 9999))); - GameLogEcho(strcat(":anticheat:idle_snapaim_signal:", ftos(self.playerid), ":", anticheat_display(MEAN_EVALUATE(anticheat_idle_snapaim_signal), 120, 0, 9999))); - GameLogEcho(strcat(":anticheat:idle_snapaim_noise:", ftos(self.playerid), ":", anticheat_display(MEAN_EVALUATE(anticheat_idle_snapaim_noise), 120, 0, 9999))); - GameLogEcho(strcat(":anticheat:idle_snapaim_m2:", ftos(self.playerid), ":", anticheat_display(MEAN_EVALUATE(anticheat_idle_snapaim_m2), 120, 0, 9999))); - GameLogEcho(strcat(":anticheat:idle_snapaim_m3:", ftos(self.playerid), ":", anticheat_display(MEAN_EVALUATE(anticheat_idle_snapaim_m3), 120, 0, 9999))); - GameLogEcho(strcat(":anticheat:idle_snapaim_m4:", ftos(self.playerid), ":", anticheat_display(MEAN_EVALUATE(anticheat_idle_snapaim_m4), 120, 0, 9999))); - GameLogEcho(strcat(":anticheat:idle_snapaim_m7:", ftos(self.playerid), ":", anticheat_display(MEAN_EVALUATE(anticheat_idle_snapaim_m7), 120, 0, 9999))); - GameLogEcho(strcat(":anticheat:idle_snapaim_m10:", ftos(self.playerid), ":", anticheat_display(MEAN_EVALUATE(anticheat_idle_snapaim_m10), 120, 0, 9999))); + GameLogEcho(strcat(":anticheat:_time:", ftos(this.playerid), ":", ftos(servertime - CS(this).anticheat_jointime))); +#define ANTICHEAT_REPORT_ONE(name, f, tmin, mi, ma) \ + GameLogEcho(strcat(":anticheat:", name, ":", anticheat_display(f, servertime - CS(this).anticheat_jointime, tmin, mi, ma))) + ANTICHEATS(ANTICHEAT_REPORT_ONE); +#undef ANTICHEAT_REPORT_ONE } -float anticheat_getvalue(string id) -{ - switch(id) { - case "_time": return servertime - self.anticheat_jointime; - case "speedhack": return MEAN_EVALUATE(anticheat_speedhack); - case "speedhack_m1": return MEAN_EVALUATE(anticheat_speedhack_m1); - case "speedhack_m2": return MEAN_EVALUATE(anticheat_speedhack_m2); - case "speedhack_m3": return MEAN_EVALUATE(anticheat_speedhack_m3); - case "speedhack_m4": return MEAN_EVALUATE(anticheat_speedhack_m4); - case "speedhack_m5": return MEAN_EVALUATE(anticheat_speedhack_m5); - case "div0_strafebot_old": return MEAN_EVALUATE(anticheat_div0_strafebot_old); - case "div0_strafebot_new": return MEAN_EVALUATE(anticheat_div0_strafebot_new); - case "div0_evade": return MEAN_EVALUATE(anticheat_div0_evade); - case "idle_snapaim": return MEAN_EVALUATE(anticheat_idle_snapaim_signal) - MEAN_EVALUATE(anticheat_idle_snapaim_noise); - case "idle_snapaim_signal": return MEAN_EVALUATE(anticheat_idle_snapaim_signal); - case "idle_snapaim_noise": return MEAN_EVALUATE(anticheat_idle_snapaim_noise); - case "idle_snapaim_m2": return MEAN_EVALUATE(anticheat_idle_snapaim_m2); - case "idle_snapaim_m3": return MEAN_EVALUATE(anticheat_idle_snapaim_m3); - case "idle_snapaim_m4": return MEAN_EVALUATE(anticheat_idle_snapaim_m4); - case "idle_snapaim_m7": return MEAN_EVALUATE(anticheat_idle_snapaim_m7); - case "idle_snapaim_m10": return MEAN_EVALUATE(anticheat_idle_snapaim_m10); - } - return -1; +void anticheat_report_to_playerstats(entity this) { + PlayerStats_GameReport_Event_Player(this, + strcat(PLAYERSTATS_ANTICHEAT, "_time"), servertime - CS(this).anticheat_jointime); +#define ANTICHEAT_REPORT_ONE(name, f, tmin, mi, ma) \ + PlayerStats_GameReport_Event_Player(this, strcat(PLAYERSTATS_ANTICHEAT, name), f) + ANTICHEATS(ANTICHEAT_REPORT_ONE); +#undef ANTICHEAT_REPORT_ONE } +void anticheat_register_to_playerstats() { + PlayerStats_GameReport_AddEvent(strcat(PLAYERSTATS_ANTICHEAT, "_time")); +#define ANTICHEAT_REGISTER_ONE(name, unused_f, unused_tmin, unused_mi, unused_ma) \ + PlayerStats_GameReport_AddEvent(strcat(PLAYERSTATS_ANTICHEAT, name)) + ANTICHEATS(ANTICHEAT_REGISTER_ONE); +#undef ANTICHEAT_REGISTER_ONE +} + +#undef ANTICHEATS + void anticheat_startframe() { anticheat_div0_evade_evasion_delta += frametime * (0.5 + random()); } -void anticheat_fixangle() +void anticheat_fixangle(entity this) { - self.anticheat_fixangle_endtime = servertime + ANTILAG_LATENCY(self) + 0.2; + CS(this).anticheat_fixangle_endtime = servertime + ANTILAG_LATENCY(this) + 0.2; } void anticheat_endframe() { - entity oldself = self; - FOR_EACH_CLIENT(self) - if (self.fixangle) - anticheat_fixangle(); - self = oldself; + FOREACH_CLIENT(it.fixangle, anticheat_fixangle(it)); anticheat_div0_evade_evasion_delta += frametime * (0.5 + random()); } -void anticheat_init() -{ - self.anticheat_speedhack_offset = 0; - self.anticheat_jointime = servertime; -} - -void anticheat_shutdown() +void anticheat_init(entity this) { + CS(this).anticheat_speedhack_offset = 0; + CS(this).anticheat_jointime = servertime; }