DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
sv_demo.c
Go to the documentation of this file.
1#include "quakedef.h"
2#include "sv_demo.h"
3
5
6void SV_StartDemoRecording(client_t *client, const char *filename, int forcetrack)
7{
9 char name[MAX_QPATH];
10
11 if(client->sv_demo_file != NULL)
12 return; // we already have a demo
13
14 dp_strlcpy(name, filename, sizeof(name));
15 FS_DefaultExtension(name, ".dem", sizeof(name));
16
17 Con_Printf("Recording demo for # %d (%s) to %s\n", PRVM_NUM_FOR_EDICT(client->edict), client->netaddress, name);
18
19 // Reset discardable flag for every new demo.
21
22 client->sv_demo_file = FS_OpenRealFile(name, "wb", false);
23 if(!client->sv_demo_file)
24 {
25 Con_Print(CON_ERROR "ERROR: couldn't open.\n");
26 return;
27 }
28
29 FS_Printf(client->sv_demo_file, "%i\n", forcetrack);
30}
31
32void SV_WriteDemoMessage(client_t *client, sizebuf_t *sendbuffer, qbool clienttoserver)
33{
34 prvm_prog_t *prog = SVVM_prog;
35 int len, i;
36 float f;
37 int temp;
38
39 if(client->sv_demo_file == NULL)
40 return;
41 if(sendbuffer->cursize == 0)
42 return;
43
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)
48 {
50 FS_Write(client->sv_demo_file, &f, 4);
51 }
52 FS_Write(client->sv_demo_file, sendbuffer->data, sendbuffer->cursize);
53}
54
56{
57 prvm_prog_t *prog = SVVM_prog;
59 unsigned char bufdata[64];
60
61 if(client->sv_demo_file == NULL)
62 return;
63
64 buf.data = bufdata;
65 buf.maxsize = sizeof(bufdata);
66 SZ_Clear(&buf);
68 SV_WriteDemoMessage(client, &buf, false);
69
71 {
73 Con_Printf("Stopped recording discardable demo for # %d (%s)\n", PRVM_NUM_FOR_EDICT(client->edict), client->netaddress);
74 }
75 else
76 Con_Printf("Stopped recording demo for # %d (%s)\n", PRVM_NUM_FOR_EDICT(client->edict), client->netaddress);
77
78 FS_Close(client->sv_demo_file);
79 client->sv_demo_file = NULL;
80}
81
83{
84 // This "pseudo packet" is written so a program can easily find out whose demo this is
86 unsigned char bufdata[MAX_SCOREBOARDNAME + 64];
87
88 if(client->sv_demo_file == NULL)
89 return;
90
91 buf.data = bufdata;
92 buf.maxsize = sizeof(bufdata);
93 SZ_Clear(&buf);
95 MSG_WriteUnterminatedString(&buf, "\n// this demo contains the point of view of: ");
97 MSG_WriteString(&buf, "\n");
98 SV_WriteDemoMessage(client, &buf, false);
99}
void MSG_WriteString(sizebuf_t *sb, const char *s)
Definition com_msg.c:173
void MSG_WriteByte(sizebuf_t *sb, int c)
Definition com_msg.c:130
void MSG_WriteUnterminatedString(sizebuf_t *sb, const char *s)
Definition com_msg.c:181
void SZ_Clear(sizebuf_t *buf)
Definition common.c:44
#define LittleLong(l)
Definition common.h:92
#define dp_strlcpy(dst, src, dsize)
Definition common.h:303
#define LittleFloat(l)
Definition common.h:94
void Con_Print(const char *msg)
Prints to all appropriate console targets, and adds timestamps.
Definition console.c:1504
void Con_Printf(const char *fmt,...)
Prints to all appropriate console targets.
Definition console.c:1514
#define CON_ERROR
Definition console.h:102
float discardabledemo
fs_offset_t FS_Write(qfile_t *file, const void *data, size_t datasize)
Definition fs.c:3019
void FS_DefaultExtension(char *path, const char *extension, size_t size_path)
Definition fs.c:3641
qfile_t * FS_OpenRealFile(const char *filepath, const char *mode, qbool quiet)
Definition fs.c:2901
void FS_RemoveOnClose(qfile_t *file)
Definition fs.c:3007
int FS_Close(qfile_t *file)
Definition fs.c:2970
int FS_Printf(qfile_t *file, const char *format,...)
Definition fs.c:3273
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition glquake.h:657
const GLchar * name
Definition glquake.h:601
vector v_angle
Definition progsdefs.qc:161
#define PRVM_serveredictvector(ed, fieldname)
Definition progsvm.h:173
#define PRVM_NUM_FOR_EDICT(e)
Definition progsvm.h:870
#define PRVM_serveredictfloat(ed, fieldname)
Definition progsvm.h:172
#define SVVM_prog
Definition progsvm.h:766
#define svc_disconnect
Definition protocol.h:216
#define svc_stufftext
Definition protocol.h:223
int i
#define MAX_SCOREBOARDNAME
max length of player name in game
Definition qdefs.h:111
#define MAX_QPATH
max length of a quake game pathname
Definition qdefs.h:169
#define NULL
Definition qtypes.h:12
bool qbool
Definition qtypes.h:9
#define DEMOMSG_CLIENT_TO_SERVER
Definition quakedef.h:178
float f
char name[MAX_SCOREBOARDNAME]
Definition server.h:235
char netaddress[MAX_QPATH]
netaddress support
Definition server.h:242
qfile_t * sv_demo_file
demo recording
Definition server.h:297
prvm_edict_t * edict
PRVM_EDICT_NUM(clientnum+1)
Definition server.h:221
Definition cvar.h:66
int integer
Definition cvar.h:73
unsigned char * data
Definition common.h:52
int cursize
Definition common.h:54
cvar_t sv_autodemo_perclient_discardable
Definition sv_main.c:213
void SV_StopDemoRecording(client_t *client)
Definition sv_demo.c:55
void SV_WriteNetnameIntoDemo(client_t *client)
Definition sv_demo.c:82
void SV_StartDemoRecording(client_t *client, const char *filename, int forcetrack)
Definition sv_demo.c:6
void SV_WriteDemoMessage(client_t *client, sizebuf_t *sendbuffer, qbool clienttoserver)
Definition sv_demo.c:32