4 void SV_StartDemoRecording(client_t *client, const char *filename, int forcetrack)
8 if(client->sv_demo_file != NULL)
9 return; // we already have a demo
11 strlcpy(name, filename, sizeof(name));
12 FS_DefaultExtension(name, ".dem", sizeof(name));
14 Con_Printf("Recording demo for # %d (%s) to %s\n", PRVM_NUM_FOR_EDICT(client->edict), client->netaddress, name);
16 client->sv_demo_file = FS_Open(name, "wb", false, false);
17 if(!client->sv_demo_file)
19 Con_Print("ERROR: couldn't open.\n");
23 FS_Printf(client->sv_demo_file, "%i\n", forcetrack);
26 void SV_WriteDemoMessage(client_t *client, sizebuf_t *sendbuffer)
31 if(client->sv_demo_file == NULL)
33 if(sendbuffer->cursize == 0)
36 len = LittleLong(sendbuffer->cursize);
37 FS_Write(client->sv_demo_file, &len, 4);
38 for(i = 0; i < 3; ++i)
40 f = LittleFloat(client->edict->fields.server->v_angle[i]);
41 FS_Write(client->sv_demo_file, &f, 4);
43 FS_Write(client->sv_demo_file, sendbuffer->data, sendbuffer->cursize);
46 void SV_StopDemoRecording(client_t *client)
49 unsigned char bufdata[64];
51 if(client->sv_demo_file == NULL)
55 buf.maxsize = sizeof(bufdata);
57 MSG_WriteByte(&buf, svc_disconnect);
58 SV_WriteDemoMessage(client, &buf);
60 FS_Close(client->sv_demo_file);
61 client->sv_demo_file = NULL;
62 Con_Printf("Stopped recording demo for # %d (%s)\n", PRVM_NUM_FOR_EDICT(client->edict), client->netaddress);
65 void SV_WriteNetnameIntoDemo(client_t *client)
67 // This "pseudo packet" is written so a program can easily find out whose demo this is
69 unsigned char bufdata[128];
71 if(client->sv_demo_file == NULL)
75 buf.maxsize = sizeof(bufdata);
77 MSG_WriteByte(&buf, svc_stufftext);
78 MSG_WriteUnterminatedString(&buf, "\n// this demo contains the point of view of: ");
79 MSG_WriteUnterminatedString(&buf, client->name);
80 MSG_WriteString(&buf, "\n");
81 SV_WriteDemoMessage(client, &buf);