Debian Codegraph @

code/server/server.h

raw symbols ◀ ▶ SCIP
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_dorestart;
292 extern cvar_t *sv_pure;
293 extern cvar_t *sv_floodProtect;
294 extern cvar_t *sv_lanForceRate;
295 #ifndef STANDALONE
296 extern cvar_t *sv_strictAuth;
297 #endif
298 extern cvar_t *sv_banFile;
299
300 extern serverBan_t serverBans[SERVER_MAXBANS];
301 extern int serverBansCount;
302
303 #ifdef USE_VOIP
304 extern cvar_t *sv_voip;
305 extern cvar_t *sv_voipProtocol;
306 #endif
307
308
309 //===========================================================
310
311 //
312 // sv_main.c
313 //
314 typedef struct leakyBucket_s leakyBucket_t;
315 struct leakyBucket_s {
316 netadrtype_t type;
317
318 union {
319 byte _4[4];
320 byte _6[16];
321 } ipv;
322
323 int lastTime;
324 signed char burst;
325
326 long hash;
327
328 leakyBucket_t *prev, *next;
329 };
330
331 extern leakyBucket_t outboundLeakyBucket;
332
333 qboolean SVC_RateLimit( leakyBucket_t *bucket, int burst, int period );
334 qboolean SVC_RateLimitAddress( netadr_t from, int burst, int period );
335
336 void SV_FinalMessage (char *message);
337 void QDECL SV_SendServerCommand( client_t *cl, const char *fmt, ...) Q_PRINTF_FUNC(2, 3);
338
339
340 void SV_AddOperatorCommands (void);
341 void SV_RemoveOperatorCommands (void);
342
343
344 void SV_MasterShutdown (void);
345 int SV_RateMsec(client_t *client);
346
347
348
349 //
350 // sv_init.c
351 //
352 void SV_SetConfigstring( int index, const char *val );
353 void SV_GetConfigstring( int index, char *buffer, int bufferSize );
354 void SV_UpdateConfigstrings( client_t *client );
355
356 void SV_SetUserinfo( int index, const char *val );
357 void SV_GetUserinfo( int index, char *buffer, int bufferSize );
358
359 void SV_ChangeMaxClients( void );
360 void SV_SpawnServer( char *server, qboolean killBots );
361
362
363
364 //
365 // sv_client.c
366 //
367 void SV_GetChallenge(netadr_t from);
368
369 void SV_DirectConnect( netadr_t from );
370
371 #ifndef STANDALONE
372 void SV_AuthorizeIpPacket( netadr_t from );
373 #endif
374
375 void SV_ExecuteClientMessage( client_t *cl, msg_t *msg );
376 void SV_UserinfoChanged( client_t *cl );
377
378 void SV_ClientEnterWorld( client_t *client, usercmd_t *cmd );
379 void SV_FreeClient(client_t *client);
380 void SV_DropClient( client_t *drop, const char *reason );
381
382 void SV_ExecuteClientCommand( client_t *cl, const char *s, qboolean clientOK );
383 void SV_ClientThink (client_t *cl, usercmd_t *cmd);
384
385 int SV_WriteDownloadToClient(client_t *cl , msg_t *msg);
386 int SV_SendDownloadMessages(void);
387 int SV_SendQueuedMessages(void);
388
389
390 //
391 // sv_ccmds.c
392 //
393 void SV_Heartbeat_f( void );
394
395 //
396 // sv_snapshot.c
397 //
398 void SV_AddServerCommand( client_t *client, const char *cmd );
399 void SV_UpdateServerCommandsToClient( client_t *client, msg_t *msg );
400 void SV_WriteFrameToClient (client_t *client, msg_t *msg);
401 void SV_SendMessageToClient( msg_t *msg, client_t *client );
402 void SV_SendClientMessages( void );
403 void SV_SendClientSnapshot( client_t *client );
404
405 //
406 // sv_game.c
407 //
408 int SV_NumForGentity( sharedEntity_t *ent );
409 sharedEntity_t *SV_GentityNum( int num );
410 playerState_t *SV_GameClientNum( int num );
411 svEntity_t *SV_SvEntityForGentity( sharedEntity_t *gEnt );
412 sharedEntity_t *SV_GEntityForSvEntity( svEntity_t *svEnt );
413 void SV_InitGameProgs ( void );
414 void SV_ShutdownGameProgs ( void );
415 void SV_RestartGameProgs( void );
416 qboolean SV_inPVS (const vec3_t p1, const vec3_t p2);
417
418 //
419 // sv_bot.c
420 //
421 void SV_BotFrame( int time );
422 int SV_BotAllocateClient(void);
423 void SV_BotFreeClient( int clientNum );
424
425 void SV_BotInitCvars(void);
426 int SV_BotLibSetup( void );
427 int SV_BotLibShutdown( void );
428 int SV_BotGetSnapshotEntity( int client, int ent );
429 int SV_BotGetConsoleMessage( int client, char *buf, int size );
430
431 int BotImport_DebugPolygonCreate(int color, int numPoints, vec3_t *points);
432 void BotImport_DebugPolygonDelete(int id);
433
434 void SV_BotInitBotLib(void);
435
436 //============================================================
437 //
438 // high level object sorting to reduce interaction tests
439 //
440
441 void SV_ClearWorld (void);
442 // called after the world model has been loaded, before linking any entities
443
444 void SV_UnlinkEntity( sharedEntity_t *ent );
445 // call before removing an entity, and before trying to move one,
446 // so it doesn't clip against itself
447
448 void SV_LinkEntity( sharedEntity_t *ent );
449 // Needs to be called any time an entity changes origin, mins, maxs,
450 // or solid. Automatically unlinks if needed.
451 // sets ent->r.absmin and ent->r.absmax
452 // sets ent->leafnums[] for pvs determination even if the entity
453 // is not solid
454
455
456 clipHandle_t SV_ClipHandleForEntity( const sharedEntity_t *ent );
457
458
459 void SV_SectorList_f( void );
460
461
462 int SV_AreaEntities( const vec3_t mins, const vec3_t maxs, int *entityList, int maxcount );
463 // fills in a table of entity numbers with entities that have bounding boxes
464 // that intersect the given area. It is possible for a non-axial bmodel
465 // to be returned that doesn't actually intersect the area on an exact
466 // test.
467 // returns the number of pointers filled in
468 // The world entity is never returned in this list.
469
470
471 int SV_PointContents( const vec3_t p, int passEntityNum );
472 // returns the CONTENTS_* value from the world and all entities at the given point.
473
474
475 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 );
476 // mins and maxs are relative
477
478 // if the entire move stays in a solid volume, trace.allsolid will be set,
479 // trace.startsolid will be set, and trace.fraction will be 0
480
481 // if the starting point is in a solid, it will be allowed to move out
482 // to an open area
483
484 // passEntityNum is explicitly excluded from clipping checks (normally ENTITYNUM_NONE)
485
486
487 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 );
488 // clip to a specific entity
489
490 //
491 // sv_net_chan.c
492 //
493 void SV_Netchan_Transmit( client_t *client, msg_t *msg);
494 int SV_Netchan_TransmitNextFragment(client_t *client);
495 qboolean SV_Netchan_Process( client_t *client, msg_t *msg );
496 void SV_Netchan_FreeQueue(client_t *client);