4 extern cvar_t sv_autodemo_perclient_discardable;
6 void SV_StartDemoRecording(client_t *client, const char *filename, int forcetrack)
10 if(client->sv_demo_file != NULL)
11 return; // we already have a demo
13 strlcpy(name, filename, sizeof(name));
14 FS_DefaultExtension(name, ".dem", sizeof(name));
16 Con_Printf("Recording demo for # %d (%s) to %s\n", PRVM_NUM_FOR_EDICT(client->edict), client->netaddress, name);
18 // Reset discardable flag for every new demo.
19 PRVM_serveredictfloat(client->edict, discardabledemo) = 0;
21 client->sv_demo_file = FS_OpenRealFile(name, "wb", false);
22 if(!client->sv_demo_file)
24 Con_Print("ERROR: couldn't open.\n");
28 FS_Printf(client->sv_demo_file, "%i\n", forcetrack);
31 void SV_WriteDemoMessage(client_t *client, sizebuf_t *sendbuffer, qboolean clienttoserver)
37 if(client->sv_demo_file == NULL)
39 if(sendbuffer->cursize == 0)
42 temp = sendbuffer->cursize | (clienttoserver ? DEMOMSG_CLIENT_TO_SERVER : 0);
43 len = LittleLong(temp);
44 FS_Write(client->sv_demo_file, &len, 4);
45 for(i = 0; i < 3; ++i)
47 f = LittleFloat(PRVM_serveredictvector(client->edict, v_angle)[i]);
48 FS_Write(client->sv_demo_file, &f, 4);
50 FS_Write(client->sv_demo_file, sendbuffer->data, sendbuffer->cursize);
53 void SV_StopDemoRecording(client_t *client)
56 unsigned char bufdata[64];
58 if(client->sv_demo_file == NULL)
62 buf.maxsize = sizeof(bufdata);
64 MSG_WriteByte(&buf, svc_disconnect);
65 SV_WriteDemoMessage(client, &buf, false);
67 if (sv_autodemo_perclient_discardable.integer && PRVM_serveredictfloat(client->edict, discardabledemo))
69 FS_RemoveOnClose(client->sv_demo_file);
70 Con_Printf("Stopped recording discardable demo for # %d (%s)\n", PRVM_NUM_FOR_EDICT(client->edict), client->netaddress);
73 Con_Printf("Stopped recording demo for # %d (%s)\n", PRVM_NUM_FOR_EDICT(client->edict), client->netaddress);
75 FS_Close(client->sv_demo_file);
76 client->sv_demo_file = NULL;
79 void SV_WriteNetnameIntoDemo(client_t *client)
81 // This "pseudo packet" is written so a program can easily find out whose demo this is
83 unsigned char bufdata[128];
85 if(client->sv_demo_file == NULL)
89 buf.maxsize = sizeof(bufdata);
91 MSG_WriteByte(&buf, svc_stufftext);
92 MSG_WriteUnterminatedString(&buf, "\n// this demo contains the point of view of: ");
93 MSG_WriteUnterminatedString(&buf, client->name);
94 MSG_WriteString(&buf, "\n");
95 SV_WriteDemoMessage(client, &buf, false);