Quake II RTX doxygen  1.0 dev
client.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2003-2006 Andrey Nazarov
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18 
19 #include "../server.h"
20 #include <setjmp.h>
21 
22 #define MVD_Malloc(size) Z_TagMalloc(size, TAG_MVD)
23 #define MVD_Mallocz(size) Z_TagMallocz(size, TAG_MVD)
24 #define MVD_CopyString(s) Z_TagCopyString(s, TAG_MVD)
25 
26 #define FOR_EACH_MVD(mvd) \
27  LIST_FOR_EACH(mvd_t, mvd, &mvd_channel_list, entry)
28 
29 #define FOR_EACH_MVDCL(cl, mvd) \
30  LIST_FOR_EACH(mvd_client_t, cl, &(mvd)->clients, entry)
31 
32 #define EDICT_MVDCL(ent) ((mvd_client_t *)((ent)->client))
33 #define CS_NUM(c, n) ((char *)(c) + (n) * MAX_QPATH)
34 
35 #define MVD_InfoSet(var, val) \
36  Cvar_FullSet(var, val, CVAR_SERVERINFO | CVAR_GAME, FROM_CODE)
37 
38 // game features MVD client supports
39 #define MVD_FEATURES (GMF_CLIENTNUM | GMF_PROPERINUSE | GMF_WANT_ALL_DISCONNECTS)
40 
41 #define LAYOUT_MSEC 3000
42 
43 typedef enum {
44  LAYOUT_NONE, // no layout at all
45  LAYOUT_FOLLOW, // display chase target name
46  LAYOUT_SCORES, // layout of the MVD dummy
47  LAYOUT_OLDSCORES, // saved at intermission time
48  LAYOUT_MENU, // MVD main menu
49  LAYOUT_CLIENTS, // MVD clients list
50  LAYOUT_CHANNELS // MVD channel list
51 } mvd_layout_t;
52 
53 #define FLOOD_SAMPLES 16
54 #define FLOOD_MASK (FLOOD_SAMPLES - 1)
55 
56 typedef struct mvd_cs_s {
57  struct mvd_cs_s *next;
58  int index;
59  char string[1];
60 } mvd_cs_t;
61 
62 typedef struct {
63  player_state_t ps;
64  qboolean inuse;
65  char name[16];
67 } mvd_player_t;
68 
69 typedef struct {
70  /* =================== */
71  player_state_t ps;
72  int ping;
73  int clientNum;
74  /* =================== */
75 
76  list_t entry;
77  struct mvd_s *mvd;
79  qboolean admin;
80  qboolean notified;
81  unsigned begin_time;
82  float fov;
83  int uf;
84 
88  qboolean chase_auto;
89  qboolean chase_wait;
90  byte chase_bitmap[MAX_CLIENTS / CHAR_BIT];
91 
93  unsigned layout_time;
95 
96  unsigned floodSamples[FLOOD_SAMPLES];
97  unsigned floodHead;
98  unsigned floodTime;
99 
100  usercmd_t lastcmd;
101  //short delta_angles[3];
103 } mvd_client_t;
104 
105 #define MAX_MVD_NAME 16
106 
107 typedef enum {
108  MVD_DEAD, // no gamestate received yet, unusable for observers
109  MVD_WAITING, // buffering more frames, stalled
110  MVD_READING, // reading frames
111 
113 } mvd_state_t;
114 
115 typedef struct {
116  list_t entry;
117  int framenum;
118  off_t filepos;
119  size_t msglen;
120  byte data[1];
121 } mvd_snap_t;
122 
123 struct gtv_s;
124 
125 // FIXME: entire struct is > 500 kB in size!
126 // need to eliminate those large static arrays below...
127 typedef struct mvd_s {
128  list_t entry;
129 
131  int id;
133  struct gtv_s *gtv;
134  qboolean (*read_frame)(struct mvd_s *);
135  qboolean (*forward_cmd)(mvd_client_t *);
136 
137  // demo related variables
138  qhandle_t demorecording;
139  char *demoname;
140  qboolean demoseeking;
142  list_t snapshots;
143 
144  // delay buffer
145  fifo_t delay;
146  size_t msglen;
149  int framenum;
150 
151  // game state
152  char gamedir[MAX_QPATH];
153  char mapname[MAX_QPATH];
156  edict_pool_t pool;
157  cm_t cm;
158  vec3_t spawnOrigin;
159  vec3_t spawnAngles;
160  int pm_type;
161  byte dcs[CS_BITMAP_BYTES];
162  char baseconfigstrings[MAX_CONFIGSTRINGS][MAX_QPATH];
163  char configstrings[MAX_CONFIGSTRINGS][MAX_QPATH];
164  edict_t edicts[MAX_EDICTS];
165  mvd_player_t *players; // [maxclients]
166  mvd_player_t *dummy; // &players[clientNum]
167  int numplayers; // number of active players in frame
169  mvd_flags_t flags;
170  char layout[MAX_NET_STRING];
171  char oldscores[MAX_NET_STRING]; // layout is copied here
172  qboolean intermission;
173  qboolean dirty;
174 
175  // UDP client list
176  list_t clients;
177 } mvd_t;
178 
179 
180 //
181 // mvd_client.c
182 //
183 
184 extern list_t mvd_channel_list;
185 extern mvd_t mvd_waitingRoom;
186 extern qboolean mvd_dirty;
187 
188 extern qboolean mvd_active;
189 extern unsigned mvd_last_activity;
190 
191 extern jmp_buf mvd_jmpbuf;
192 
193 #ifdef _DEBUG
194 extern cvar_t *mvd_shownet;
195 #endif
196 
197 void MVD_Destroyf(mvd_t *mvd, const char *fmt, ...) q_noreturn q_printf(2, 3);
198 void MVD_Shutdown(void);
199 
200 mvd_t *MVD_SetChannel(int arg);
201 
202 void MVD_File_g(genctx_t *ctx);
203 
204 void MVD_Spawn(void);
205 
206 void MVD_StopRecord(mvd_t *mvd);
207 
208 void MVD_StreamedStop_f(void);
209 void MVD_StreamedRecord_f(void);
210 
211 void MVD_Register(void);
212 int MVD_Frame(void);
213 
214 //
215 // mvd_parse.c
216 //
217 
218 qboolean MVD_ParseMessage(mvd_t *mvd);
219 void MVD_ParseEntityString(mvd_t *mvd, const char *data);
220 void MVD_ClearState(mvd_t *mvd, qboolean full);
221 
222 //
223 // mvd_game.c
224 //
225 
226 extern mvd_client_t *mvd_clients; // [maxclients]
227 
228 void MVD_SwitchChannel(mvd_client_t *client, mvd_t *mvd);
229 void MVD_RemoveClient(client_t *client);
231  int mask, const char *fmt, ...) q_printf(4, 5);
232 void MVD_PrepWorldFrame(void);
233 void MVD_GameClientNameChanged(edict_t *ent, const char *name);
234 void MVD_GameClientDrop(edict_t *ent, const char *prefix, const char *reason);
236 void MVD_FreePlayer(mvd_player_t *player);
237 void MVD_UpdateConfigstring(mvd_t *mvd, int index);
239 void MVD_LinkEdict(mvd_t *mvd, edict_t *ent);
240 
FLOOD_SAMPLES
#define FLOOD_SAMPLES
Definition: client.h:53
mvd_client_t::ping
int ping
Definition: client.h:72
mvd_player_t::configstrings
mvd_cs_t * configstrings
Definition: client.h:66
MVD_Spawn
void MVD_Spawn(void)
Definition: client.c:1653
MVD_StopRecord
void MVD_StopRecord(mvd_t *mvd)
Definition: client.c:125
mvd_channel_list
list_t mvd_channel_list
MVD_NUM_STATES
@ MVD_NUM_STATES
Definition: client.h:112
mvd_client_t::layout_time
unsigned layout_time
Definition: client.h:93
mvd_layout_t
mvd_layout_t
Definition: client.h:43
mvd_s::pm_type
int pm_type
Definition: client.h:160
mvd_s::servercount
int servercount
Definition: client.h:154
mvd_client_t::layout_cursor
int layout_cursor
Definition: client.h:94
mvd_client_t::begin_time
unsigned begin_time
Definition: client.h:81
MVD_DEAD
@ MVD_DEAD
Definition: client.h:108
MVD_Register
void MVD_Register(void)
Definition: client.c:2582
mvd_s::cm
cm_t cm
Definition: client.h:157
MVD_GameClientNameChanged
void MVD_GameClientNameChanged(edict_t *ent, const char *name)
Definition: game.c:1922
mvd_s::dirty
qboolean dirty
Definition: client.h:173
MVD_StreamedRecord_f
void MVD_StreamedRecord_f(void)
Definition: client.c:1896
LAYOUT_CHANNELS
@ LAYOUT_CHANNELS
Definition: client.h:50
mvd_client_t::lastcmd
usercmd_t lastcmd
Definition: client.h:100
mvd_client_t::admin
qboolean admin
Definition: client.h:79
mvd_waitingRoom
mvd_t mvd_waitingRoom
Definition: client.c:101
mvd_s::numplayers
int numplayers
Definition: client.h:167
mvd_s::flags
mvd_flags_t flags
Definition: client.h:169
mvd_client_t::chase_mask
int chase_mask
Definition: client.h:87
mvd_client_t::floodTime
unsigned floodTime
Definition: client.h:98
mvd_jmpbuf
jmp_buf mvd_jmpbuf
Definition: client.c:108
gtv_s
Definition: client.c:46
mvd_s::underflows
unsigned underflows
Definition: client.h:148
mvd_s::read_frame
qboolean(* read_frame)(struct mvd_s *)
Definition: client.h:134
mvd_s::demoseeking
qboolean demoseeking
Definition: client.h:140
mvd_s::gamedir
char gamedir[MAX_QPATH]
Definition: client.h:152
MVD_UpdateConfigstring
void MVD_UpdateConfigstring(mvd_t *mvd, int index)
Definition: game.c:1616
mvd_s::spawnOrigin
vec3_t spawnOrigin
Definition: client.h:158
mvd_client_t::notified
qboolean notified
Definition: client.h:80
LAYOUT_SCORES
@ LAYOUT_SCORES
Definition: client.h:46
mvd_snap_t::framenum
int framenum
Definition: client.h:117
mvd_s::dcs
byte dcs[CS_BITMAP_BYTES]
Definition: client.h:161
mvd_snap_t
Definition: client.h:115
mvd_client_t::entry
list_t entry
Definition: client.h:76
mvd_client_t::layout_type
mvd_layout_t layout_type
Definition: client.h:92
LAYOUT_CLIENTS
@ LAYOUT_CLIENTS
Definition: client.h:49
mvd_s::id
int id
Definition: client.h:131
mvd_active
qboolean mvd_active
Definition: client.c:105
mvd_dirty
qboolean mvd_dirty
Definition: client.c:102
mvd_s::last_snapshot
int last_snapshot
Definition: client.h:141
mvd_client_t::uf
int uf
Definition: client.h:83
LAYOUT_FOLLOW
@ LAYOUT_FOLLOW
Definition: client.h:45
MVD_ParseEntityString
void MVD_ParseEntityString(mvd_t *mvd, const char *data)
Definition: parse.c:64
mvd_cs_s::index
int index
Definition: client.h:58
mvd_s::overflows
unsigned overflows
Definition: client.h:148
mvd_client_t::mvd
struct mvd_s * mvd
Definition: client.h:77
mvd_client_t::clientNum
int clientNum
Definition: client.h:73
mvd_s::state
mvd_state_t state
Definition: client.h:130
MVD_PrepWorldFrame
void void MVD_PrepWorldFrame(void)
Definition: game.c:2263
MVD_ParseMessage
qboolean MVD_ParseMessage(mvd_t *mvd)
Definition: parse.c:1098
mvd_player_t::inuse
qboolean inuse
Definition: client.h:64
mvd_s
Definition: client.h:127
mvd_t
struct mvd_s mvd_t
mvd_s::gtv
struct gtv_s * gtv
Definition: client.h:133
mvd_s::maxclients
int maxclients
Definition: client.h:155
mvd
static mvd_server_t mvd
Definition: mvd.c:81
mvd_client_t::target
mvd_player_t * target
Definition: client.h:85
mvd_s::delay
fifo_t delay
Definition: client.h:145
mvd_s::forward_cmd
qboolean(* forward_cmd)(mvd_client_t *)
Definition: client.h:135
mvd_state_t
mvd_state_t
Definition: client.h:107
MVD_StreamedStop_f
void MVD_StreamedStop_f(void)
Definition: client.c:1778
mvd_s::configstrings
char configstrings[MAX_CONFIGSTRINGS][MAX_QPATH]
Definition: client.h:163
mvd_s::intermission
qboolean intermission
Definition: client.h:172
mvd_s::num_packets
unsigned num_packets
Definition: client.h:147
mvd_s::players
mvd_player_t * players
Definition: client.h:165
mvd_s::mapname
char mapname[MAX_QPATH]
Definition: client.h:153
MAX_MVD_NAME
#define MAX_MVD_NAME
Definition: client.h:105
MVD_GameClientDrop
void MVD_GameClientDrop(edict_t *ent, const char *prefix, const char *reason)
Definition: game.c:1934
LAYOUT_NONE
@ LAYOUT_NONE
Definition: client.h:44
mvd_s::msglen
size_t msglen
Definition: client.h:146
mvd_last_activity
unsigned mvd_last_activity
Definition: client.c:106
mvd_s::dummy
mvd_player_t * dummy
Definition: client.h:166
mvd_client_t::oldtarget
mvd_player_t * oldtarget
Definition: client.h:86
MVD_SetChannel
mvd_t * MVD_SetChannel(int arg)
Definition: client.c:230
mvd_cs_t
struct mvd_cs_s mvd_cs_t
mvd_client_t::cl
client_t * cl
Definition: client.h:78
MVD_WAITING
@ MVD_WAITING
Definition: client.h:109
mvd_client_t
Definition: client.h:69
MVD_LinkEdict
void MVD_LinkEdict(mvd_t *mvd, edict_t *ent)
Definition: game.c:1652
mvd_client_t::jump_held
int jump_held
Definition: client.h:102
MVD_Shutdown
void void MVD_Shutdown(void)
Definition: client.c:2528
MVD_SetPlayerNames
void MVD_SetPlayerNames(mvd_t *mvd)
Definition: game.c:1607
mvd_snap_t::msglen
size_t msglen
Definition: client.h:119
MVD_READING
@ MVD_READING
Definition: client.h:110
mvd_client_t::ps
player_state_t ps
Definition: client.h:71
mvd_s::name
char name[MAX_MVD_NAME]
Definition: client.h:132
LAYOUT_MENU
@ LAYOUT_MENU
Definition: client.h:48
MVD_File_g
void MVD_File_g(genctx_t *ctx)
Definition: client.c:2406
mvd_cs_s
Definition: client.h:56
mvd_client_t::chase_auto
qboolean chase_auto
Definition: client.h:88
mvd_s::layout
char layout[MAX_NET_STRING]
Definition: client.h:170
mvd_client_t::chase_wait
qboolean chase_wait
Definition: client.h:89
MVD_SwitchChannel
void MVD_SwitchChannel(mvd_client_t *client, mvd_t *mvd)
Definition: game.c:765
mvd_s::clients
list_t clients
Definition: client.h:176
mvd_player_t
Definition: client.h:62
MVD_UpdateClients
void MVD_UpdateClients(mvd_t *mvd)
Definition: game.c:2175
MVD_ClearState
void MVD_ClearState(mvd_t *mvd, qboolean full)
Definition: parse.c:856
mvd_s::clientNum
int clientNum
Definition: client.h:168
mvd_snap_t::filepos
off_t filepos
Definition: client.h:118
MVD_Frame
int MVD_Frame(void)
Definition: client.c:406
q_printf
static void q_printf(2, 3)
Definition: files.c:2516
mvd_cs_s::next
struct mvd_cs_s * next
Definition: client.h:57
LAYOUT_OLDSCORES
@ LAYOUT_OLDSCORES
Definition: client.h:47
level
level_locals_t level
Definition: g_main.c:22
mvd_client_t::floodHead
unsigned floodHead
Definition: client.h:97
client_s
Definition: server.h:256
mvd_s::pool
edict_pool_t pool
Definition: client.h:156
mvd_s::oldscores
char oldscores[MAX_NET_STRING]
Definition: client.h:171
mvd_s::edicts
edict_t edicts[MAX_EDICTS]
Definition: client.h:164
mvd_s::spawnAngles
vec3_t spawnAngles
Definition: client.h:159
MVD_BroadcastPrintf
void MVD_BroadcastPrintf(mvd_t *mvd, int level, int mask, const char *fmt,...) q_printf(4
MVD_FreePlayer
void MVD_FreePlayer(mvd_player_t *player)
Definition: game.c:1540
mvd_s::framenum
int framenum
Definition: client.h:149
mvd_s::snapshots
list_t snapshots
Definition: client.h:142
MVD_RemoveClient
void MVD_RemoveClient(client_t *client)
Definition: game.c:1685
mvd_client_t::fov
float fov
Definition: client.h:82
mvd_s::demorecording
qhandle_t demorecording
Definition: client.h:138
mvd_snap_t::entry
list_t entry
Definition: client.h:116
mvd_s::demoname
char * demoname
Definition: client.h:139
MVD_Destroyf
void MVD_Destroyf(mvd_t *mvd, const char *fmt,...) q_noreturn q_printf(2
mvd_player_t::ps
player_state_t ps
Definition: client.h:63
mvd_s::min_packets
unsigned min_packets
Definition: client.h:147
mvd_s::baseconfigstrings
char baseconfigstrings[MAX_CONFIGSTRINGS][MAX_QPATH]
Definition: client.h:162
mvd_s::entry
list_t entry
Definition: client.h:128
mvd_clients
mvd_client_t * mvd_clients
Definition: game.c:37