]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Add QC/cfg facilities to control deletion of automatically recorded demos
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 2 May 2010 12:16:28 +0000 (12:16 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 2 May 2010 12:16:28 +0000 (12:16 +0000)
This patch adds two new cvars, cl_autodemo_delete and
sv_autodemo_perclient_discardable, as well as an entity field for use
by game code, .float discardabledemo.  See the cvar descriptions for
more details.

From: Jānis Rūcis <parasti@gmail.com>

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10112 d7cf8633-e32d-0410-b094-e92efae38249

cl_demo.c
cl_main.c
cl_parse.c
client.h
fs.c
fs.h
progsvm.h
prvm_edict.c
sv_demo.c
sv_main.c

index 08f84745425d26fcecda08795abe157d892298bf..7b678b7f0d22d925b203ddd9f41e39278bed0af7 100644 (file)
--- a/cl_demo.c
+++ b/cl_demo.c
@@ -306,10 +306,16 @@ void CL_Stop_f (void)
        CL_WriteDemoMessage(&buf);
 
 // finish up
+       if (cl_autodemo.integer && ((cl_autodemo_delete.integer & 1) ^ ((cl_autodemo_delete.integer >> 1) & 1))) // bit 0 XOR bit 1
+       {
+               FS_RemoveOnClose(cls.demofile);
+               Con_Print("Completed and deleted demo\n");
+       }
+       else
+               Con_Print("Completed demo\n");
        FS_Close (cls.demofile);
        cls.demofile = NULL;
        cls.demorecording = false;
-       Con_Print("Completed demo\n");
 }
 
 /*
index 66964ea40117fd0d42ee6ce31123a2aa7dc026f2..a254ca58cfcaae4d2d8a434f0c24ead0aac495fa 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -57,6 +57,7 @@ cvar_t freelook = {CVAR_SAVE, "freelook", "1","mouse controls pitch instead of f
 
 cvar_t cl_autodemo = {CVAR_SAVE, "cl_autodemo", "0", "records every game played, using the date/time and map name to name the demo file" };
 cvar_t cl_autodemo_nameformat = {CVAR_SAVE, "cl_autodemo_nameformat", "autodemos/%Y-%m-%d_%H-%M", "The format of the cl_autodemo filename, followed by the map name (the date is encoded using strftime escapes)" };
+cvar_t cl_autodemo_delete = {0, "cl_autodemo_delete", "0", "Delete demos after recording.  This is a bitmask, bit 1 gives the default, bit 0 inverts the meaning of bit 1 for the current demo.  Thus, the values are: 0 = disabled; 1 = delete current demo only; 2 = delete all demos from this point on; 3 = delete all demos except the current demo" };
 
 cvar_t r_draweffects = {0, "r_draweffects", "1","renders temporary sprite effects"};
 
@@ -2380,6 +2381,7 @@ void CL_Init (void)
 
        Cvar_RegisterVariable (&cl_autodemo);
        Cvar_RegisterVariable (&cl_autodemo_nameformat);
+       Cvar_RegisterVariable (&cl_autodemo_delete);
 
        Cmd_AddCommand ("fog", CL_Fog_f, "set global fog parameters (density red green blue [alpha [mindist [maxdist [top [fadedepth]]]]])");
        Cmd_AddCommand ("fog_heighttexture", CL_Fog_HeightTexture_f, "set global fog parameters (density red green blue alpha mindist maxdist top depth textures/mapname/fogheight.tga)");
index 96109e54948b1fcba542e8fc2d676129aeb46144..2adedb050c896969682842c01e324cb4ae8abb27 100644 (file)
@@ -1828,6 +1828,9 @@ void CL_ParseServerInfo (void)
 
                Con_Printf ("Auto-recording to %s.\n", demofile);
 
+               // Clear the invert flag for every new demo
+               Cvar_SetValueQuick(&cl_autodemo_delete, cl_autodemo_delete.integer & ~0x1);
+
                cls.demofile = FS_OpenRealFile(demofile, "wb", false);
                if (cls.demofile)
                {
index e177b76ea43137a2540acbee18fb82c3b2ea261a..69c2fcc13fbd5e9426fc2a8ce8c841d6fced041f 100644 (file)
--- a/client.h
+++ b/client.h
@@ -1276,6 +1276,7 @@ extern cvar_t m_side;
 
 extern cvar_t cl_autodemo;
 extern cvar_t cl_autodemo_nameformat;
+extern cvar_t cl_autodemo_delete;
 
 extern cvar_t r_draweffects;
 
diff --git a/fs.c b/fs.c
index 40f78f0a49fabbf7e33ef6eeed8db9f82cf84a6c..01581988d6a9af760e0a57660afcadb77d749ed2 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -188,6 +188,8 @@ typedef struct
 #define QFILE_FLAG_DEFLATED (1 << 1)
 /// file is actually already loaded data
 #define QFILE_FLAG_DATA (1 << 2)
+/// real file will be removed on close
+#define QFILE_FLAG_REMOVE (1 << 3)
 
 #define FILE_BUFF_SIZE 2048
 typedef struct
@@ -215,6 +217,8 @@ struct qfile_s
        ztoolkit_t*             ztk;    ///< For zipped files.
 
        const unsigned char *data;      ///< For data files.
+
+       const char *filename; ///< Kept around for QFILE_FLAG_REMOVE, unused otherwise
 };
 
 
@@ -1924,6 +1928,8 @@ static qfile_t* FS_SysOpen (const char* filepath, const char* mode, qboolean non
                return NULL;
        }
 
+       file->filename = Mem_strdup(fs_mempool, filepath);
+
        file->real_length = lseek (file->handle, 0, SEEK_END);
 
        // For files opened in append mode, we start at the end of the file
@@ -2389,6 +2395,14 @@ int FS_Close (qfile_t* file)
        if (close (file->handle))
                return EOF;
 
+       if (file->filename)
+       {
+               if (file->flags & QFILE_FLAG_REMOVE)
+                       remove(file->filename);
+
+               Mem_Free((void *) file->filename);
+       }
+
        if (file->ztk)
        {
                qz_inflateEnd (&file->ztk->zstream);
@@ -2399,6 +2413,10 @@ int FS_Close (qfile_t* file)
        return 0;
 }
 
+void FS_RemoveOnClose(qfile_t* file)
+{
+       file->flags |= QFILE_FLAG_REMOVE;
+}
 
 /*
 ====================
diff --git a/fs.h b/fs.h
index 65ee54ec474386f6f3be778fee52094e279588ad..f8d813cb1e768afcbe5be399234e0ec871fb1ec2 100644 (file)
--- a/fs.h
+++ b/fs.h
@@ -62,6 +62,7 @@ qfile_t* FS_OpenRealFile (const char* filepath, const char* mode, qboolean quiet
 qfile_t* FS_OpenVirtualFile (const char* filepath, qboolean quiet);
 qfile_t* FS_FileFromData (const unsigned char *data, const size_t size, qboolean quiet);
 int FS_Close (qfile_t* file);
+void FS_RemoveOnClose(qfile_t* file);
 fs_offset_t FS_Write (qfile_t* file, const void* data, size_t datasize);
 fs_offset_t FS_Read (qfile_t* file, void* buffer, size_t buffersize);
 int FS_Print(qfile_t* file, const char *msg);
index dc7f192a4a5f3a581ca3dadceefefb2a04476909..ddbd75d025f5c58248a2db7942408b5ee079fb98 100644 (file)
--- a/progsvm.h
+++ b/progsvm.h
@@ -187,6 +187,7 @@ typedef struct prvm_prog_fieldoffsets_s
        int dimension_hit; // ssqc / csqc
        int dimension_solid; // ssqc / csqc
        int disableclientprediction; // ssqc
+       int discardabledemo; // ssqc
        int dphitcontentsmask; // ssqc / csqc
        int drawonlytoclient; // ssqc
        int effects; // ssqc / csqc
index 56a1e3f400219b15af2753006ade47e4f816b3a9..56171616d5c04cc5c73782f55de881813827323a 100644 (file)
@@ -1575,6 +1575,7 @@ void PRVM_FindOffsets(void)
        prog->fieldoffsets.dimension_hit                  = PRVM_ED_FindFieldOffset("dimension_hit");
        prog->fieldoffsets.dimension_solid                = PRVM_ED_FindFieldOffset("dimension_solid");
        prog->fieldoffsets.disableclientprediction        = PRVM_ED_FindFieldOffset("disableclientprediction");
+       prog->fieldoffsets.discardabledemo                = PRVM_ED_FindFieldOffset("discardabledemo");
        prog->fieldoffsets.dphitcontentsmask              = PRVM_ED_FindFieldOffset("dphitcontentsmask");
        prog->fieldoffsets.drawonlytoclient               = PRVM_ED_FindFieldOffset("drawonlytoclient");
        prog->fieldoffsets.exteriormodeltoclient          = PRVM_ED_FindFieldOffset("exteriormodeltoclient");
index 81f169bb64b067a7ee5a065d157e964f13284bd6..acea7b01ed37f2665ae102de1aeb2af941a296dd 100644 (file)
--- a/sv_demo.c
+++ b/sv_demo.c
@@ -1,9 +1,12 @@
 #include "quakedef.h"
 #include "sv_demo.h"
 
+extern cvar_t sv_autodemo_perclient_discardable;
+
 void SV_StartDemoRecording(client_t *client, const char *filename, int forcetrack)
 {
        char name[MAX_QPATH];
+       prvm_eval_t *val;
 
        if(client->sv_demo_file != NULL)
                return; // we already have a demo
@@ -13,6 +16,10 @@ void SV_StartDemoRecording(client_t *client, const char *filename, int forcetrac
 
        Con_Printf("Recording demo for # %d (%s) to %s\n", PRVM_NUM_FOR_EDICT(client->edict), client->netaddress, name);
 
+       // Reset discardable flag for every new demo.
+       if ((val = PRVM_EDICTFIELDVALUE(client->edict, prog->fieldoffsets.discardabledemo)))
+               val->_float = 0;
+
        client->sv_demo_file = FS_OpenRealFile(name, "wb", false);
        if(!client->sv_demo_file)
        {
@@ -49,6 +56,7 @@ void SV_StopDemoRecording(client_t *client)
 {
        sizebuf_t buf;
        unsigned char bufdata[64];
+       prvm_eval_t *val;
 
        if(client->sv_demo_file == NULL)
                return;
@@ -59,9 +67,16 @@ void SV_StopDemoRecording(client_t *client)
        MSG_WriteByte(&buf, svc_disconnect);
        SV_WriteDemoMessage(client, &buf, false);
 
+       if (sv_autodemo_perclient_discardable.integer && (val = PRVM_EDICTFIELDVALUE(client->edict, prog->fieldoffsets.discardabledemo)) && val->_float)
+       {
+               FS_RemoveOnClose(client->sv_demo_file);
+               Con_Printf("Stopped recording discardable demo for # %d (%s)\n", PRVM_NUM_FOR_EDICT(client->edict), client->netaddress);
+       }
+       else
+               Con_Printf("Stopped recording demo for # %d (%s)\n", PRVM_NUM_FOR_EDICT(client->edict), client->netaddress);
+
        FS_Close(client->sv_demo_file);
        client->sv_demo_file = NULL;
-       Con_Printf("Stopped recording demo for # %d (%s)\n", PRVM_NUM_FOR_EDICT(client->edict), client->netaddress);
 }
 
 void SV_WriteNetnameIntoDemo(client_t *client)
index 40d7e6dde3027da56593fb8331873e83b6505dc9..cda3379f3186d89547b079e267e2d1644e8d7818 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -175,6 +175,7 @@ cvar_t cutscene = {0, "cutscene", "1", "enables cutscenes in nehahra, can be use
 
 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 client number and the IP address + port number, separated by underscores (the date is encoded using strftime escapes)" };
+cvar_t sv_autodemo_perclient_discardable = {CVAR_SAVE, "sv_autodemo_perclient_discardable", "0", "Allow game code to decide whether a demo should be kept or discarded."};
 
 cvar_t halflifebsp = {0, "halflifebsp", "0", "indicates the current map is hlbsp format (useful to know because of different bounding box sizes)"};
 
@@ -492,6 +493,7 @@ void SV_Init (void)
 
        Cvar_RegisterVariable (&sv_autodemo_perclient);
        Cvar_RegisterVariable (&sv_autodemo_perclient_nameformat);
+       Cvar_RegisterVariable (&sv_autodemo_perclient_discardable);
 
        Cvar_RegisterVariable (&halflifebsp);