]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_demo.c
customizable loading screen picture scale, including limiting to screen bounds in...
[xonotic/darkplaces.git] / sv_demo.c
index 3ba4349a47f58923acaea273fd39094a129a4a8e..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,7 +16,11 @@ 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);
 
-       client->sv_demo_file = FS_Open(name, "wb", false, false);
+       // 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)
        {
                Con_Print("ERROR: couldn't open.\n");
@@ -23,17 +30,19 @@ 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;
+       int temp;
 
        if(client->sv_demo_file == NULL)
                return;
        if(sendbuffer->cursize == 0)
                return;
        
-       len = LittleLong(sendbuffer->cursize);
+       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)
        {
@@ -47,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;
@@ -55,11 +65,18 @@ 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);
+
+       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)
@@ -78,5 +95,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);
 }