icculus quake2 doxygen  1.0 dev
server.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 1997-2001 Id Software, Inc.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (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.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 */
20 // server.h
21 
22 
23 //define PARANOID // speed sapping error checking
24 
25 #include "../qcommon/qcommon.h"
26 #include "../game/game.h"
27 
28 //=============================================================================
29 
30 #define MAX_MASTERS 8 // max recipients for heartbeat packets
31 
32 typedef enum {
33  ss_dead, // no map loaded
34  ss_loading, // spawning level edicts
35  ss_game, // actively running
40 // some qc commands are only valid before the server has finished
41 // initializing (precache commands, static sounds / objects, etc)
42 
43 typedef struct
44 {
45  server_state_t state; // precache commands are only valid during load
46 
47  qboolean attractloop; // running cinematics and demos for the local system only
48  qboolean loadgame; // client begins should reuse existing entity
49 
50  unsigned time; // always sv.framenum * 100 msec
51  int framenum;
52 
53  char name[MAX_QPATH]; // map name, or cinematic name
54  struct cmodel_s *models[MAX_MODELS];
55 
56  char configstrings[MAX_CONFIGSTRINGS][MAX_QPATH];
58 
59  // the multicast buffer is used to send a message to a set of clients
60  // it is only used to marshall data until SV_Multicast is called
62  byte multicast_buf[MAX_MSGLEN];
63 
64  // demo server information
65  FILE *demofile;
66  qboolean timedemo; // don't time sync
67 } server_t;
68 
69 #define EDICT_NUM(n) ((edict_t *)((byte *)ge->edicts + ge->edict_size*(n)))
70 #define NUM_FOR_EDICT(e) ( ((byte *)(e)-(byte *)ge->edicts ) / ge->edict_size)
71 
72 
73 typedef enum
74 {
75  cs_free, // can be reused for a new connection
76  cs_zombie, // client has been disconnected, but don't reuse
77  // connection for a couple seconds
78  cs_connected, // has been assigned to a client_t, but not in game yet
79  cs_spawned // client is fully in game
81 
82 typedef struct
83 {
84  int areabytes;
85  byte areabits[MAX_MAP_AREAS/8]; // portalarea visibility bits
88  int first_entity; // into the circular sv_packet_entities[]
89  int senttime; // for ping calculations
91 
92 #define LATENCY_COUNTS 16
93 #define RATE_MESSAGES 10
94 
95 typedef struct client_s
96 {
98 
99  char userinfo[MAX_INFO_STRING]; // name, etc
100 
101  int lastframe; // for delta compression
102  usercmd_t lastcmd; // for filling in big drops
103 
104  int commandMsec; // every seconds this is reset, if user
105  // commands exhaust it, assume time cheating
106 
108  int ping;
109 
110  int message_size[RATE_MESSAGES]; // used to rate drop packets
111  int rate;
112  int surpressCount; // number of messages rate supressed
113 
114  edict_t *edict; // EDICT_NUM(clientnum+1)
115  char name[32]; // extracted from userinfo, high bits masked
116  int messagelevel; // for filtering printed messages
117 
118  // The datagram is written to by sound calls, prints, temp ents, etc.
119  // It can be harmlessly overflowed.
122 
123  client_frame_t frames[UPDATE_BACKUP]; // updates can be delta'd from here
124 
125  byte *download; // file being downloaded
126  int downloadsize; // total bytes (can't use EOF because of paks)
127  int downloadcount; // bytes sent
128 
129  int lastmessage; // sv.framenum when packet was last received
131 
132  int challenge; // challenge of this user, randomly generated
133 
135 } client_t;
136 
137 // a client can leave the server in one of four ways:
138 // dropping properly by quiting or disconnecting
139 // timing out if no valid messages are received for timeout.value seconds
140 // getting kicked off by the server operator
141 // a program error, like an overflowed reliable buffer
142 
143 //=============================================================================
144 
145 // MAX_CHALLENGES is made large to prevent a denial
146 // of service attack that could cycle all of them
147 // out before legitimate users connected
148 #define MAX_CHALLENGES 1024
149 
150 typedef struct
151 {
154  int time;
155 } challenge_t;
156 
157 
158 typedef struct
159 {
160  qboolean initialized; // sv_init has completed
161  int realtime; // always increasing, no clamping, etc
162 
163  char mapcmd[MAX_TOKEN_CHARS]; // ie: *intro.cin+base
164 
165  int spawncount; // incremented each server start
166  // used to check late spawns
167 
168  client_t *clients; // [maxclients->value];
169  int num_client_entities; // maxclients->value*UPDATE_BACKUP*MAX_PACKET_ENTITIES
170  int next_client_entities; // next client_entity to use
171  entity_state_t *client_entities; // [num_client_entities]
172 
174 
175  challenge_t challenges[MAX_CHALLENGES]; // to prevent invalid IPs from connecting
176 
177  // serverrecord values
178  FILE *demofile;
180  byte demo_multicast_buf[MAX_MSGLEN];
182 
183 //=============================================================================
184 
185 extern netadr_t net_from;
186 extern sizebuf_t net_message;
187 
188 extern netadr_t master_adr[MAX_MASTERS]; // address of the master server
189 
190 extern server_static_t svs; // persistant server info
191 extern server_t sv; // local server
192 
193 extern cvar_t *sv_paused;
194 extern cvar_t *maxclients;
195 extern cvar_t *sv_noreload; // don't reload level state when reentering
196 extern cvar_t *sv_airaccelerate; // don't reload level state when reentering
197  // development tool
198 extern cvar_t *sv_enforcetime;
199 
200 extern client_t *sv_client;
201 extern edict_t *sv_player;
202 
203 //===========================================================
204 
205 //
206 // sv_main.c
207 //
208 void SV_FinalMessage (char *message, qboolean reconnect);
209 void SV_DropClient (client_t *drop);
210 
211 int SV_ModelIndex (char *name);
212 int SV_SoundIndex (char *name);
213 int SV_ImageIndex (char *name);
214 
216 
217 void SV_ExecuteUserCommand (char *s);
218 void SV_InitOperatorCommands (void);
219 
220 void SV_SendServerinfo (client_t *client);
222 
223 
224 void Master_Heartbeat (void);
225 void Master_Packet (void);
226 
227 //
228 // sv_init.c
229 //
230 void SV_InitGame (void);
231 void SV_Map (qboolean attractloop, char *levelstring, qboolean loadgame);
232 
233 
234 //
235 // sv_phys.c
236 //
237 void SV_PrepWorldFrame (void);
238 
239 //
240 // sv_send.c
241 //
243 #define SV_OUTPUTBUF_LENGTH (MAX_MSGLEN - 16)
244 
245 extern char sv_outputbuf[SV_OUTPUTBUF_LENGTH];
246 
247 void SV_FlushRedirect (int sv_redirected, char *outputbuf);
248 
249 void SV_DemoCompleted (void);
250 void SV_SendClientMessages (void);
251 
252 void SV_Multicast (vec3_t origin, multicast_t to);
253 void SV_StartSound (vec3_t origin, edict_t *entity, int channel,
254  int soundindex, float volume,
255  float attenuation, float timeofs);
256 void SV_ClientPrintf (client_t *cl, int level, char *fmt, ...);
257 void SV_BroadcastPrintf (int level, char *fmt, ...);
258 void SV_BroadcastCommand (char *fmt, ...);
259 
260 //
261 // sv_user.c
262 //
263 void SV_Nextserver (void);
265 
266 //
267 // sv_ccmds.c
268 //
269 void SV_ReadLevelFile (void);
270 void SV_Status_f (void);
271 
272 //
273 // sv_ents.c
274 //
276 void SV_RecordDemoMessage (void);
277 void SV_BuildClientFrame (client_t *client);
278 
279 
280 void SV_Error (char *error, ...);
281 
282 //
283 // sv_game.c
284 //
285 extern game_export_t *ge;
286 
287 void SV_InitGameProgs (void);
288 void SV_ShutdownGameProgs (void);
289 void SV_InitEdict (edict_t *e);
290 
291 
292 
293 //============================================================
294 
295 //
296 // high level object sorting to reduce interaction tests
297 //
298 
299 void SV_ClearWorld (void);
300 // called after the world model has been loaded, before linking any entities
301 
302 void SV_UnlinkEdict (edict_t *ent);
303 // call before removing an entity, and before trying to move one,
304 // so it doesn't clip against itself
305 
306 void SV_LinkEdict (edict_t *ent);
307 // Needs to be called any time an entity changes origin, mins, maxs,
308 // or solid. Automatically unlinks if needed.
309 // sets ent->v.absmin and ent->v.absmax
310 // sets ent->leafnums[] for pvs determination even if the entity
311 // is not solid
312 
313 int SV_AreaEdicts (vec3_t mins, vec3_t maxs, edict_t **list, int maxcount, int areatype);
314 // fills in a table of edict pointers with edicts that have bounding boxes
315 // that intersect the given area. It is possible for a non-axial bmodel
316 // to be returned that doesn't actually intersect the area on an exact
317 // test.
318 // returns the number of pointers filled in
319 // ??? does this always return the world?
320 
321 //===================================================================
322 
323 //
324 // functions that interact with everything apropriate
325 //
326 int SV_PointContents (vec3_t p);
327 // returns the CONTENTS_* value from the world at the given point.
328 // Quake 2 extends this to also check entities, to allow moving liquids
329 
330 
331 trace_t SV_Trace (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, edict_t *passedict, int contentmask);
332 // mins and maxs are relative
333 
334 // if the entire move stays in a solid volume, trace.allsolid will be set,
335 // trace.startsolid will be set, and trace.fraction will be 0
336 
337 // if the starting point is in a solid, it will be allowed to move out
338 // to an open area
339 
340 // passedict is explicitly excluded from clipping checks (normally NULL)
341 
client_s::lastframe
int lastframe
Definition: server.h:101
server_t::framenum
int framenum
Definition: server.h:51
cs_zombie
@ cs_zombie
Definition: server.h:76
sv
server_t sv
Definition: sv_init.c:24
client_s::lastconnect
int lastconnect
Definition: server.h:130
client_frame_t::num_entities
int num_entities
Definition: server.h:87
SV_DemoCompleted
void SV_DemoCompleted(void)
Definition: sv_send.c:440
sizebuf_s
Definition: qcommon.h:75
client_s::datagram
sizebuf_t datagram
Definition: server.h:120
client_s::message_size
int message_size[RATE_MESSAGES]
Definition: server.h:110
SV_SendServerinfo
void SV_SendServerinfo(client_t *client)
MAX_QPATH
#define MAX_QPATH
Definition: q_shared.h:73
MAX_MODELS
#define MAX_MODELS
Definition: q_shared.h:82
server_static_t::spawncount
int spawncount
Definition: server.h:165
server_t
Definition: server.h:43
client_frame_t::ps
player_state_t ps
Definition: server.h:86
challenge_t::challenge
int challenge
Definition: server.h:153
RD_CLIENT
@ RD_CLIENT
Definition: server.h:242
challenge_t::adr
netadr_t adr
Definition: server.h:152
SV_FlushRedirect
void SV_FlushRedirect(int sv_redirected, char *outputbuf)
Definition: sv_send.c:34
client_s::frame_latency
int frame_latency[LATENCY_COUNTS]
Definition: server.h:107
entity_state_s
Definition: q_shared.h:1169
SV_LinkEdict
void SV_LinkEdict(edict_t *ent)
Definition: sv_world.c:165
SV_InitEdict
void SV_InitEdict(edict_t *e)
SV_ReadLevelFile
void SV_ReadLevelFile(void)
Definition: sv_ccmds.c:306
UPDATE_BACKUP
#define UPDATE_BACKUP
Definition: qcommon.h:190
server_static_t::realtime
int realtime
Definition: server.h:161
qboolean
qboolean
Definition: q_shared.h:56
trace_t
Definition: q_shared.h:449
MAX_MASTERS
#define MAX_MASTERS
Definition: server.h:30
SV_ClearWorld
void SV_ClearWorld(void)
Definition: sv_world.c:135
server_t::multicast
sizebuf_t multicast
Definition: server.h:61
SV_Status_f
void SV_Status_f(void)
Definition: sv_ccmds.c:737
SV_ExecuteUserCommand
void SV_ExecuteUserCommand(char *s)
Definition: sv_user.c:477
netchan_t
Definition: qcommon.h:574
cs_connected
@ cs_connected
Definition: server.h:78
RATE_MESSAGES
#define RATE_MESSAGES
Definition: server.h:93
client_s::downloadcount
int downloadcount
Definition: server.h:127
SV_BroadcastPrintf
void SV_BroadcastPrintf(int level, char *fmt,...)
Definition: sv_send.c:89
MAX_TOKEN_CHARS
#define MAX_TOKEN_CHARS
Definition: q_shared.h:71
server_static_t::next_client_entities
int next_client_entities
Definition: server.h:170
client_s::name
char name[32]
Definition: server.h:115
client_frame_t::first_entity
int first_entity
Definition: server.h:88
Master_Packet
void Master_Packet(void)
MAX_MAP_AREAS
#define MAX_MAP_AREAS
Definition: qfiles.h:234
client_s::state
client_state_t state
Definition: server.h:97
server_t::demofile
FILE * demofile
Definition: server.h:65
cvar_s
Definition: q_shared.h:317
SV_BroadcastCommand
void SV_BroadcastCommand(char *fmt,...)
Definition: sv_send.c:132
MAX_INFO_STRING
#define MAX_INFO_STRING
Definition: q_shared.h:252
SV_InitGame
void SV_InitGame(void)
Definition: sv_init.c:289
sv_player
edict_t * sv_player
Definition: sv_user.c:24
server_state_t
server_state_t
Definition: server.h:32
msg
cvar_t * msg
Definition: cl_main.c:98
server_static_t::client_entities
entity_state_t * client_entities
Definition: server.h:171
server_static_t::clients
client_t * clients
Definition: server.h:168
sv_outputbuf
char sv_outputbuf[SV_OUTPUTBUF_LENGTH]
Definition: sv_send.c:32
client_s::netchan
netchan_t netchan
Definition: server.h:134
ss_cinematic
@ ss_cinematic
Definition: server.h:36
SV_AreaEdicts
int SV_AreaEdicts(vec3_t mins, vec3_t maxs, edict_t **list, int maxcount, int areatype)
Definition: sv_world.c:408
client_frame_t::areabytes
int areabytes
Definition: server.h:84
edict_s
Definition: g_local.h:962
server_static_t::num_client_entities
int num_client_entities
Definition: server.h:169
SV_Error
void SV_Error(char *error,...)
server_static_t
Definition: server.h:158
sv_enforcetime
cvar_t * sv_enforcetime
Definition: sv_main.c:30
SV_UnlinkEdict
void SV_UnlinkEdict(edict_t *ent)
Definition: sv_world.c:149
client_s::download
byte * download
Definition: server.h:125
SV_BuildClientFrame
void SV_BuildClientFrame(client_t *client)
Definition: sv_ents.c:524
ge
game_export_t * ge
Definition: sv_game.c:24
ss_demo
@ ss_demo
Definition: server.h:37
SV_InitGameProgs
void SV_InitGameProgs(void)
Definition: sv_game.c:325
client_s::frames
client_frame_t frames[UPDATE_BACKUP]
Definition: server.h:123
multicast_t
multicast_t
Definition: q_shared.h:107
SV_StartSound
void SV_StartSound(vec3_t origin, edict_t *entity, int channel, int soundindex, float volume, float attenuation, float timeofs)
Definition: sv_send.c:272
client_t
struct client_s client_t
client_s::lastcmd
usercmd_t lastcmd
Definition: server.h:102
sv_client
client_t * sv_client
Definition: sv_main.c:25
SV_Trace
trace_t SV_Trace(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, edict_t *passedict, int contentmask)
Definition: sv_world.c:624
cs_free
@ cs_free
Definition: server.h:75
SV_DropClient
void SV_DropClient(client_t *drop)
Definition: sv_main.c:70
client_s::challenge
int challenge
Definition: server.h:132
SV_ExecuteClientMessage
void SV_ExecuteClientMessage(client_t *cl)
Definition: sv_user.c:539
SV_FinalMessage
void SV_FinalMessage(char *message, qboolean reconnect)
Definition: sv_main.c:996
master_adr
netadr_t master_adr[MAX_MASTERS]
Definition: sv_main.c:23
SV_Nextserver
void SV_Nextserver(void)
Definition: sv_user.c:405
server_t::attractloop
qboolean attractloop
Definition: server.h:47
client_state_t
client_state_t
Definition: server.h:73
cmodel_s
Definition: q_shared.h:428
client_frame_t
Definition: server.h:82
server_t::loadgame
qboolean loadgame
Definition: server.h:48
svs
server_static_t svs
Definition: sv_init.c:23
client_s::messagelevel
int messagelevel
Definition: server.h:116
MAX_CHALLENGES
#define MAX_CHALLENGES
Definition: server.h:148
MAX_CONFIGSTRINGS
#define MAX_CONFIGSTRINGS
Definition: q_shared.h:1143
SV_Multicast
void SV_Multicast(vec3_t origin, multicast_t to)
Definition: sv_send.c:161
name
cvar_t * name
Definition: cl_main.c:94
SV_OUTPUTBUF_LENGTH
#define SV_OUTPUTBUF_LENGTH
Definition: server.h:243
MAX_EDICTS
#define MAX_EDICTS
Definition: q_shared.h:80
SV_SendClientMessages
void SV_SendClientMessages(void)
Definition: sv_send.c:490
net_from
netadr_t net_from
Definition: net_chan.c:81
server_static_t::last_heartbeat
int last_heartbeat
Definition: server.h:173
MAX_MSGLEN
#define MAX_MSGLEN
Definition: qcommon.h:527
server_static_t::initialized
qboolean initialized
Definition: server.h:160
SV_ClientPrintf
void SV_ClientPrintf(client_t *cl, int level, char *fmt,...)
Definition: sv_send.c:65
client_frame_t::senttime
int senttime
Definition: server.h:89
client_s::surpressCount
int surpressCount
Definition: server.h:112
game_export_t
Definition: game.h:181
server_t::timedemo
qboolean timedemo
Definition: server.h:66
SV_UserinfoChanged
void SV_UserinfoChanged(client_t *cl)
Definition: sv_main.c:901
SV_PrepWorldFrame
void SV_PrepWorldFrame(void)
Definition: sv_main.c:703
cs_spawned
@ cs_spawned
Definition: server.h:79
redirect_t
redirect_t
Definition: server.h:242
server_t::time
unsigned time
Definition: server.h:50
usercmd_s
Definition: q_shared.h:513
SV_PointContents
int SV_PointContents(vec3_t p)
Definition: sv_world.c:431
SV_RecordDemoMessage
void SV_RecordDemoMessage(void)
Definition: sv_ents.c:682
SV_WriteFrameToClient
void SV_WriteFrameToClient(client_t *client, sizebuf_t *msg)
Definition: sv_ents.c:415
SV_ShutdownGameProgs
void SV_ShutdownGameProgs(void)
Definition: sv_game.c:307
level
GLint level
Definition: qgl_win.c:116
client_s::datagram_buf
byte datagram_buf[MAX_MSGLEN]
Definition: server.h:121
SV_WriteClientdataToMessage
void SV_WriteClientdataToMessage(client_t *client, sizebuf_t *msg)
SV_SoundIndex
int SV_SoundIndex(char *name)
Definition: sv_init.c:69
ss_game
@ ss_game
Definition: server.h:35
server_t::state
server_state_t state
Definition: server.h:45
client_s::lastmessage
int lastmessage
Definition: server.h:129
SV_ImageIndex
int SV_ImageIndex(char *name)
Definition: sv_init.c:74
sv_paused
cvar_t * sv_paused
Definition: sv_main.c:27
RD_NONE
@ RD_NONE
Definition: server.h:242
client_s::ping
int ping
Definition: server.h:108
netadr_t
Definition: qcommon.h:538
client_s
Definition: server.h:95
Master_Heartbeat
void Master_Heartbeat(void)
Definition: sv_main.c:827
client_s::downloadsize
int downloadsize
Definition: server.h:126
challenge_t
Definition: server.h:150
maxclients
cvar_t * maxclients
Definition: g_main.c:44
player_state_t
Definition: q_shared.h:1198
sv_noreload
cvar_t * sv_noreload
Definition: sv_main.c:45
SV_InitOperatorCommands
void SV_InitOperatorCommands(void)
Definition: sv_ccmds.c:1024
client_s::commandMsec
int commandMsec
Definition: server.h:104
client_s::rate
int rate
Definition: server.h:111
ss_pic
@ ss_pic
Definition: server.h:38
client_state_t
Definition: client.h:111
server_static_t::demo_multicast
sizebuf_t demo_multicast
Definition: server.h:179
ss_loading
@ ss_loading
Definition: server.h:34
RD_PACKET
@ RD_PACKET
Definition: server.h:242
cl
client_state_t cl
Definition: cl_main.c:106
SV_Map
void SV_Map(qboolean attractloop, char *levelstring, qboolean loadgame)
Definition: sv_init.c:393
client_s::userinfo
char userinfo[MAX_INFO_STRING]
Definition: server.h:99
SV_ModelIndex
int SV_ModelIndex(char *name)
Definition: sv_init.c:64
vec3_t
vec_t vec3_t[3]
Definition: q_shared.h:127
ss_dead
@ ss_dead
Definition: server.h:33
sv_airaccelerate
cvar_t * sv_airaccelerate
Definition: sv_main.c:43
LATENCY_COUNTS
#define LATENCY_COUNTS
Definition: server.h:92
server_static_t::demofile
FILE * demofile
Definition: server.h:178
net_message
sizebuf_t net_message
Definition: net_chan.c:82
client_s::edict
edict_t * edict
Definition: server.h:114
challenge_t::time
int time
Definition: server.h:154