[nexuiz-commits] r8389 - trunk/data/qcsrc/server

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Sun Dec 13 12:11:07 EST 2009


Author: div0
Date: 2009-12-13 12:10:57 -0500 (Sun, 13 Dec 2009)
New Revision: 8389

Added:
   trunk/data/qcsrc/server/anticheat.qc
   trunk/data/qcsrc/server/anticheat.qh
Modified:
   trunk/data/qcsrc/server/cl_client.qc
   trunk/data/qcsrc/server/cl_physics.qc
   trunk/data/qcsrc/server/defs.qh
   trunk/data/qcsrc/server/gamecommand.qc
   trunk/data/qcsrc/server/progs.src
Log:
add detection code for generic speedhacks, old and new strafebot, div0 spectator evasion hack


Added: trunk/data/qcsrc/server/anticheat.qc
===================================================================
--- trunk/data/qcsrc/server/anticheat.qc	                        (rev 0)
+++ trunk/data/qcsrc/server/anticheat.qc	2009-12-13 17:10:57 UTC (rev 8389)
@@ -0,0 +1,175 @@
+void mean_accumulate(entity e, .float a, .float c, float mean, float value, float weight)
+{
+	if(weight == 0)
+		return;
+	if(mean == 0)
+		e.a *= pow(value, weight);
+	else
+		e.a += pow(value, mean) * weight;
+	e.c += weight;
+}
+
+float mean_evaluate(entity e, .float a, .float c, float mean)
+{
+	if(e.c == 0)
+		return 0;
+	if(mean == 0)
+		return pow(e.a, 1.0 / e.c);
+	else
+		return pow(e.a / e.c, 1.0 / mean);
+}
+
+#define MEAN_ACCUMULATE(prefix,v,w) mean_accumulate(self,prefix##_accumulator,prefix##_count,prefix##_mean,v,w)
+#define MEAN_EVALUATE(prefix) mean_evaluate(self,prefix##_accumulator,prefix##_count,prefix##_mean)
+#define MEAN_DECLARE(prefix,m) float prefix##_mean = m; .float prefix##_count, prefix##_accumulator
+
+float anticheat_div0_evade_evasion_delta;
+.float anticheat_div0_evade_offset;
+.vector anticheat_div0_evade_v_angle;
+.vector anticheat_div0_evade_forward_initial;
+MEAN_DECLARE(anticheat_div0_evade, 5);
+
+.vector anticheat_div0_strafebot_movement_prev;
+MEAN_DECLARE(anticheat_div0_strafebot_old, 5);
+
+.vector anticheat_div0_strafebot_forward_prev;
+MEAN_DECLARE(anticheat_div0_strafebot_new, 5);
+
+.float anticheat_speedhack_offset;
+.float anticheat_speedhack_movetime, anticheat_speedhack_movetime_count, anticheat_speedhack_movetime_frac;
+MEAN_DECLARE(anticheat_speedhack, 5);
+
+float movement_oddity(vector m0, vector m1)
+{
+	float cosangle = normalize(m0) * normalize(m1);
+	if(cosangle >= 0)
+		return 0;
+	return 0.5 - 0.5 * cos(cosangle * cosangle * 4 * M_PI);
+		// returns 0 for: -1, -sqrt(0.5), 0 (angles that commonly happen with kbd)
+}
+
+void anticheat_physics()
+{
+	float f, wishspeed;
+	vector wishvel;
+
+	// div0_evade -> SPECTATORS
+	makevectors(self.v_angle);
+	if(self.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 = time + sys_ticrate * (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);
+	}
+	else
+	{
+		if(time < self.anticheat_div0_evade_offset)
+			self.anticheat_div0_evade_v_angle = self.v_angle;
+		MEAN_ACCUMULATE(anticheat_div0_evade, 1 - (self.anticheat_div0_evade_forward_initial * v_forward), 1);
+	}
+
+	MEAN_ACCUMULATE(anticheat_div0_strafebot_old, movement_oddity(self.movement, self.anticheat_div0_strafebot_movement_prev), max(0, 0.05 - frametime));
+	self.anticheat_div0_strafebot_movement_prev = self.movement;
+
+	if(vlen(self.anticheat_div0_strafebot_forward_prev))
+		MEAN_ACCUMULATE(anticheat_div0_strafebot_new, 1 - (self.anticheat_div0_strafebot_forward_prev * v_forward), max(0, 0.05 - frametime));
+	self.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;
+	else
+	{
+		MEAN_ACCUMULATE(anticheat_speedhack, fabs(f - self.anticheat_speedhack_offset), 1);
+		self.anticheat_speedhack_offset += (f - self.anticheat_speedhack_offset) * frametime * 0.1;
+	}
+
+	// race/CTS: force kbd movement for fairness
+	if(g_race || g_cts)
+	{
+		// if record times matter
+		// ensure nothing EVIL is being done (i.e. div0_evade)
+		// this hinders joystick users though
+		// but it still gives SOME analog control
+		wishvel_x = fabs(self.movement_x);
+		wishvel_y = fabs(self.movement_y);
+		if(wishvel_x != 0 && wishvel_y != 0 && wishvel_x != wishvel_y)
+		{
+			wishvel_z = 0;
+			wishspeed = vlen(wishvel);
+			if(wishvel_x >= 2 * wishvel_y)
+			{
+				// pure X motion
+				if(self.movement_x > 0)
+					self.movement_x = wishspeed;
+				else
+					self.movement_x = -wishspeed;
+				self.movement_y = 0;
+			}
+			else if(wishvel_y >= 2 * wishvel_x)
+			{
+				// pure Y motion
+				self.movement_x = 0;
+				if(self.movement_y > 0)
+					self.movement_y = wishspeed;
+				else
+					self.movement_y = -wishspeed;
+			}
+			else
+			{
+				// diagonal
+				if(self.movement_x > 0)
+					self.movement_x = M_SQRT1_2 * wishspeed;
+				else
+					self.movement_x = -M_SQRT1_2 * wishspeed;
+				if(self.movement_y > 0)
+					self.movement_y = M_SQRT1_2 * wishspeed;
+				else
+					self.movement_y = -M_SQRT1_2 * wishspeed;
+			}
+		}
+	}
+}
+
+void anticheat_spectatecopy(entity spectatee)
+{
+	// div0_evade -> SPECTATORS
+	self.angles = spectatee.anticheat_div0_evade_v_angle;
+}
+
+void anticheat_prethink()
+{
+	// div0_evade -> SPECTATORS
+	self.anticheat_div0_evade_offset = 0;
+}
+
+void anticheat_report()
+{
+	GameLogEcho(strcat(":anticheat:speedhack:", ftos(self.playerid), ":", ftos(MEAN_EVALUATE(anticheat_speedhack))));
+	GameLogEcho(strcat(":anticheat:div0_strafebot_old:", ftos(self.playerid), ":", ftos(MEAN_EVALUATE(anticheat_div0_strafebot_old))));
+	GameLogEcho(strcat(":anticheat:div0_strafebot_new:", ftos(self.playerid), ":", ftos(MEAN_EVALUATE(anticheat_div0_strafebot_new))));
+	GameLogEcho(strcat(":anticheat:div0_evade:", ftos(self.playerid), ":", ftos(MEAN_EVALUATE(anticheat_div0_evade))));
+}
+
+void anticheat_serverframe()
+{
+	anticheat_div0_evade_evasion_delta += frametime * (0.5 + random());
+}
+
+void anticheat_init()
+{
+	self.anticheat_speedhack_offset = 0;
+}
+
+void anticheat_shutdown()
+{
+	anticheat_report();
+}

Added: trunk/data/qcsrc/server/anticheat.qh
===================================================================
--- trunk/data/qcsrc/server/anticheat.qh	                        (rev 0)
+++ trunk/data/qcsrc/server/anticheat.qh	2009-12-13 17:10:57 UTC (rev 8389)
@@ -0,0 +1,9 @@
+void anticheat_init();
+void anticheat_report();
+void anticheat_shutdown();
+
+void anticheat_physics();
+void anticheat_spectatecopy(entity spectatee);
+void anticheat_prethink();
+
+void anticheat_serverframe();

Modified: trunk/data/qcsrc/server/cl_client.qc
===================================================================
--- trunk/data/qcsrc/server/cl_client.qc	2009-12-13 15:54:52 UTC (rev 8388)
+++ trunk/data/qcsrc/server/cl_client.qc	2009-12-13 17:10:57 UTC (rev 8389)
@@ -1329,9 +1329,11 @@
 	ClientData_Attach();
 
 	bot_clientconnect();
-	
+
 	playerdemo_init();
 
+	anticheat_init();
+	
 	race_PreSpawnObserver();
 
 	//if(g_domination)
@@ -1513,6 +1515,9 @@
 		self.hitplotfh = -1;
 	}
 
+	anticheat_report();
+	anticheat_shutdown();
+
 	playerdemo_shutdown();
 
 	bot_clientdisconnect();
@@ -2096,6 +2101,8 @@
 	setorigin(self, spectatee.origin);
 	setsize(self, spectatee.mins, spectatee.maxs);
 	SetZoomState(spectatee.zoomstate);
+
+	anticheat_spectatecopy(spectatee);
 }
 
 float SpectateUpdate() {
@@ -2371,6 +2378,12 @@
 	self.stat_allow_oldnexbeam = cvar("g_allow_oldnexbeam");
 	self.stat_leadlimit = cvar("leadlimit");
 
+	if(frametime)
+	{
+		// physics frames: update anticheat stuff
+		anticheat_prethink();
+	}
+
 	if(blockSpectators && frametime)
 		// WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
 		checkSpectatorBlock();

Modified: trunk/data/qcsrc/server/cl_physics.qc
===================================================================
--- trunk/data/qcsrc/server/cl_physics.qc	2009-12-13 15:54:52 UTC (rev 8388)
+++ trunk/data/qcsrc/server/cl_physics.qc	2009-12-13 17:10:57 UTC (rev 8389)
@@ -29,10 +29,6 @@
 .float wasFlying;
 .float spectatorspeed;
 
-#define SHTEST_DELTA 10
-#define SHTEST_THRESHOLD 1.1
-.float shtest_next;
-.float shtest_accumulator;
 .float doublejump_nextjumptime;
 
 /*
@@ -542,7 +538,7 @@
 void SV_PlayerPhysics()
 {
 	local vector wishvel, wishdir, v;
-	local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, shtest_score, buttons;
+	local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, buttons;
 	string temps;
 	float buttons_prev;
 	float not_allowed_to_move;
@@ -552,58 +548,14 @@
         if(self.PlayerPhysplug())
             return;
 
-	if(g_race || g_cts)
-	{
-		// if record times matter
-		// ensure nothing EVIL is being done (i.e. strafebot)
-		// this hinders joystick users though
-		// but it still gives SOME analog control
-		// TODO implement this for engine cl_movement code too (basically, clipping to the four axes)
-		wishvel_x = fabs(self.movement_x);
-		wishvel_y = fabs(self.movement_y);
-		if(wishvel_x != 0 && wishvel_y != 0 && wishvel_x != wishvel_y)
-		{
-			wishvel_z = 0;
-			wishspeed = vlen(wishvel);
-			if(wishvel_x >= 2 * wishvel_y)
-			{
-				// pure X motion
-				if(self.movement_x > 0)
-					self.movement_x = wishspeed;
-				else
-					self.movement_x = -wishspeed;
-				self.movement_y = 0;
-			}
-			else if(wishvel_y >= 2 * wishvel_x)
-			{
-				// pure Y motion
-				self.movement_x = 0;
-				if(self.movement_y > 0)
-					self.movement_y = wishspeed;
-				else
-					self.movement_y = -wishspeed;
-			}
-			else
-			{
-				// diagonal
-				if(self.movement_x > 0)
-					self.movement_x = M_SQRT1_2 * wishspeed;
-				else
-					self.movement_x = -M_SQRT1_2 * wishspeed;
-				if(self.movement_y > 0)
-					self.movement_y = M_SQRT1_2 * wishspeed;
-				else
-					self.movement_y = -M_SQRT1_2 * wishspeed;
-			}
-		}
-	}
-
 	self.race_movetime_frac += frametime;
 	f = floor(self.race_movetime_frac);
 	self.race_movetime_frac -= f;
 	self.race_movetime_count += f;
 	self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
 
+	anticheat_physics();
+
 	buttons = self.BUTTON_ATCK + 2 * self.BUTTON_JUMP + 4 * self.BUTTON_ATCK2 + 8 * self.BUTTON_ZOOM + 16 * self.BUTTON_CROUCH + 32 * self.BUTTON_HOOK + 64 * self.BUTTON_USE + 128 * (self.movement_x < 0) + 256 * (self.movement_x > 0) + 512 * (self.movement_y < 0) + 1024 * (self.movement_y > 0);
 
 	if(!buttons)
@@ -662,24 +614,6 @@
 		}
 	}
 
-	if(time > self.shtest_next)
-	{
-		if(self.shtest_next > 0)
-		{
-			// self.shtest_accumulator:
-			//   started at time - SHTEST_DELTA
-			//   should be at SHTEST_DELTA
-			shtest_score = self.shtest_accumulator / (SHTEST_DELTA + time - self.shtest_next);
-			if(shtest_score > SHTEST_THRESHOLD)
-				print("TIME PARADOX: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
-			else if(cvar("developer_shtest"))
-				dprint("okay: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
-		}
-		self.shtest_next = time + SHTEST_DELTA;
-		self.shtest_accumulator = 0;
-	}
-	self.shtest_accumulator += frametime;
-
 	if (self.punchangle != '0 0 0')
 	{
 		f = vlen(self.punchangle) - 10 * frametime;

Modified: trunk/data/qcsrc/server/defs.qh
===================================================================
--- trunk/data/qcsrc/server/defs.qh	2009-12-13 15:54:52 UTC (rev 8388)
+++ trunk/data/qcsrc/server/defs.qh	2009-12-13 17:10:57 UTC (rev 8389)
@@ -637,4 +637,4 @@
 .float just_joined;
 
 .float cvar_cl_accuracy_data_share;
-.float cvar_cl_accuracy_data_receive;
\ No newline at end of file
+.float cvar_cl_accuracy_data_receive;

Modified: trunk/data/qcsrc/server/gamecommand.qc
===================================================================
--- trunk/data/qcsrc/server/gamecommand.qc	2009-12-13 15:54:52 UTC (rev 8388)
+++ trunk/data/qcsrc/server/gamecommand.qc	2009-12-13 17:10:57 UTC (rev 8389)
@@ -1274,6 +1274,23 @@
 		}
 	}
 
+	if(argv(0) == "anticheat")
+	{
+		entno = stof(argv(1));
+		if((entno < 1) | (entno > maxclients)) {
+			print("Player ", argv(1), " doesn't exist\n");
+			return;
+		}
+		client = edict_num(entno);
+		if(clienttype(client) != CLIENTTYPE_REAL && clienttype(client) != CLIENTTYPE_BOT) {
+			print("Player ", client.netname, " is not active\n");
+			return;
+		}
+		self = client;
+		anticheat_report();
+		return;
+	}
+
 	print("Invalid command. For a list of supported commands, try sv_cmd help.\n");
 }
 

Modified: trunk/data/qcsrc/server/progs.src
===================================================================
--- trunk/data/qcsrc/server/progs.src	2009-12-13 15:54:52 UTC (rev 8388)
+++ trunk/data/qcsrc/server/progs.src	2009-12-13 17:10:57 UTC (rev 8389)
@@ -25,6 +25,8 @@
 csqcprojectile.qh
 csqceffects.qc
 
+anticheat.qh
+
 portals.qh
 
 g_hook.qh
@@ -174,3 +176,5 @@
 ../common/mathlib.qc
 
 playerdemo.qc
+
+anticheat.qc



More information about the nexuiz-commits mailing list