Quake-III-Arena

Quake III Arena GPL Source Release
Log | Files | Refs

qcommon.h (32532B)


      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 Foobar; if not, write to the Free Software
     19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     20 ===========================================================================
     21 */
     22 // qcommon.h -- definitions common between client and server, but not game.or ref modules
     23 #ifndef _QCOMMON_H_
     24 #define _QCOMMON_H_
     25 
     26 #include "../qcommon/cm_public.h"
     27 
     28 //#define	PRE_RELEASE_DEMO
     29 
     30 //============================================================================
     31 
     32 //
     33 // msg.c
     34 //
     35 typedef struct {
     36 	qboolean	allowoverflow;	// if false, do a Com_Error
     37 	qboolean	overflowed;		// set to true if the buffer size failed (with allowoverflow set)
     38 	qboolean	oob;			// set to true if the buffer size failed (with allowoverflow set)
     39 	byte	*data;
     40 	int		maxsize;
     41 	int		cursize;
     42 	int		readcount;
     43 	int		bit;				// for bitwise reads and writes
     44 } msg_t;
     45 
     46 void MSG_Init (msg_t *buf, byte *data, int length);
     47 void MSG_InitOOB( msg_t *buf, byte *data, int length );
     48 void MSG_Clear (msg_t *buf);
     49 void MSG_WriteData (msg_t *buf, const void *data, int length);
     50 void MSG_Bitstream( msg_t *buf );
     51 
     52 // TTimo
     53 // copy a msg_t in case we need to store it as is for a bit
     54 // (as I needed this to keep an msg_t from a static var for later use)
     55 // sets data buffer as MSG_Init does prior to do the copy
     56 void MSG_Copy(msg_t *buf, byte *data, int length, msg_t *src);
     57 
     58 struct usercmd_s;
     59 struct entityState_s;
     60 struct playerState_s;
     61 
     62 void MSG_WriteBits( msg_t *msg, int value, int bits );
     63 
     64 void MSG_WriteChar (msg_t *sb, int c);
     65 void MSG_WriteByte (msg_t *sb, int c);
     66 void MSG_WriteShort (msg_t *sb, int c);
     67 void MSG_WriteLong (msg_t *sb, int c);
     68 void MSG_WriteFloat (msg_t *sb, float f);
     69 void MSG_WriteString (msg_t *sb, const char *s);
     70 void MSG_WriteBigString (msg_t *sb, const char *s);
     71 void MSG_WriteAngle16 (msg_t *sb, float f);
     72 
     73 void	MSG_BeginReading (msg_t *sb);
     74 void	MSG_BeginReadingOOB(msg_t *sb);
     75 
     76 int		MSG_ReadBits( msg_t *msg, int bits );
     77 
     78 int		MSG_ReadChar (msg_t *sb);
     79 int		MSG_ReadByte (msg_t *sb);
     80 int		MSG_ReadShort (msg_t *sb);
     81 int		MSG_ReadLong (msg_t *sb);
     82 float	MSG_ReadFloat (msg_t *sb);
     83 char	*MSG_ReadString (msg_t *sb);
     84 char	*MSG_ReadBigString (msg_t *sb);
     85 char	*MSG_ReadStringLine (msg_t *sb);
     86 float	MSG_ReadAngle16 (msg_t *sb);
     87 void	MSG_ReadData (msg_t *sb, void *buffer, int size);
     88 
     89 
     90 void MSG_WriteDeltaUsercmd( msg_t *msg, struct usercmd_s *from, struct usercmd_s *to );
     91 void MSG_ReadDeltaUsercmd( msg_t *msg, struct usercmd_s *from, struct usercmd_s *to );
     92 
     93 void MSG_WriteDeltaUsercmdKey( msg_t *msg, int key, usercmd_t *from, usercmd_t *to );
     94 void MSG_ReadDeltaUsercmdKey( msg_t *msg, int key, usercmd_t *from, usercmd_t *to );
     95 
     96 void MSG_WriteDeltaEntity( msg_t *msg, struct entityState_s *from, struct entityState_s *to
     97 						   , qboolean force );
     98 void MSG_ReadDeltaEntity( msg_t *msg, entityState_t *from, entityState_t *to, 
     99 						 int number );
    100 
    101 void MSG_WriteDeltaPlayerstate( msg_t *msg, struct playerState_s *from, struct playerState_s *to );
    102 void MSG_ReadDeltaPlayerstate( msg_t *msg, struct playerState_s *from, struct playerState_s *to );
    103 
    104 
    105 void MSG_ReportChangeVectors_f( void );
    106 
    107 //============================================================================
    108 
    109 /*
    110 ==============================================================
    111 
    112 NET
    113 
    114 ==============================================================
    115 */
    116 
    117 #define	PACKET_BACKUP	32	// number of old messages that must be kept on client and
    118 							// server for delta comrpession and ping estimation
    119 #define	PACKET_MASK		(PACKET_BACKUP-1)
    120 
    121 #define	MAX_PACKET_USERCMDS		32		// max number of usercmd_t in a packet
    122 
    123 #define	PORT_ANY			-1
    124 
    125 #define	MAX_RELIABLE_COMMANDS	64			// max string commands buffered for restransmit
    126 
    127 typedef enum {
    128 	NA_BOT,
    129 	NA_BAD,					// an address lookup failed
    130 	NA_LOOPBACK,
    131 	NA_BROADCAST,
    132 	NA_IP,
    133 	NA_IPX,
    134 	NA_BROADCAST_IPX
    135 } netadrtype_t;
    136 
    137 typedef enum {
    138 	NS_CLIENT,
    139 	NS_SERVER
    140 } netsrc_t;
    141 
    142 typedef struct {
    143 	netadrtype_t	type;
    144 
    145 	byte	ip[4];
    146 	byte	ipx[10];
    147 
    148 	unsigned short	port;
    149 } netadr_t;
    150 
    151 void		NET_Init( void );
    152 void		NET_Shutdown( void );
    153 void		NET_Restart( void );
    154 void		NET_Config( qboolean enableNetworking );
    155 
    156 void		NET_SendPacket (netsrc_t sock, int length, const void *data, netadr_t to);
    157 void		QDECL NET_OutOfBandPrint( netsrc_t net_socket, netadr_t adr, const char *format, ...);
    158 void		QDECL NET_OutOfBandData( netsrc_t sock, netadr_t adr, byte *format, int len );
    159 
    160 qboolean	NET_CompareAdr (netadr_t a, netadr_t b);
    161 qboolean	NET_CompareBaseAdr (netadr_t a, netadr_t b);
    162 qboolean	NET_IsLocalAddress (netadr_t adr);
    163 const char	*NET_AdrToString (netadr_t a);
    164 qboolean	NET_StringToAdr ( const char *s, netadr_t *a);
    165 qboolean	NET_GetLoopPacket (netsrc_t sock, netadr_t *net_from, msg_t *net_message);
    166 void		NET_Sleep(int msec);
    167 
    168 
    169 #define	MAX_MSGLEN				16384		// max length of a message, which may
    170 											// be fragmented into multiple packets
    171 
    172 #define MAX_DOWNLOAD_WINDOW			8		// max of eight download frames
    173 #define MAX_DOWNLOAD_BLKSIZE		2048	// 2048 byte block chunks
    174  
    175 
    176 /*
    177 Netchan handles packet fragmentation and out of order / duplicate suppression
    178 */
    179 
    180 typedef struct {
    181 	netsrc_t	sock;
    182 
    183 	int			dropped;			// between last packet and previous
    184 
    185 	netadr_t	remoteAddress;
    186 	int			qport;				// qport value to write when transmitting
    187 
    188 	// sequencing variables
    189 	int			incomingSequence;
    190 	int			outgoingSequence;
    191 
    192 	// incoming fragment assembly buffer
    193 	int			fragmentSequence;
    194 	int			fragmentLength;	
    195 	byte		fragmentBuffer[MAX_MSGLEN];
    196 
    197 	// outgoing fragment buffer
    198 	// we need to space out the sending of large fragmented messages
    199 	qboolean	unsentFragments;
    200 	int			unsentFragmentStart;
    201 	int			unsentLength;
    202 	byte		unsentBuffer[MAX_MSGLEN];
    203 } netchan_t;
    204 
    205 void Netchan_Init( int qport );
    206 void Netchan_Setup( netsrc_t sock, netchan_t *chan, netadr_t adr, int qport );
    207 
    208 void Netchan_Transmit( netchan_t *chan, int length, const byte *data );
    209 void Netchan_TransmitNextFragment( netchan_t *chan );
    210 
    211 qboolean Netchan_Process( netchan_t *chan, msg_t *msg );
    212 
    213 
    214 /*
    215 ==============================================================
    216 
    217 PROTOCOL
    218 
    219 ==============================================================
    220 */
    221 
    222 #define	PROTOCOL_VERSION	68
    223 // 1.31 - 67
    224 
    225 // maintain a list of compatible protocols for demo playing
    226 // NOTE: that stuff only works with two digits protocols
    227 extern int demo_protocols[];
    228 
    229 #define	UPDATE_SERVER_NAME	"update.quake3arena.com"
    230 // override on command line, config files etc.
    231 #ifndef MASTER_SERVER_NAME
    232 #define MASTER_SERVER_NAME	"master.quake3arena.com"
    233 #endif
    234 #ifndef AUTHORIZE_SERVER_NAME
    235 #define	AUTHORIZE_SERVER_NAME	"authorize.quake3arena.com"
    236 #endif
    237 
    238 #define	PORT_MASTER			27950
    239 #define	PORT_UPDATE			27951
    240 #ifndef PORT_AUTHORIZE
    241 #define	PORT_AUTHORIZE		27952
    242 #endif
    243 #define	PORT_SERVER			27960
    244 #define	NUM_SERVER_PORTS	4		// broadcast scan this many ports after
    245 									// PORT_SERVER so a single machine can
    246 									// run multiple servers
    247 
    248 
    249 // the svc_strings[] array in cl_parse.c should mirror this
    250 //
    251 // server to client
    252 //
    253 enum svc_ops_e {
    254 	svc_bad,
    255 	svc_nop,
    256 	svc_gamestate,
    257 	svc_configstring,			// [short] [string] only in gamestate messages
    258 	svc_baseline,				// only in gamestate messages
    259 	svc_serverCommand,			// [string] to be executed by client game module
    260 	svc_download,				// [short] size [size bytes]
    261 	svc_snapshot,
    262 	svc_EOF
    263 };
    264 
    265 
    266 //
    267 // client to server
    268 //
    269 enum clc_ops_e {
    270 	clc_bad,
    271 	clc_nop, 		
    272 	clc_move,				// [[usercmd_t]
    273 	clc_moveNoDelta,		// [[usercmd_t]
    274 	clc_clientCommand,		// [string] message
    275 	clc_EOF
    276 };
    277 
    278 /*
    279 ==============================================================
    280 
    281 VIRTUAL MACHINE
    282 
    283 ==============================================================
    284 */
    285 
    286 typedef struct vm_s vm_t;
    287 
    288 typedef enum {
    289 	VMI_NATIVE,
    290 	VMI_BYTECODE,
    291 	VMI_COMPILED
    292 } vmInterpret_t;
    293 
    294 typedef enum {
    295 	TRAP_MEMSET = 100,
    296 	TRAP_MEMCPY,
    297 	TRAP_STRNCPY,
    298 	TRAP_SIN,
    299 	TRAP_COS,
    300 	TRAP_ATAN2,
    301 	TRAP_SQRT,
    302 	TRAP_MATRIXMULTIPLY,
    303 	TRAP_ANGLEVECTORS,
    304 	TRAP_PERPENDICULARVECTOR,
    305 	TRAP_FLOOR,
    306 	TRAP_CEIL,
    307 
    308 	TRAP_TESTPRINTINT,
    309 	TRAP_TESTPRINTFLOAT
    310 } sharedTraps_t;
    311 
    312 void	VM_Init( void );
    313 vm_t	*VM_Create( const char *module, int (*systemCalls)(int *), 
    314 				   vmInterpret_t interpret );
    315 // module should be bare: "cgame", not "cgame.dll" or "vm/cgame.qvm"
    316 
    317 void	VM_Free( vm_t *vm );
    318 void	VM_Clear(void);
    319 vm_t	*VM_Restart( vm_t *vm );
    320 
    321 int		QDECL VM_Call( vm_t *vm, int callNum, ... );
    322 
    323 void	VM_Debug( int level );
    324 
    325 void	*VM_ArgPtr( int intValue );
    326 void	*VM_ExplicitArgPtr( vm_t *vm, int intValue );
    327 
    328 /*
    329 ==============================================================
    330 
    331 CMD
    332 
    333 Command text buffering and command execution
    334 
    335 ==============================================================
    336 */
    337 
    338 /*
    339 
    340 Any number of commands can be added in a frame, from several different sources.
    341 Most commands come from either keybindings or console line input, but entire text
    342 files can be execed.
    343 
    344 */
    345 
    346 void Cbuf_Init (void);
    347 // allocates an initial text buffer that will grow as needed
    348 
    349 void Cbuf_AddText( const char *text );
    350 // Adds command text at the end of the buffer, does NOT add a final \n
    351 
    352 void Cbuf_ExecuteText( int exec_when, const char *text );
    353 // this can be used in place of either Cbuf_AddText or Cbuf_InsertText
    354 
    355 void Cbuf_Execute (void);
    356 // Pulls off \n terminated lines of text from the command buffer and sends
    357 // them through Cmd_ExecuteString.  Stops when the buffer is empty.
    358 // Normally called once per frame, but may be explicitly invoked.
    359 // Do not call inside a command function, or current args will be destroyed.
    360 
    361 //===========================================================================
    362 
    363 /*
    364 
    365 Command execution takes a null terminated string, breaks it into tokens,
    366 then searches for a command or variable that matches the first token.
    367 
    368 */
    369 
    370 typedef void (*xcommand_t) (void);
    371 
    372 void	Cmd_Init (void);
    373 
    374 void	Cmd_AddCommand( const char *cmd_name, xcommand_t function );
    375 // called by the init functions of other parts of the program to
    376 // register commands and functions to call for them.
    377 // The cmd_name is referenced later, so it should not be in temp memory
    378 // if function is NULL, the command will be forwarded to the server
    379 // as a clc_clientCommand instead of executed locally
    380 
    381 void	Cmd_RemoveCommand( const char *cmd_name );
    382 
    383 void	Cmd_CommandCompletion( void(*callback)(const char *s) );
    384 // callback with each valid string
    385 
    386 int		Cmd_Argc (void);
    387 char	*Cmd_Argv (int arg);
    388 void	Cmd_ArgvBuffer( int arg, char *buffer, int bufferLength );
    389 char	*Cmd_Args (void);
    390 char	*Cmd_ArgsFrom( int arg );
    391 void	Cmd_ArgsBuffer( char *buffer, int bufferLength );
    392 char	*Cmd_Cmd (void);
    393 // The functions that execute commands get their parameters with these
    394 // functions. Cmd_Argv () will return an empty string, not a NULL
    395 // if arg > argc, so string operations are allways safe.
    396 
    397 void	Cmd_TokenizeString( const char *text );
    398 // Takes a null terminated string.  Does not need to be /n terminated.
    399 // breaks the string up into arg tokens.
    400 
    401 void	Cmd_ExecuteString( const char *text );
    402 // Parses a single line of text into arguments and tries to execute it
    403 // as if it was typed at the console
    404 
    405 
    406 /*
    407 ==============================================================
    408 
    409 CVAR
    410 
    411 ==============================================================
    412 */
    413 
    414 /*
    415 
    416 cvar_t variables are used to hold scalar or string variables that can be changed
    417 or displayed at the console or prog code as well as accessed directly
    418 in C code.
    419 
    420 The user can access cvars from the console in three ways:
    421 r_draworder			prints the current value
    422 r_draworder 0		sets the current value to 0
    423 set r_draworder 0	as above, but creates the cvar if not present
    424 
    425 Cvars are restricted from having the same names as commands to keep this
    426 interface from being ambiguous.
    427 
    428 The are also occasionally used to communicated information between different
    429 modules of the program.
    430 
    431 */
    432 
    433 cvar_t *Cvar_Get( const char *var_name, const char *value, int flags );
    434 // creates the variable if it doesn't exist, or returns the existing one
    435 // if it exists, the value will not be changed, but flags will be ORed in
    436 // that allows variables to be unarchived without needing bitflags
    437 // if value is "", the value will not override a previously set value.
    438 
    439 void	Cvar_Register( vmCvar_t *vmCvar, const char *varName, const char *defaultValue, int flags );
    440 // basically a slightly modified Cvar_Get for the interpreted modules
    441 
    442 void	Cvar_Update( vmCvar_t *vmCvar );
    443 // updates an interpreted modules' version of a cvar
    444 
    445 void 	Cvar_Set( const char *var_name, const char *value );
    446 // will create the variable with no flags if it doesn't exist
    447 
    448 void Cvar_SetLatched( const char *var_name, const char *value);
    449 // don't set the cvar immediately
    450 
    451 void	Cvar_SetValue( const char *var_name, float value );
    452 // expands value to a string and calls Cvar_Set
    453 
    454 float	Cvar_VariableValue( const char *var_name );
    455 int		Cvar_VariableIntegerValue( const char *var_name );
    456 // returns 0 if not defined or non numeric
    457 
    458 char	*Cvar_VariableString( const char *var_name );
    459 void	Cvar_VariableStringBuffer( const char *var_name, char *buffer, int bufsize );
    460 // returns an empty string if not defined
    461 
    462 void	Cvar_CommandCompletion( void(*callback)(const char *s) );
    463 // callback with each valid string
    464 
    465 void 	Cvar_Reset( const char *var_name );
    466 
    467 void	Cvar_SetCheatState( void );
    468 // reset all testing vars to a safe value
    469 
    470 qboolean Cvar_Command( void );
    471 // called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known
    472 // command.  Returns true if the command was a variable reference that
    473 // was handled. (print or change)
    474 
    475 void 	Cvar_WriteVariables( fileHandle_t f );
    476 // writes lines containing "set variable value" for all variables
    477 // with the archive flag set to true.
    478 
    479 void	Cvar_Init( void );
    480 
    481 char	*Cvar_InfoString( int bit );
    482 char	*Cvar_InfoString_Big( int bit );
    483 // returns an info string containing all the cvars that have the given bit set
    484 // in their flags ( CVAR_USERINFO, CVAR_SERVERINFO, CVAR_SYSTEMINFO, etc )
    485 void	Cvar_InfoStringBuffer( int bit, char *buff, int buffsize );
    486 
    487 void	Cvar_Restart_f( void );
    488 
    489 extern	int			cvar_modifiedFlags;
    490 // whenever a cvar is modifed, its flags will be OR'd into this, so
    491 // a single check can determine if any CVAR_USERINFO, CVAR_SERVERINFO,
    492 // etc, variables have been modified since the last check.  The bit
    493 // can then be cleared to allow another change detection.
    494 
    495 /*
    496 ==============================================================
    497 
    498 FILESYSTEM
    499 
    500 No stdio calls should be used by any part of the game, because
    501 we need to deal with all sorts of directory and seperator char
    502 issues.
    503 ==============================================================
    504 */
    505 
    506 // referenced flags
    507 // these are in loop specific order so don't change the order
    508 #define FS_GENERAL_REF	0x01
    509 #define FS_UI_REF		0x02
    510 #define FS_CGAME_REF	0x04
    511 #define FS_QAGAME_REF	0x08
    512 // number of id paks that will never be autodownloaded from baseq3
    513 #define NUM_ID_PAKS		9
    514 
    515 #define	MAX_FILE_HANDLES	64
    516 
    517 #define BASEGAME "baseq3"
    518 
    519 qboolean FS_Initialized();
    520 
    521 void	FS_InitFilesystem (void);
    522 void	FS_Shutdown( qboolean closemfp );
    523 
    524 qboolean	FS_ConditionalRestart( int checksumFeed );
    525 void	FS_Restart( int checksumFeed );
    526 // shutdown and restart the filesystem so changes to fs_gamedir can take effect
    527 
    528 char	**FS_ListFiles( const char *directory, const char *extension, int *numfiles );
    529 // directory should not have either a leading or trailing /
    530 // if extension is "/", only subdirectories will be returned
    531 // the returned files will not include any directories or /
    532 
    533 void	FS_FreeFileList( char **list );
    534 
    535 qboolean FS_FileExists( const char *file );
    536 
    537 int		FS_LoadStack();
    538 
    539 int		FS_GetFileList(  const char *path, const char *extension, char *listbuf, int bufsize );
    540 int		FS_GetModList(  char *listbuf, int bufsize );
    541 
    542 fileHandle_t	FS_FOpenFileWrite( const char *qpath );
    543 // will properly create any needed paths and deal with seperater character issues
    544 
    545 int		FS_filelength( fileHandle_t f );
    546 fileHandle_t FS_SV_FOpenFileWrite( const char *filename );
    547 int		FS_SV_FOpenFileRead( const char *filename, fileHandle_t *fp );
    548 void	FS_SV_Rename( const char *from, const char *to );
    549 int		FS_FOpenFileRead( const char *qpath, fileHandle_t *file, qboolean uniqueFILE );
    550 // if uniqueFILE is true, then a new FILE will be fopened even if the file
    551 // is found in an already open pak file.  If uniqueFILE is false, you must call
    552 // FS_FCloseFile instead of fclose, otherwise the pak FILE would be improperly closed
    553 // It is generally safe to always set uniqueFILE to true, because the majority of
    554 // file IO goes through FS_ReadFile, which Does The Right Thing already.
    555 
    556 int		FS_FileIsInPAK(const char *filename, int *pChecksum );
    557 // returns 1 if a file is in the PAK file, otherwise -1
    558 
    559 int		FS_Write( const void *buffer, int len, fileHandle_t f );
    560 
    561 int		FS_Read2( void *buffer, int len, fileHandle_t f );
    562 int		FS_Read( void *buffer, int len, fileHandle_t f );
    563 // properly handles partial reads and reads from other dlls
    564 
    565 void	FS_FCloseFile( fileHandle_t f );
    566 // note: you can't just fclose from another DLL, due to MS libc issues
    567 
    568 int		FS_ReadFile( const char *qpath, void **buffer );
    569 // returns the length of the file
    570 // a null buffer will just return the file length without loading
    571 // as a quick check for existance. -1 length == not present
    572 // A 0 byte will always be appended at the end, so string ops are safe.
    573 // the buffer should be considered read-only, because it may be cached
    574 // for other uses.
    575 
    576 void	FS_ForceFlush( fileHandle_t f );
    577 // forces flush on files we're writing to.
    578 
    579 void	FS_FreeFile( void *buffer );
    580 // frees the memory returned by FS_ReadFile
    581 
    582 void	FS_WriteFile( const char *qpath, const void *buffer, int size );
    583 // writes a complete file, creating any subdirectories needed
    584 
    585 int		FS_filelength( fileHandle_t f );
    586 // doesn't work for files that are opened from a pack file
    587 
    588 int		FS_FTell( fileHandle_t f );
    589 // where are we?
    590 
    591 void	FS_Flush( fileHandle_t f );
    592 
    593 void 	QDECL FS_Printf( fileHandle_t f, const char *fmt, ... );
    594 // like fprintf
    595 
    596 int		FS_FOpenFileByMode( const char *qpath, fileHandle_t *f, fsMode_t mode );
    597 // opens a file for reading, writing, or appending depending on the value of mode
    598 
    599 int		FS_Seek( fileHandle_t f, long offset, int origin );
    600 // seek on a file (doesn't work for zip files!!!!!!!!)
    601 
    602 qboolean FS_FilenameCompare( const char *s1, const char *s2 );
    603 
    604 const char *FS_GamePureChecksum( void );
    605 // Returns the checksum of the pk3 from which the server loaded the qagame.qvm
    606 
    607 const char *FS_LoadedPakNames( void );
    608 const char *FS_LoadedPakChecksums( void );
    609 const char *FS_LoadedPakPureChecksums( void );
    610 // Returns a space separated string containing the checksums of all loaded pk3 files.
    611 // Servers with sv_pure set will get this string and pass it to clients.
    612 
    613 const char *FS_ReferencedPakNames( void );
    614 const char *FS_ReferencedPakChecksums( void );
    615 const char *FS_ReferencedPakPureChecksums( void );
    616 // Returns a space separated string containing the checksums of all loaded 
    617 // AND referenced pk3 files. Servers with sv_pure set will get this string 
    618 // back from clients for pure validation 
    619 
    620 void FS_ClearPakReferences( int flags );
    621 // clears referenced booleans on loaded pk3s
    622 
    623 void FS_PureServerSetReferencedPaks( const char *pakSums, const char *pakNames );
    624 void FS_PureServerSetLoadedPaks( const char *pakSums, const char *pakNames );
    625 // If the string is empty, all data sources will be allowed.
    626 // If not empty, only pk3 files that match one of the space
    627 // separated checksums will be checked for files, with the
    628 // sole exception of .cfg files.
    629 
    630 qboolean FS_idPak( char *pak, char *base );
    631 qboolean FS_ComparePaks( char *neededpaks, int len, qboolean dlstring );
    632 
    633 void FS_Rename( const char *from, const char *to );
    634 
    635 /*
    636 ==============================================================
    637 
    638 Edit fields and command line history/completion
    639 
    640 ==============================================================
    641 */
    642 
    643 #define	MAX_EDIT_LINE	256
    644 typedef struct {
    645 	int		cursor;
    646 	int		scroll;
    647 	int		widthInChars;
    648 	char	buffer[MAX_EDIT_LINE];
    649 } field_t;
    650 
    651 void Field_Clear( field_t *edit );
    652 void Field_CompleteCommand( field_t *edit );
    653 
    654 /*
    655 ==============================================================
    656 
    657 MISC
    658 
    659 ==============================================================
    660 */
    661 
    662 // TTimo
    663 // vsnprintf is ISO/IEC 9899:1999
    664 // abstracting this to make it portable
    665 #ifdef WIN32
    666 #define Q_vsnprintf _vsnprintf
    667 #else
    668 // TODO: do we need Mac define?
    669 #define Q_vsnprintf vsnprintf
    670 #endif
    671 
    672 // centralizing the declarations for cl_cdkey
    673 // https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=470
    674 extern char cl_cdkey[34];
    675 
    676 // returnbed by Sys_GetProcessorId
    677 #define CPUID_GENERIC			0			// any unrecognized processor
    678 
    679 #define CPUID_AXP				0x10
    680 
    681 #define CPUID_INTEL_UNSUPPORTED	0x20			// Intel 386/486
    682 #define CPUID_INTEL_PENTIUM		0x21			// Intel Pentium or PPro
    683 #define CPUID_INTEL_MMX			0x22			// Intel Pentium/MMX or P2/MMX
    684 #define CPUID_INTEL_KATMAI		0x23			// Intel Katmai
    685 
    686 #define CPUID_AMD_3DNOW			0x30			// AMD K6 3DNOW!
    687 
    688 // TTimo
    689 // centralized and cleaned, that's the max string you can send to a Com_Printf / Com_DPrintf (above gets truncated)
    690 #define	MAXPRINTMSG	4096
    691 
    692 char		*CopyString( const char *in );
    693 void		Info_Print( const char *s );
    694 
    695 void		Com_BeginRedirect (char *buffer, int buffersize, void (*flush)(char *));
    696 void		Com_EndRedirect( void );
    697 void 		QDECL Com_Printf( const char *fmt, ... );
    698 void 		QDECL Com_DPrintf( const char *fmt, ... );
    699 void 		QDECL Com_Error( int code, const char *fmt, ... );
    700 void 		Com_Quit_f( void );
    701 int			Com_EventLoop( void );
    702 int			Com_Milliseconds( void );	// will be journaled properly
    703 unsigned	Com_BlockChecksum( const void *buffer, int length );
    704 unsigned	Com_BlockChecksumKey (void *buffer, int length, int key);
    705 int			Com_HashKey(char *string, int maxlen);
    706 int			Com_Filter(char *filter, char *name, int casesensitive);
    707 int			Com_FilterPath(char *filter, char *name, int casesensitive);
    708 int			Com_RealTime(qtime_t *qtime);
    709 qboolean	Com_SafeMode( void );
    710 
    711 void		Com_StartupVariable( const char *match );
    712 // checks for and removes command line "+set var arg" constructs
    713 // if match is NULL, all set commands will be executed, otherwise
    714 // only a set with the exact name.  Only used during startup.
    715 
    716 
    717 extern	cvar_t	*com_developer;
    718 extern	cvar_t	*com_dedicated;
    719 extern	cvar_t	*com_speeds;
    720 extern	cvar_t	*com_timescale;
    721 extern	cvar_t	*com_sv_running;
    722 extern	cvar_t	*com_cl_running;
    723 extern	cvar_t	*com_viewlog;			// 0 = hidden, 1 = visible, 2 = minimized
    724 extern	cvar_t	*com_version;
    725 extern	cvar_t	*com_blood;
    726 extern	cvar_t	*com_buildScript;		// for building release pak files
    727 extern	cvar_t	*com_journal;
    728 extern	cvar_t	*com_cameraMode;
    729 
    730 // both client and server must agree to pause
    731 extern	cvar_t	*cl_paused;
    732 extern	cvar_t	*sv_paused;
    733 
    734 // com_speeds times
    735 extern	int		time_game;
    736 extern	int		time_frontend;
    737 extern	int		time_backend;		// renderer backend time
    738 
    739 extern	int		com_frameTime;
    740 extern	int		com_frameMsec;
    741 
    742 extern	qboolean	com_errorEntered;
    743 
    744 extern	fileHandle_t	com_journalFile;
    745 extern	fileHandle_t	com_journalDataFile;
    746 
    747 typedef enum {
    748 	TAG_FREE,
    749 	TAG_GENERAL,
    750 	TAG_BOTLIB,
    751 	TAG_RENDERER,
    752 	TAG_SMALL,
    753 	TAG_STATIC
    754 } memtag_t;
    755 
    756 /*
    757 
    758 --- low memory ----
    759 server vm
    760 server clipmap
    761 ---mark---
    762 renderer initialization (shaders, etc)
    763 UI vm
    764 cgame vm
    765 renderer map
    766 renderer models
    767 
    768 ---free---
    769 
    770 temp file loading
    771 --- high memory ---
    772 
    773 */
    774 
    775 #if defined(_DEBUG) && !defined(BSPC)
    776 	#define ZONE_DEBUG
    777 #endif
    778 
    779 #ifdef ZONE_DEBUG
    780 #define Z_TagMalloc(size, tag)			Z_TagMallocDebug(size, tag, #size, __FILE__, __LINE__)
    781 #define Z_Malloc(size)					Z_MallocDebug(size, #size, __FILE__, __LINE__)
    782 #define S_Malloc(size)					S_MallocDebug(size, #size, __FILE__, __LINE__)
    783 void *Z_TagMallocDebug( int size, int tag, char *label, char *file, int line );	// NOT 0 filled memory
    784 void *Z_MallocDebug( int size, char *label, char *file, int line );			// returns 0 filled memory
    785 void *S_MallocDebug( int size, char *label, char *file, int line );			// returns 0 filled memory
    786 #else
    787 void *Z_TagMalloc( int size, int tag );	// NOT 0 filled memory
    788 void *Z_Malloc( int size );			// returns 0 filled memory
    789 void *S_Malloc( int size );			// NOT 0 filled memory only for small allocations
    790 #endif
    791 void Z_Free( void *ptr );
    792 void Z_FreeTags( int tag );
    793 int Z_AvailableMemory( void );
    794 void Z_LogHeap( void );
    795 
    796 void Hunk_Clear( void );
    797 void Hunk_ClearToMark( void );
    798 void Hunk_SetMark( void );
    799 qboolean Hunk_CheckMark( void );
    800 void Hunk_ClearTempMemory( void );
    801 void *Hunk_AllocateTempMemory( int size );
    802 void Hunk_FreeTempMemory( void *buf );
    803 int	Hunk_MemoryRemaining( void );
    804 void Hunk_Log( void);
    805 void Hunk_Trash( void );
    806 
    807 void Com_TouchMemory( void );
    808 
    809 // commandLine should not include the executable name (argv[0])
    810 void Com_Init( char *commandLine );
    811 void Com_Frame( void );
    812 void Com_Shutdown( void );
    813 
    814 
    815 /*
    816 ==============================================================
    817 
    818 CLIENT / SERVER SYSTEMS
    819 
    820 ==============================================================
    821 */
    822 
    823 //
    824 // client interface
    825 //
    826 void CL_InitKeyCommands( void );
    827 // the keyboard binding interface must be setup before execing
    828 // config files, but the rest of client startup will happen later
    829 
    830 void CL_Init( void );
    831 void CL_Disconnect( qboolean showMainMenu );
    832 void CL_Shutdown( void );
    833 void CL_Frame( int msec );
    834 qboolean CL_GameCommand( void );
    835 void CL_KeyEvent (int key, qboolean down, unsigned time);
    836 
    837 void CL_CharEvent( int key );
    838 // char events are for field typing, not game control
    839 
    840 void CL_MouseEvent( int dx, int dy, int time );
    841 
    842 void CL_JoystickEvent( int axis, int value, int time );
    843 
    844 void CL_PacketEvent( netadr_t from, msg_t *msg );
    845 
    846 void CL_ConsolePrint( char *text );
    847 
    848 void CL_MapLoading( void );
    849 // do a screen update before starting to load a map
    850 // when the server is going to load a new map, the entire hunk
    851 // will be cleared, so the client must shutdown cgame, ui, and
    852 // the renderer
    853 
    854 void	CL_ForwardCommandToServer( const char *string );
    855 // adds the current command line as a clc_clientCommand to the client message.
    856 // things like godmode, noclip, etc, are commands directed to the server,
    857 // so when they are typed in at the console, they will need to be forwarded.
    858 
    859 void CL_CDDialog( void );
    860 // bring up the "need a cd to play" dialog
    861 
    862 void CL_ShutdownAll( void );
    863 // shutdown all the client stuff
    864 
    865 void CL_FlushMemory( void );
    866 // dump all memory on an error
    867 
    868 void CL_StartHunkUsers( void );
    869 // start all the client stuff using the hunk
    870 
    871 void Key_WriteBindings( fileHandle_t f );
    872 // for writing the config files
    873 
    874 void S_ClearSoundBuffer( void );
    875 // call before filesystem access
    876 
    877 void SCR_DebugGraph (float value, int color);	// FIXME: move logging to common?
    878 
    879 
    880 //
    881 // server interface
    882 //
    883 void SV_Init( void );
    884 void SV_Shutdown( char *finalmsg );
    885 void SV_Frame( int msec );
    886 void SV_PacketEvent( netadr_t from, msg_t *msg );
    887 qboolean SV_GameCommand( void );
    888 
    889 
    890 //
    891 // UI interface
    892 //
    893 qboolean UI_GameCommand( void );
    894 qboolean UI_usesUniqueCDKey();
    895 
    896 /*
    897 ==============================================================
    898 
    899 NON-PORTABLE SYSTEM SERVICES
    900 
    901 ==============================================================
    902 */
    903 
    904 typedef enum {
    905 	AXIS_SIDE,
    906 	AXIS_FORWARD,
    907 	AXIS_UP,
    908 	AXIS_ROLL,
    909 	AXIS_YAW,
    910 	AXIS_PITCH,
    911 	MAX_JOYSTICK_AXIS
    912 } joystickAxis_t;
    913 
    914 typedef enum {
    915   // bk001129 - make sure SE_NONE is zero
    916 	SE_NONE = 0,	// evTime is still valid
    917 	SE_KEY,		// evValue is a key code, evValue2 is the down flag
    918 	SE_CHAR,	// evValue is an ascii char
    919 	SE_MOUSE,	// evValue and evValue2 are reletive signed x / y moves
    920 	SE_JOYSTICK_AXIS,	// evValue is an axis number and evValue2 is the current state (-127 to 127)
    921 	SE_CONSOLE,	// evPtr is a char*
    922 	SE_PACKET	// evPtr is a netadr_t followed by data bytes to evPtrLength
    923 } sysEventType_t;
    924 
    925 typedef struct {
    926 	int				evTime;
    927 	sysEventType_t	evType;
    928 	int				evValue, evValue2;
    929 	int				evPtrLength;	// bytes of data pointed to by evPtr, for journaling
    930 	void			*evPtr;			// this must be manually freed if not NULL
    931 } sysEvent_t;
    932 
    933 sysEvent_t	Sys_GetEvent( void );
    934 
    935 void	Sys_Init (void);
    936 
    937 // general development dll loading for virtual machine testing
    938 // fqpath param added 7/20/02 by T.Ray - Sys_LoadDll is only called in vm.c at this time
    939 void	* QDECL Sys_LoadDll( const char *name, char *fqpath , int (QDECL **entryPoint)(int, ...),
    940 				  int (QDECL *systemcalls)(int, ...) );
    941 void	Sys_UnloadDll( void *dllHandle );
    942 
    943 void	Sys_UnloadGame( void );
    944 void	*Sys_GetGameAPI( void *parms );
    945 
    946 void	Sys_UnloadCGame( void );
    947 void	*Sys_GetCGameAPI( void );
    948 
    949 void	Sys_UnloadUI( void );
    950 void	*Sys_GetUIAPI( void );
    951 
    952 //bot libraries
    953 void	Sys_UnloadBotLib( void );
    954 void	*Sys_GetBotLibAPI( void *parms );
    955 
    956 char	*Sys_GetCurrentUser( void );
    957 
    958 void	QDECL Sys_Error( const char *error, ...);
    959 void	Sys_Quit (void);
    960 char	*Sys_GetClipboardData( void );	// note that this isn't journaled...
    961 
    962 void	Sys_Print( const char *msg );
    963 
    964 // Sys_Milliseconds should only be used for profiling purposes,
    965 // any game related timing information should come from event timestamps
    966 int		Sys_Milliseconds (void);
    967 
    968 void	Sys_SnapVector( float *v );
    969 
    970 // the system console is shown when a dedicated server is running
    971 void	Sys_DisplaySystemConsole( qboolean show );
    972 
    973 int		Sys_GetProcessorId( void );
    974 
    975 void	Sys_BeginStreamedFile( fileHandle_t f, int readahead );
    976 void	Sys_EndStreamedFile( fileHandle_t f );
    977 int		Sys_StreamedRead( void *buffer, int size, int count, fileHandle_t f );
    978 void	Sys_StreamSeek( fileHandle_t f, int offset, int origin );
    979 
    980 void	Sys_ShowConsole( int level, qboolean quitOnClose );
    981 void	Sys_SetErrorText( const char *text );
    982 
    983 void	Sys_SendPacket( int length, const void *data, netadr_t to );
    984 
    985 qboolean	Sys_StringToAdr( const char *s, netadr_t *a );
    986 //Does NOT parse port numbers, only base addresses.
    987 
    988 qboolean	Sys_IsLANAddress (netadr_t adr);
    989 void		Sys_ShowIP(void);
    990 
    991 qboolean	Sys_CheckCD( void );
    992 
    993 void	Sys_Mkdir( const char *path );
    994 char	*Sys_Cwd( void );
    995 void	Sys_SetDefaultCDPath(const char *path);
    996 char	*Sys_DefaultCDPath(void);
    997 void	Sys_SetDefaultInstallPath(const char *path);
    998 char	*Sys_DefaultInstallPath(void);
    999 void  Sys_SetDefaultHomePath(const char *path);
   1000 char	*Sys_DefaultHomePath(void);
   1001 
   1002 char **Sys_ListFiles( const char *directory, const char *extension, char *filter, int *numfiles, qboolean wantsubs );
   1003 void	Sys_FreeFileList( char **list );
   1004 
   1005 void	Sys_BeginProfiling( void );
   1006 void	Sys_EndProfiling( void );
   1007 
   1008 qboolean Sys_LowPhysicalMemory();
   1009 unsigned int Sys_ProcessorCount();
   1010 
   1011 int Sys_MonkeyShouldBeSpanked( void );
   1012 
   1013 /* This is based on the Adaptive Huffman algorithm described in Sayood's Data
   1014  * Compression book.  The ranks are not actually stored, but implicitly defined
   1015  * by the location of a node within a doubly-linked list */
   1016 
   1017 #define NYT HMAX					/* NYT = Not Yet Transmitted */
   1018 #define INTERNAL_NODE (HMAX+1)
   1019 
   1020 typedef struct nodetype {
   1021 	struct	nodetype *left, *right, *parent; /* tree structure */ 
   1022 	struct	nodetype *next, *prev; /* doubly-linked list */
   1023 	struct	nodetype **head; /* highest ranked node in block */
   1024 	int		weight;
   1025 	int		symbol;
   1026 } node_t;
   1027 
   1028 #define HMAX 256 /* Maximum symbol */
   1029 
   1030 typedef struct {
   1031 	int			blocNode;
   1032 	int			blocPtrs;
   1033 
   1034 	node_t*		tree;
   1035 	node_t*		lhead;
   1036 	node_t*		ltail;
   1037 	node_t*		loc[HMAX+1];
   1038 	node_t**	freelist;
   1039 
   1040 	node_t		nodeList[768];
   1041 	node_t*		nodePtrs[768];
   1042 } huff_t;
   1043 
   1044 typedef struct {
   1045 	huff_t		compressor;
   1046 	huff_t		decompressor;
   1047 } huffman_t;
   1048 
   1049 void	Huff_Compress(msg_t *buf, int offset);
   1050 void	Huff_Decompress(msg_t *buf, int offset);
   1051 void	Huff_Init(huffman_t *huff);
   1052 void	Huff_addRef(huff_t* huff, byte ch);
   1053 int		Huff_Receive (node_t *node, int *ch, byte *fin);
   1054 void	Huff_transmit (huff_t *huff, int ch, byte *fout);
   1055 void	Huff_offsetReceive (node_t *node, int *ch, byte *fin, int *offset);
   1056 void	Huff_offsetTransmit (huff_t *huff, int ch, byte *fout, int *offset);
   1057 void	Huff_putBit( int bit, byte *fout, int *offset);
   1058 int		Huff_getBit( byte *fout, int *offset);
   1059 
   1060 extern huffman_t clientHuffTables;
   1061 
   1062 #define	SV_ENCODE_START		4
   1063 #define SV_DECODE_START		12
   1064 #define	CL_ENCODE_START		12
   1065 #define CL_DECODE_START		4
   1066 
   1067 #endif // _QCOMMON_H_