From ffffe657727890724cd57beecc8d34cf33154746 Mon Sep 17 00:00:00 2001 From: divverent Date: Mon, 28 Jan 2008 09:40:11 +0000 Subject: [PATCH] add a DEMOMSG_CLIENT_TO_SERVER flag to demos (0x80000000) in the size field; packets with this flag will be ignored by playback. sv_autodemo_perclient 2 will record these packages for debugging purposes (like, recording a speedhacker's or other protocol exploiter's packets, and analyzing them with the data in the demo file manually) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8032 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_demo.c | 2 ++ quakedef.h | 5 +++++ sv_demo.c | 8 ++++---- sv_demo.h | 2 +- sv_main.c | 6 +++--- sv_user.c | 5 +++++ 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/cl_demo.c b/cl_demo.c index 9d8e4a00..50a23fc6 100644 --- a/cl_demo.c +++ b/cl_demo.c @@ -186,6 +186,8 @@ void CL_ReadDemoMessage(void) // get the next message FS_Read(cls.demofile, &net_message.cursize, 4); net_message.cursize = LittleLong(net_message.cursize); + if(net_message.cursize & DEMOMSG_CLIENT_TO_SERVER) // This is a client->server message! Ignore for now! + continue; if (net_message.cursize > net_message.maxsize) Host_Error("Demo message (%i) > net_message.maxsize (%i)", net_message.cursize, net_message.maxsize); VectorCopy(cl.mviewangles[0], cl.mviewangles[1]); diff --git a/quakedef.h b/quakedef.h index 87643cad..efc228a0 100644 --- a/quakedef.h +++ b/quakedef.h @@ -345,5 +345,10 @@ float noise4f(float x, float y, float z, float w); void Sys_Shared_Init(void); +// Flag in size field of demos to indicate a client->server packet. Demo +// playback will ignore this, but it may be useful to make DP sniff packets to +// debug protocol exploits. +#define DEMOMSG_CLIENT_TO_SERVER 0x80000000 + #endif diff --git a/sv_demo.c b/sv_demo.c index 3ba4349a..d8f2bea9 100644 --- a/sv_demo.c +++ b/sv_demo.c @@ -23,7 +23,7 @@ void SV_StartDemoRecording(client_t *client, const char *filename, int forcetrac FS_Printf(client->sv_demo_file, "%i\n", forcetrack); } -void SV_WriteDemoMessage(client_t *client, sizebuf_t *sendbuffer) +void SV_WriteDemoMessage(client_t *client, sizebuf_t *sendbuffer, qboolean clienttoserver) { int len, i; float f; @@ -33,7 +33,7 @@ void SV_WriteDemoMessage(client_t *client, sizebuf_t *sendbuffer) if(sendbuffer->cursize == 0) return; - len = LittleLong(sendbuffer->cursize); + len = LittleLong(sendbuffer->cursize | (clienttoserver ? DEMOMSG_CLIENT_TO_SERVER : 0)); FS_Write(client->sv_demo_file, &len, 4); for(i = 0; i < 3; ++i) { @@ -55,7 +55,7 @@ void SV_StopDemoRecording(client_t *client) buf.maxsize = sizeof(bufdata); SZ_Clear(&buf); MSG_WriteByte(&buf, svc_disconnect); - SV_WriteDemoMessage(client, &buf); + SV_WriteDemoMessage(client, &buf, false); FS_Close(client->sv_demo_file); client->sv_demo_file = NULL; @@ -78,5 +78,5 @@ void SV_WriteNetnameIntoDemo(client_t *client) MSG_WriteUnterminatedString(&buf, "\n// this demo contains the point of view of: "); MSG_WriteUnterminatedString(&buf, client->name); MSG_WriteString(&buf, "\n"); - SV_WriteDemoMessage(client, &buf); + SV_WriteDemoMessage(client, &buf, false); } diff --git a/sv_demo.h b/sv_demo.h index ad26d9d4..65c19248 100644 --- a/sv_demo.h +++ b/sv_demo.h @@ -2,7 +2,7 @@ #define SV_DEMO_H void SV_StartDemoRecording(client_t *client, const char *filename, int forcetrack); -void SV_WriteDemoMessage(client_t *client, sizebuf_t *sendbuffer); +void SV_WriteDemoMessage(client_t *client, sizebuf_t *sendbuffer, qboolean clienttoserver); void SV_StopDemoRecording(client_t *client); void SV_WriteNetnameIntoDemo(client_t *client); diff --git a/sv_main.c b/sv_main.c index 4fadaff3..a15f914c 100644 --- a/sv_main.c +++ b/sv_main.c @@ -148,7 +148,7 @@ cvar_t nehx18 = {0, "nehx18", "0", "nehahra data storage cvar (used in singlepla cvar_t nehx19 = {0, "nehx19", "0", "nehahra data storage cvar (used in singleplayer)"}; cvar_t cutscene = {0, "cutscene", "1", "enables cutscenes in nehahra, can be used by other mods"}; -cvar_t sv_autodemo_perclient = {CVAR_SAVE, "sv_autodemo_perclient", "0", "set to 1 to enable autorecorded per-client demos (they'll start to record at the beginning of a match)"}; +cvar_t sv_autodemo_perclient = {CVAR_SAVE, "sv_autodemo_perclient", "0", "set to 1 to enable autorecorded per-client demos (they'll start to record at the beginning of a match); set it to 2 to also record client->server packets (for debugging)"}; cvar_t sv_autodemo_perclient_nameformat = {CVAR_SAVE, "sv_autodemo_perclient_nameformat", "sv_autodemos/%Y-%m-%d_%H-%M", "The format of the sv_autodemo_perclient filename, followed by the map name, the IP address + port number, and the client number, separated by underscores" }; @@ -1864,9 +1864,9 @@ static void SV_SendClientDatagram (client_t *client) // reliable only if none is in progress if(client->sendsignon != 2 && !client->netconnection->sendMessageLength) - SV_WriteDemoMessage(client, &(client->netconnection->message)); + SV_WriteDemoMessage(client, &(client->netconnection->message), false); // unreliable - SV_WriteDemoMessage(client, &msg); + SV_WriteDemoMessage(client, &msg, false); // send the datagram NetConn_SendUnreliableMessage (client->netconnection, &msg, sv.protocol, clientrate, client->sendsignon == 2); diff --git a/sv_user.c b/sv_user.c index 279c0367..0bc1090f 100644 --- a/sv_user.c +++ b/sv_user.c @@ -20,9 +20,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // sv_user.c -- server code for moving users #include "quakedef.h" +#include "sv_demo.h" #define DEBUGMOVES 0 static usercmd_t cmd; +extern cvar_t sv_autodemo_perclient; /* =============== @@ -729,6 +731,9 @@ void SV_ReadClientMessage(void) int cmd, num, start; char *s, *p, *q; + if(sv_autodemo_perclient.integer >= 2) + SV_WriteDemoMessage(host_client, &(host_client->netconnection->message), true); + //MSG_BeginReading (); sv_numreadmoves = 0; -- 2.39.2