Debian Codegraph @

code/server/server.h

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22 // server.h
23
24 #include "../qcommon/q_shared.h"
25 #include "../qcommon/qcommon.h"
26 #include "../game/g_public.h"
27 #include "../game/bg_public.h"
28
29 //=============================================================================
30
31 #define PERS_SCORE 0 // !!! MUST NOT CHANGE, SERVER AND
32 // GAME BOTH REFERENCE !!!
33
34 #define MAX_ENT_CLUSTERS 16
35
36 #ifdef USE_VOIP
37 #define VOIP_QUEUE_LENGTH 64
38
39 typedef struct voipServerPacket_s
40 {
41 int generation;
42 int sequence;
43 int frames;
44 int len;
45 int sender;
46 int flags;
47 byte data[4000];
48 } voipServerPacket_t;
49 #endif
50
51 typedef struct svEntity_s {
52 struct worldSector_s *worldSector;
53 struct svEntity_s *nextEntityInWorldSector;
54
55 entityState_t baseline; // for delta compression of initial sighting
56 int numClusters; // if -1, use headnode instead
57 int clusternums[MAX_ENT_CLUSTERS];
58 int lastCluster; // if all the clusters don't fit in clusternums
59 int areanum, areanum2;
60 int snapshotCounter; // used to prevent double adding from portal views
61 } svEntity_t;
62
63 typedef enum {
64 SS_DEAD, // no map loaded
65 SS_LOADING, // spawning level entities
66 SS_GAME // actively running
67 } serverState_t;
68
69 typedef struct {
70 serverState_t state;
71 qboolean restarting; // if true, send configstring changes during SS_LOADING
72 int serverId; // changes each server start
73 int restartedServerId; // serverId before a map_restart
74 int checksumFeed; // the feed key that we use to compute the pure checksum strings
75 // https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=475
76 // the serverId associated with the current checksumFeed (always <= serverId)
77 int checksumFeedServerId;
78 int snapshotCounter; // incremented for each snapshot built
79 int timeResidual; // <= 1000 / sv_frame->value
80 int nextFrameTime; // when time > nextFrameTime, process world
81 char *configstrings[MAX_CONFIGSTRINGS];
82 svEntity_t svEntities[MAX_GENTITIES];
83
84 char *entityParsePoint; // used during game VM init
85
86 // the game virtual machine will update these on init and changes
87 sharedEntity_t *gentities;
88 int gentitySize;
89 int num_entities; // current number, <= MAX_GENTITIES
90
91 playerState_t *gameClients;
92 int gameClientSize; // will be > sizeof(playerState_t) due to game private data
93
94 int restartTime;
95 int time;
96 } server_t;
97
98
99
100
101
102 typedef struct {
103 int areabytes;
104 byte areabits[MAX_MAP_AREA_BYTES]; // portalarea visibility bits
105 playerState_t ps;
106 int num_entities;
107 int first_entity; // into the circular sv_packet_entities[]
108 // the entities MUST be in increasing state number
109 // order, otherwise the delta compression will fail
110 int messageSent; // time the message was transmitted
111 int messageAcked; // time the message was acked
112 int messageSize; // used to rate drop packets
113 } clientSnapshot_t;
114
115 typedef enum {
116 CS_FREE, // can be reused for a new connection
117 CS_ZOMBIE, // client has been disconnected, but don't reuse
118 // connection for a couple seconds
119 CS_CONNECTED, // has been assigned to a client_t, but no gamestate yet
120 CS_PRIMED, // gamestate has been sent, but client hasn't sent a usercmd
121 CS_ACTIVE // client is fully in game
122 } clientState_t;
123
124 typedef struct netchan_buffer_s {
125 msg_t msg;
126 byte msgBuffer[MAX_MSGLEN];
127 #ifdef LEGACY_PROTOCOL
128 char clientCommandString[MAX_STRING_CHARS]; // valid command string for SV_Netchan_Encode
129 #endif
130 struct netchan_buffer_s *next;
131 } netchan_buffer_t;
132
133 typedef struct client_s {
134 clientState_t state;
135 char userinfo[MAX_INFO_STRING]; // name, etc
136
137 char reliableCommands[MAX_RELIABLE_COMMANDS][MAX_STRING_CHARS];
138 int reliableSequence; // last added reliable message, not necessarily sent or acknowledged yet
139 int reliableAcknowledge; // last acknowledged reliable message
140 int reliableSent; // last sent reliable message, not necessarily acknowledged yet
141 int messageAcknowledge;
142
143 int gamestateMessageNum; // netchan->outgoingSequence of gamestate
144 int challenge;
145
146 usercmd_t lastUsercmd;
147 int lastMessageNum; // for delta compression
148 int lastClientCommand; // reliable client message sequence
149 char lastClientCommandString[MAX_STRING_CHARS];
150 sharedEntity_t *gentity; // SV_GentityNum(clientnum)
151 char name[MAX_NAME_LENGTH]; // extracted from userinfo, high bits masked
152
153 // downloading
154 char downloadName[MAX_QPATH]; // if not empty string, we are downloading
155 fileHandle_t download; // file being downloaded
156 int downloadSize; // total bytes (can't use EOF because of paks)
157 int downloadCount; // bytes sent
158 int downloadClientBlock; // last block we sent to the client, awaiting ack
159 int downloadCurrentBlock; // current block number
160 int downloadXmitBlock; // last block we xmited
161 unsigned char *downloadBlocks[MAX_DOWNLOAD_WINDOW]; // the buffers for the download blocks
162 int downloadBlockSize[MAX_DOWNLOAD_WINDOW];
163 qboolean downloadEOF; // We have sent the EOF block
164 int downloadSendTime; // time we last got an ack from the client
165
166 int deltaMessage; // frame last client usercmd message
167 int nextReliableTime; // svs.time when another reliable command will be allowed
168 int lastPacketTime; // svs.time when packet was last received
169 int lastConnectTime; // svs.time when connection started
170 int lastSnapshotTime; // svs.time of last sent snapshot
171 qboolean rateDelayed; // true if nextSnapshotTime was set based on rate instead of snapshotMsec
172 int timeoutCount; // must timeout a few frames in a row so debugging doesn't break
173 clientSnapshot_t frames[PACKET_BACKUP]; // updates can be delta'd from here
174 int ping;
175 int rate; // bytes / second
176 int snapshotMsec; // requests a snapshot every snapshotMsec unless rate choked
177 int pureAuthentic;
178 qboolean gotCP; // TTimo - additional flag to distinguish between a bad pure checksum, and no cp command at all
179 netchan_t netchan;
180 // TTimo
181 // queuing outgoing fragmented messages to send them properly, without udp packet bursts
182 // in case large fragmented messages are stacking up
183 // buffer them into this queue, and hand them out to netchan as needed
184 netchan_buffer_t *netchan_start_queue;
185 netchan_buffer_t **netchan_end_queue;
186
187 #ifdef USE_VOIP
188 qboolean hasVoip;
189 qboolean muteAllVoip;
190 qboolean ignoreVoipFromClient[MAX_CLIENTS];
191 voipServerPacket_t *voipPacket[VOIP_QUEUE_LENGTH];
192 int queuedVoipPackets;
193 int queuedVoipIndex;
194 #endif
195
196 int oldServerTime;
197 qboolean csUpdated[MAX_CONFIGSTRINGS];
198
199 #ifdef LEGACY_PROTOCOL
200 qboolean compat;
201 #endif
202 } client_t;
203
204 //=============================================================================
205
206
207 // MAX_CHALLENGES is made large to prevent a denial
208 // of service attack that could cycle all of them
209 // out before legitimate users connected
210 #define MAX_CHALLENGES 2048
211 // Allow a certain amount of challenges to have the same IP address
212 // to make it a bit harder to DOS one single IP address from connecting
213 // while not allowing a single ip to grab all challenge resources
214 #define MAX_CHALLENGES_MULTI (MAX_CHALLENGES / 2)
215
216 #define AUTHORIZE_TIMEOUT 5000
217
218 typedef struct {
219 netadr_t adr;
220 int challenge;
221 int clientChallenge; // challenge number coming from the client
222 int time; // time the last packet was sent to the autherize server
223 int pingTime; // time the challenge response was sent to client
224 int firstTime; // time the adr was first used, for authorize timeout checks
225 qboolean wasrefused;
226 qboolean connected;
227 } challenge_t;
228
229 // this structure will be cleared only when the game dll changes
230 typedef struct {
231 qboolean initialized; // sv_init has completed
232
233 int time; // will be strictly increasing across level changes
234
235 int snapFlagServerBit; // ^= SNAPFLAG_SERVERCOUNT every SV_SpawnServer()
236
237 client_t *clients; // [sv_maxclients->integer];
238 int numSnapshotEntities; // sv_maxclients->integer*PACKET_BACKUP*MAX_SNAPSHOT_ENTITIES
239 int nextSnapshotEntities; // next snapshotEntities to use
240 entityState_t *snapshotEntities; // [numSnapshotEntities]
241 int nextHeartbeatTime;
242 challenge_t challenges[MAX_CHALLENGES]; // to prevent invalid IPs from connecting
243 netadr_t redirectAddress; // for rcon return messages
244 #ifndef STANDALONE
245 netadr_t authorizeAddress; // authorize server address
246 #endif
247 int masterResolveTime[MAX_MASTER_SERVERS]; // next svs.time that server should do dns lookup for master server
248 } serverStatic_t;
249
250 #define SERVER_MAXBANS 1024
251 // Structure for managing bans
252 typedef struct
253 {
254 netadr_t ip;
255 // For a CIDR-Notation type suffix
256 int subnet;
257
258 qboolean isexception;
259 } serverBan_t;
260
261 //=============================================================================
262
263 extern serverStatic_t svs; // persistant server info across maps
264 extern server_t sv; // cleared each map
265 extern vm_t *gvm; // game virtual machine
266
267 extern cvar_t *sv_fps;
268 extern cvar_t *sv_timeout;
269 extern cvar_t *sv_zombietime;
270 extern cvar_t *sv_rconPassword;
271 extern cvar_t *sv_privatePassword;
272 extern cvar_t *sv_allowDownload;
273 extern cvar_t *sv_maxclients;
274
275 extern cvar_t *sv_privateClients;
276 extern cvar_t *sv_hostname;
277 extern cvar_t *sv_master[MAX_MASTER_SERVERS];
278 extern cvar_t *sv_reconnectlimit;
279 extern cvar_t *sv_showloss;
280 extern cvar_t *sv_padPackets;
281 extern cvar_t *sv_killserver;
282 extern cvar_t *sv_mapname;
283 extern cvar_t *sv_mapChecksum;
284 extern cvar_t *sv_serverid;
285 extern cvar_t *sv_minRate;
286 extern cvar_t *sv_maxRate;
287 extern cvar_t *sv_dlRate;
288 extern cvar_t *sv_minPing;
289 extern cvar_t *sv_maxPing;
290 extern cvar_t *sv_gametype;
291 extern cvar_t *sv_pure;
292 extern cvar_t *sv_floodProtect;
293 extern cvar_t *sv_lanForceRate;
294 #ifndef STANDALONE
295 extern cvar_t *sv_strictAuth;
296 #endif
297 extern cvar_t *sv_banFile;
298
299 extern serverBan_t serverBans[SERVER_MAXBANS];
300 extern int serverBansCount;
301
302 #ifdef USE_VOIP
303 extern cvar_t *sv_voip;
304 extern cvar_t *sv_voipProtocol;
305 #endif
306
307
308 //===========================================================
309
310 //
311 // sv_main.c
312 //
313 typedef struct leakyBucket_s leakyBucket_t;
314 struct leakyBucket_s {
315 netadrtype_t type;
316
317 union {
318 byte _4[4];
319 byte _6[16];
320 } ipv;
321
322 int lastTime;
323 signed char burst;
324
325 long hash;
326
327 leakyBucket_t *prev, *next;
328 };
329
330 extern leakyBucket_t outboundLeakyBucket;
331
332 qboolean SVC_RateLimit( leakyBucket_t *bucket, int burst, int period );
333 qboolean SVC_RateLimitAddress( netadr_t from, int burst, int period );
334
335 void SV_FinalMessage (char *message);
336 void QDECL SV_SendServerCommand( client_t *cl, const char *fmt, ...) Q_PRINTF_FUNC(2, 3);
337
338
339 void SV_AddOperatorCommands (void);
340 void SV_RemoveOperatorCommands (void);
341
342
343 void SV_MasterShutdown (void);
344 int SV_RateMsec(client_t *client);
345
346
347
348 //
349 // sv_init.c
350 //
351 void SV_SetConfigstring( int index, const char *val );
352 void SV_GetConfigstring( int index, char *buffer, int bufferSize );
353 void SV_UpdateConfigstrings( client_t *client );
354
355 void SV_SetUserinfo( int index, const char *val );
356 void SV_GetUserinfo( int index, char *buffer, int bufferSize );
357
358 void SV_ChangeMaxClients( void );
359 void SV_SpawnServer( char *server, qboolean killBots );
360
361
362
363 //
364 // sv_client.c
365 //
366 void SV_GetChallenge(netadr_t from);
367
368 void SV_DirectConnect( netadr_t from );
369
370 #ifndef STANDALONE
371 void SV_AuthorizeIpPacket( netadr_t from );
372 #endif
373
374 void SV_ExecuteClientMessage( client_t *cl, msg_t *msg );
375 void SV_UserinfoChanged( client_t *cl );
376
377 void SV_ClientEnterWorld( client_t *client, usercmd_t *cmd );
378 void SV_FreeClient(client_t *client);
379 void SV_DropClient( client_t *drop, const char *reason );
380
381 void SV_ExecuteClientCommand( client_t *cl, const char *s, qboolean clientOK );
382 void SV_ClientThink (client_t *cl, usercmd_t *cmd);
383
384 int SV_WriteDownloadToClient(client_t *cl , msg_t *msg);
385 int SV_SendDownloadMessages(void);
386 int SV_SendQueuedMessages(void);
387
388
389 //
390 // sv_ccmds.c
391 //
392 void SV_Heartbeat_f( void );
393
394 //
395 // sv_snapshot.c
396 //
397 void SV_AddServerCommand( client_t *client, const char *cmd );
398 void SV_UpdateServerCommandsToClient( client_t *client, msg_t *msg );
399 void SV_WriteFrameToClient (client_t *client, msg_t *msg);
400 void SV_SendMessageToClient( msg_t *msg, client_t *client );
401 void SV_SendClientMessages( void );
402 void SV_SendClientSnapshot( client_t *client );
403
404 //
405 // sv_game.c
406 //
407 int SV_NumForGentity( sharedEntity_t *ent );
408 sharedEntity_t *SV_GentityNum( int num );
409 playerState_t *SV_GameClientNum( int num );
410 svEntity_t *SV_SvEntityForGentity( sharedEntity_t *gEnt );
411 sharedEntity_t *SV_GEntityForSvEntity( svEntity_t *svEnt );
412 void SV_InitGameProgs ( void );
413 void SV_ShutdownGameProgs ( void );
414 void SV_RestartGameProgs( void );
415 qboolean SV_inPVS (const vec3_t p1, const vec3_t p2);
416
417 //
418 // sv_bot.c
419 //
420 void SV_BotFrame( int time );
421 int SV_BotAllocateClient(void);
422 void SV_BotFreeClient( int clientNum );
423
424 void SV_BotInitCvars(void);
425 int SV_BotLibSetup( void );
426 int SV_BotLibShutdown( void );
427 int SV_BotGetSnapshotEntity( int client, int ent );
428 int SV_BotGetConsoleMessage( int client, char *buf, int size );
429
430 int BotImport_DebugPolygonCreate(int color, int numPoints, vec3_t *points);
431 void BotImport_DebugPolygonDelete(int id);
432
433 void SV_BotInitBotLib(void);
434
435 //============================================================
436 //
437 // high level object sorting to reduce interaction tests
438 //
439
440 void SV_ClearWorld (void);
441 // called after the world model has been loaded, before linking any entities
442
443 void SV_UnlinkEntity( sharedEntity_t *ent );
444 // call before removing an entity, and before trying to move one,
445 // so it doesn't clip against itself
446
447 void SV_LinkEntity( sharedEntity_t *ent );
448 // Needs to be called any time an entity changes origin, mins, maxs,
449 // or solid. Automatically unlinks if needed.
450 // sets ent->r.absmin and ent->r.absmax
451 // sets ent->leafnums[] for pvs determination even if the entity
452 // is not solid
453
454
455 clipHandle_t SV_ClipHandleForEntity( const sharedEntity_t *ent );
456
457
458 void SV_SectorList_f( void );
459
460
461 int SV_AreaEntities( const vec3_t mins, const vec3_t maxs, int *entityList, int maxcount );
462 // fills in a table of entity numbers with entities that have bounding boxes
463 // that intersect the given area. It is possible for a non-axial bmodel
464 // to be returned that doesn't actually intersect the area on an exact
465 // test.
466 // returns the number of pointers filled in
467 // The world entity is never returned in this list.
468
469
470 int SV_PointContents( const vec3_t p, int passEntityNum );
471 // returns the CONTENTS_* value from the world and all entities at the given point.
472
473
474 void SV_Trace( trace_t *results, const vec3_t start, vec3_t mins, vec3_t maxs, const vec3_t end, int passEntityNum, int contentmask, int capsule );
475 // mins and maxs are relative
476
477 // if the entire move stays in a solid volume, trace.allsolid will be set,
478 // trace.startsolid will be set, and trace.fraction will be 0
479
480 // if the starting point is in a solid, it will be allowed to move out
481 // to an open area
482
483 // passEntityNum is explicitly excluded from clipping checks (normally ENTITYNUM_NONE)
484
485
486 void SV_ClipToEntity( trace_t *trace, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int entityNum, int contentmask, int capsule );
487 // clip to a specific entity
488
489 //
490 // sv_net_chan.c
491 //
492 void SV_Netchan_Transmit( client_t *client, msg_t *msg);
493 int SV_Netchan_TransmitNextFragment(client_t *client);
494 qboolean SV_Netchan_Process( client_t *client, msg_t *msg );
495 void SV_Netchan_FreeQueue(client_t *client);