]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_demo.c
reworked PRVM_EDICTFIELD* and PRVM_GLOBALFIELD* usage to have more
[xonotic/darkplaces.git] / sv_demo.c
index c56274709e0bfb26166125af8e6467bdc4f60e98..c237f2f43a4b649189779509c179fe6cca596306 100644 (file)
--- a/sv_demo.c
+++ b/sv_demo.c
@@ -1,6 +1,8 @@
 #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];
@@ -13,6 +15,9 @@ 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.
+       PRVM_serveredictfloat(client->edict, discardabledemo) = 0;
+
        client->sv_demo_file = FS_OpenRealFile(name, "wb", false);
        if(!client->sv_demo_file)
        {
@@ -27,13 +32,15 @@ void SV_WriteDemoMessage(client_t *client, sizebuf_t *sendbuffer, qboolean clien
 {
        int len, i;
        float f;
+       int temp;
 
        if(client->sv_demo_file == NULL)
                return;
        if(sendbuffer->cursize == 0)
                return;
        
-       len = LittleLong(sendbuffer->cursize | (clienttoserver ? DEMOMSG_CLIENT_TO_SERVER : 0));
+       temp = sendbuffer->cursize | (clienttoserver ? DEMOMSG_CLIENT_TO_SERVER : 0);
+       len = LittleLong(temp);
        FS_Write(client->sv_demo_file, &len, 4);
        for(i = 0; i < 3; ++i)
        {
@@ -57,9 +64,16 @@ void SV_StopDemoRecording(client_t *client)
        MSG_WriteByte(&buf, svc_disconnect);
        SV_WriteDemoMessage(client, &buf, false);
 
+       if (sv_autodemo_perclient_discardable.integer && PRVM_serveredictfloat(client->edict, discardabledemo))
+       {
+               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)