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_OpenRealFile(name, "wb", 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, qboolean clienttoserver)
32 if(client->sv_demo_file == NULL)
34 if(sendbuffer->cursize == 0)
37 temp = sendbuffer->cursize | (clienttoserver ? DEMOMSG_CLIENT_TO_SERVER : 0);
38 len = LittleLong(temp);
39 FS_Write(client->sv_demo_file, &len, 4);
40 for(i = 0; i < 3; ++i)
42 f = LittleFloat(client->edict->fields.server->v_angle[i]);
43 FS_Write(client->sv_demo_file, &f, 4);
45 FS_Write(client->sv_demo_file, sendbuffer->data, sendbuffer->cursize);
48 void SV_StopDemoRecording(client_t *client)
51 unsigned char bufdata[64];
53 if(client->sv_demo_file == NULL)
57 buf.maxsize = sizeof(bufdata);
59 MSG_WriteByte(&buf, svc_disconnect);
60 SV_WriteDemoMessage(client, &buf, false);
62 FS_Close(client->sv_demo_file);
63 client->sv_demo_file = NULL;
64 Con_Printf("Stopped recording demo for # %d (%s)\n", PRVM_NUM_FOR_EDICT(client->edict), client->netaddress);
67 void SV_WriteNetnameIntoDemo(client_t *client)
69 // This "pseudo packet" is written so a program can easily find out whose demo this is
71 unsigned char bufdata[128];
73 if(client->sv_demo_file == NULL)
77 buf.maxsize = sizeof(bufdata);
79 MSG_WriteByte(&buf, svc_stufftext);
80 MSG_WriteUnterminatedString(&buf, "\n// this demo contains the point of view of: ");
81 MSG_WriteUnterminatedString(&buf, client->name);
82 MSG_WriteString(&buf, "\n");
83 SV_WriteDemoMessage(client, &buf, false);