r3139 - trunk/data/qcsrc/server

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Sun Jan 13 18:49:50 EST 2008


Author: div0
Date: 2008-01-13 18:49:50 -0500 (Sun, 13 Jan 2008)
New Revision: 3139

Added:
   trunk/data/qcsrc/server/antilag.qc
   trunk/data/qcsrc/server/antilag.qh
Modified:
   trunk/data/qcsrc/server/cl_client.qc
   trunk/data/qcsrc/server/cl_weaponsystem.qc
   trunk/data/qcsrc/server/progs.src
Log:
antilag with "ghost traces". Should still work (hopefully), but should no longer be vulnerable against antilag aimbot


Added: trunk/data/qcsrc/server/antilag.qc
===================================================================
--- trunk/data/qcsrc/server/antilag.qc	                        (rev 0)
+++ trunk/data/qcsrc/server/antilag.qc	2008-01-13 23:49:50 UTC (rev 3139)
@@ -0,0 +1,80 @@
+#define ANTILAG_MAX_ORIGINS 256
+.vector antilag_origins[ANTILAG_MAX_ORIGINS];
+.float antilag_times[ANTILAG_MAX_ORIGINS];
+.float antilag_index;
+.vector antilag_saved_origin;
+
+.float antilag_debug;
+
+void antilag_dummy()
+{
+	self.antilag_times = 0;
+	self.antilag_origins = '0 0 0';
+}
+
+void antilag_record(entity e)
+{
+	if(time < e.(antilag_times[e.antilag_index]))
+		return;
+	e.antilag_index = e.antilag_index + 1;
+	if(e.antilag_index >= ANTILAG_MAX_ORIGINS)
+		e.antilag_index = 0;
+	e.(antilag_times[e.antilag_index]) = time;
+	e.(antilag_origins[e.antilag_index]) = e.origin;
+
+	if(e.antilag_debug)
+		te_spark(antilag_takebackorigin(e, time - e.antilag_debug), '0 0 0', 32);
+}
+
+// finds the index BEFORE t
+float antilag_find(entity e, float t)
+{
+	float i;
+
+	for(i = e.antilag_index; i > 0; --i)
+		if(e.(antilag_times[i]) >= t)
+			if(e.(antilag_times[i - 1]) < t)
+				return i - 1;
+
+	if(e.(antilag_times[0]) >= t)
+		if(e.(antilag_times[ANTILAG_MAX_ORIGINS - 1]) < t)
+			return ANTILAG_MAX_ORIGINS - 1;
+
+	for(i = ANTILAG_MAX_ORIGINS - 1; i > e.antilag_index + 1; --i)
+		if(e.(antilag_times[i]) >= t)
+			if(e.(antilag_times[i - 1]) < t)
+				return i - 1;
+
+	// if we get here, t is sandwiched nowhere, so let's assume it's in the present
+	return -1;
+}
+
+vector lerp(float t0, vector v0, float t1, vector v1, float t)
+{
+	return v0 + (v1 - v0) * ((t - t0) / (t1 - t0));
+}
+
+vector antilag_takebackorigin(entity e, float t)
+{
+	float i0, i1;
+
+	i0 = antilag_find(e, t);
+	if(i0 < 0)
+		return e.origin;
+	i1 = i0 + 1;
+	if(i1 >= ANTILAG_MAX_ORIGINS)
+		i1 = 0;
+
+	return lerp(e.(antilag_times[i0]), e.(antilag_origins[i0]), e.(antilag_times[i1]), e.(antilag_origins[i1]), t);
+}
+
+void antilag_takeback(entity e, float t)
+{
+	e.antilag_saved_origin = e.origin;
+	e.origin = antilag_takebackorigin(e, t);
+}
+
+void antilag_restore(entity e)
+{
+	e.origin = e.antilag_saved_origin;
+}

Added: trunk/data/qcsrc/server/antilag.qh
===================================================================
--- trunk/data/qcsrc/server/antilag.qh	                        (rev 0)
+++ trunk/data/qcsrc/server/antilag.qh	2008-01-13 23:49:50 UTC (rev 3139)
@@ -0,0 +1,5 @@
+void antilag_record(entity e);
+float antilag_find(entity e, float t);
+vector antilag_takebackorigin(entity e, float t);
+void antilag_takeback(entity e, float t);
+void antilag_restore(entity e);

Modified: trunk/data/qcsrc/server/cl_client.qc
===================================================================
--- trunk/data/qcsrc/server/cl_client.qc	2008-01-13 15:02:09 UTC (rev 3138)
+++ trunk/data/qcsrc/server/cl_client.qc	2008-01-13 23:49:50 UTC (rev 3139)
@@ -1274,6 +1274,8 @@
 {
 	float f;
 
+	antilag_record(self);
+
 	// version nagging
 	if(self.version_nagtime)
 		if(self.cvar_g_nexuizversion)

Modified: trunk/data/qcsrc/server/cl_weaponsystem.qc
===================================================================
--- trunk/data/qcsrc/server/cl_weaponsystem.qc	2008-01-13 15:02:09 UTC (rev 3138)
+++ trunk/data/qcsrc/server/cl_weaponsystem.qc	2008-01-13 23:49:50 UTC (rev 3139)
@@ -45,6 +45,7 @@
 	// damage to the real player
 	if (antilag)
 	if (self.cursor_trace_ent)                 // client was aiming at someone
+	if (self.cursor_trace_ent != self)         // just to make sure
 	if (self.cursor_trace_ent.takedamage)      // and that person is killable
 	if (cvar("g_antilag"))
 	{
@@ -56,7 +57,27 @@
 			// verify that the shot would hit if altered
 			traceline_hitcorpse(self, w_shotorg, self.cursor_trace_ent.origin, MOVE_NORMAL, self);
 			if (trace_ent == self.cursor_trace_ent)
-				w_shotdir = normalize(self.cursor_trace_ent.origin - w_shotorg);
+			{
+				// verify that the shot would hit in the past
+				antilag_takeback(self,                  time - self.ping * 0.001);
+				antilag_takeback(self.cursor_trace_ent, time - self.ping * 0.001);
+
+				//te_spark(self.origin, '0 0 0', 1000);
+				//te_spark(self.cursor_trace_ent.origin, '0 0 0', 1000);
+
+				traceline_hitcorpse(self, self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, self);
+
+				antilag_restore(self);
+				antilag_restore(self.cursor_trace_ent);
+
+				if(trace_ent == self.cursor_trace_ent)
+					w_shotdir = normalize(self.cursor_trace_ent.origin - w_shotorg);
+				else
+				{
+					// wallhack or odd network conditions
+					dprint("WARNING: antilag ghost trace for ", self.netname, " failed!\n");
+				}
+			}
 		}
 	}
 

Modified: trunk/data/qcsrc/server/progs.src
===================================================================
--- trunk/data/qcsrc/server/progs.src	2008-01-13 15:02:09 UTC (rev 3138)
+++ trunk/data/qcsrc/server/progs.src	2008-01-13 23:49:50 UTC (rev 3139)
@@ -18,6 +18,8 @@
 
 keyhunt.qh
 
+antilag.qh
+
 miscfunctions.qc
 
 waypointsprites.qc
@@ -69,9 +71,11 @@
 cl_weapons.qc
 //g_tetris.qc
 cl_impulse.qc
+
 cl_player.qc
 cl_client.qc
 t_plats.qc
+antilag.qc
 
 ctf.qc
 domination.qc




More information about the nexuiz-commits mailing list