4 extern cvar_t sv_autodemo_perclient_discardable;
6 void SV_StartDemoRecording(client_t *client, const char *filename, int forcetrack)
8 prvm_prog_t *prog = SVVM_prog;
11 if(client->sv_demo_file != NULL)
12 return; // we already have a demo
14 strlcpy(name, filename, sizeof(name));
15 FS_DefaultExtension(name, ".dem", sizeof(name));
17 Con_Printf("Recording demo for # %d (%s) to %s\n", PRVM_NUM_FOR_EDICT(client->edict), client->netaddress, name);
19 // Reset discardable flag for every new demo.
20 PRVM_serveredictfloat(client->edict, discardabledemo) = 0;
22 client->sv_demo_file = FS_OpenRealFile(name, "wb", false);
23 if(!client->sv_demo_file)
25 Con_Error("ERROR: couldn't open.\n");
29 FS_Printf(client->sv_demo_file, "%i\n", forcetrack);
32 void SV_WriteDemoMessage(client_t *client, sizebuf_t *sendbuffer, qboolean clienttoserver)
34 prvm_prog_t *prog = SVVM_prog;
39 if(client->sv_demo_file == NULL)
41 if(sendbuffer->cursize == 0)
44 temp = sendbuffer->cursize | (clienttoserver ? DEMOMSG_CLIENT_TO_SERVER : 0);
45 len = LittleLong(temp);
46 FS_Write(client->sv_demo_file, &len, 4);
47 for(i = 0; i < 3; ++i)
49 f = LittleFloat(PRVM_serveredictvector(client->edict, v_angle)[i]);
50 FS_Write(client->sv_demo_file, &f, 4);
52 FS_Write(client->sv_demo_file, sendbuffer->data, sendbuffer->cursize);
55 void SV_StopDemoRecording(client_t *client)
57 prvm_prog_t *prog = SVVM_prog;
59 unsigned char bufdata[64];
61 if(client->sv_demo_file == NULL)
65 buf.maxsize = sizeof(bufdata);
67 MSG_WriteByte(&buf, svc_disconnect);
68 SV_WriteDemoMessage(client, &buf, false);
70 if (sv_autodemo_perclient_discardable.integer && PRVM_serveredictfloat(client->edict, discardabledemo))
72 FS_RemoveOnClose(client->sv_demo_file);
73 Con_Printf("Stopped recording discardable demo for # %d (%s)\n", PRVM_NUM_FOR_EDICT(client->edict), client->netaddress);
76 Con_Printf("Stopped recording demo for # %d (%s)\n", PRVM_NUM_FOR_EDICT(client->edict), client->netaddress);
78 FS_Close(client->sv_demo_file);
79 client->sv_demo_file = NULL;
82 void SV_WriteNetnameIntoDemo(client_t *client)
84 // This "pseudo packet" is written so a program can easily find out whose demo this is
86 unsigned char bufdata[MAX_SCOREBOARDNAME + 64];
88 if(client->sv_demo_file == NULL)
92 buf.maxsize = sizeof(bufdata);
94 MSG_WriteByte(&buf, svc_stufftext);
95 MSG_WriteUnterminatedString(&buf, "\n// this demo contains the point of view of: ");
96 MSG_WriteUnterminatedString(&buf, client->name);
97 MSG_WriteString(&buf, "\n");
98 SV_WriteDemoMessage(client, &buf, false);