]> git.xonotic.org Git - xonotic/darkplaces.git/blob - sv_demo.c
replaced host_sleep with cl_maxfps_alwayssleep cvar (requires cl_maxfps)
[xonotic/darkplaces.git] / sv_demo.c
1 #include "quakedef.h"
2 #include "sv_demo.h"
3
4 void SV_StartDemoRecording(client_t *client, const char *filename, int forcetrack)
5 {
6         char name[MAX_QPATH];
7
8         if(client->sv_demo_file != NULL)
9                 return; // we already have a demo
10
11         strlcpy(name, filename, sizeof(name));
12         FS_DefaultExtension(name, ".dem", sizeof(name));
13
14         Con_Printf("Recording demo for # %d (%s) to %s\n", PRVM_NUM_FOR_EDICT(client->edict), client->netaddress, name);
15
16         client->sv_demo_file = FS_OpenRealFile(name, "wb", false);
17         if(!client->sv_demo_file)
18         {
19                 Con_Print("ERROR: couldn't open.\n");
20                 return;
21         }
22
23         FS_Printf(client->sv_demo_file, "%i\n", forcetrack);
24 }
25
26 void SV_WriteDemoMessage(client_t *client, sizebuf_t *sendbuffer, qboolean clienttoserver)
27 {
28         int len, i;
29         float f;
30
31         if(client->sv_demo_file == NULL)
32                 return;
33         if(sendbuffer->cursize == 0)
34                 return;
35         
36         len = LittleLong(sendbuffer->cursize | (clienttoserver ? DEMOMSG_CLIENT_TO_SERVER : 0));
37         FS_Write(client->sv_demo_file, &len, 4);
38         for(i = 0; i < 3; ++i)
39         {
40                 f = LittleFloat(client->edict->fields.server->v_angle[i]);
41                 FS_Write(client->sv_demo_file, &f, 4);
42         }
43         FS_Write(client->sv_demo_file, sendbuffer->data, sendbuffer->cursize);
44 }
45
46 void SV_StopDemoRecording(client_t *client)
47 {
48         sizebuf_t buf;
49         unsigned char bufdata[64];
50
51         if(client->sv_demo_file == NULL)
52                 return;
53         
54         buf.data = bufdata;
55         buf.maxsize = sizeof(bufdata);
56         SZ_Clear(&buf);
57         MSG_WriteByte(&buf, svc_disconnect);
58         SV_WriteDemoMessage(client, &buf, false);
59
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);
63 }
64
65 void SV_WriteNetnameIntoDemo(client_t *client)
66 {
67         // This "pseudo packet" is written so a program can easily find out whose demo this is
68         sizebuf_t buf;
69         unsigned char bufdata[128];
70
71         if(client->sv_demo_file == NULL)
72                 return;
73
74         buf.data = bufdata;
75         buf.maxsize = sizeof(bufdata);
76         SZ_Clear(&buf);
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, false);
82 }