| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 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 |
|
| 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; |
| 56 |
int numClusters; |
| 57 |
int clusternums[MAX_ENT_CLUSTERS]; |
| 58 |
int lastCluster; |
| 59 |
int areanum, areanum2; |
| 60 |
int snapshotCounter; |
| 61 |
} svEntity_t; |
| 62 |
|
| 63 |
typedef enum { |
| 64 |
SS_DEAD, |
| 65 |
SS_LOADING, |
| 66 |
SS_GAME |
| 67 |
} serverState_t; |
| 68 |
|
| 69 |
typedef struct { |
| 70 |
serverState_t state; |
| 71 |
qboolean restarting; |
| 72 |
int serverId; |
| 73 |
int restartedServerId; |
| 74 |
int checksumFeed; |
| 75 |
|
| 76 |
|
| 77 |
int checksumFeedServerId; |
| 78 |
int snapshotCounter; |
| 79 |
int timeResidual; |
| 80 |
int nextFrameTime; |
| 81 |
char *configstrings[MAX_CONFIGSTRINGS]; |
| 82 |
svEntity_t svEntities[MAX_GENTITIES]; |
| 83 |
|
| 84 |
char *entityParsePoint; |
| 85 |
|
| 86 |
|
| 87 |
sharedEntity_t *gentities; |
| 88 |
int gentitySize; |
| 89 |
int num_entities; |
| 90 |
|
| 91 |
playerState_t *gameClients; |
| 92 |
int gameClientSize; |
| 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]; |
| 105 |
playerState_t ps; |
| 106 |
int num_entities; |
| 107 |
int first_entity; |
| 108 |
|
| 109 |
|
| 110 |
int messageSent; |
| 111 |
int messageAcked; |
| 112 |
int messageSize; |
| 113 |
} clientSnapshot_t; |
| 114 |
|
| 115 |
typedef enum { |
| 116 |
CS_FREE, |
| 117 |
CS_ZOMBIE, |
| 118 |
|
| 119 |
CS_CONNECTED, |
| 120 |
CS_PRIMED, |
| 121 |
CS_ACTIVE |
| 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]; |
| 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]; |
| 136 |
|
| 137 |
char reliableCommands[MAX_RELIABLE_COMMANDS][MAX_STRING_CHARS]; |
| 138 |
int reliableSequence; |
| 139 |
int reliableAcknowledge; |
| 140 |
int reliableSent; |
| 141 |
int messageAcknowledge; |
| 142 |
|
| 143 |
int gamestateMessageNum; |
| 144 |
int challenge; |
| 145 |
|
| 146 |
usercmd_t lastUsercmd; |
| 147 |
int lastMessageNum; |
| 148 |
int lastClientCommand; |
| 149 |
char lastClientCommandString[MAX_STRING_CHARS]; |
| 150 |
sharedEntity_t *gentity; |
| 151 |
char name[MAX_NAME_LENGTH]; |
| 152 |
|
| 153 |
|
| 154 |
char downloadName[MAX_QPATH]; |
| 155 |
fileHandle_t download; |
| 156 |
int downloadSize; |
| 157 |
int downloadCount; |
| 158 |
int downloadClientBlock; |
| 159 |
int downloadCurrentBlock; |
| 160 |
int downloadXmitBlock; |
| 161 |
unsigned char *downloadBlocks[MAX_DOWNLOAD_WINDOW]; |
| 162 |
int downloadBlockSize[MAX_DOWNLOAD_WINDOW]; |
| 163 |
qboolean downloadEOF; |
| 164 |
int downloadSendTime; |
| 165 |
|
| 166 |
int deltaMessage; |
| 167 |
int nextReliableTime; |
| 168 |
int lastPacketTime; |
| 169 |
int lastConnectTime; |
| 170 |
int lastSnapshotTime; |
| 171 |
qboolean rateDelayed; |
| 172 |
int timeoutCount; |
| 173 |
clientSnapshot_t frames[PACKET_BACKUP]; |
| 174 |
int ping; |
| 175 |
int rate; |
| 176 |
int snapshotMsec; |
| 177 |
int pureAuthentic; |
| 178 |
qboolean gotCP; |
| 179 |
netchan_t netchan; |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 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 |
|
| 208 |
|
| 209 |
|
| 210 |
#define MAX_CHALLENGES 2048 |
| 211 |
|
| 212 |
|
| 213 |
|
| 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; |
| 222 |
int time; |
| 223 |
int pingTime; |
| 224 |
int firstTime; |
| 225 |
qboolean wasrefused; |
| 226 |
qboolean connected; |
| 227 |
} challenge_t; |
| 228 |
|
| 229 |
|
| 230 |
typedef struct { |
| 231 |
qboolean initialized; |
| 232 |
|
| 233 |
int time; |
| 234 |
|
| 235 |
int snapFlagServerBit; |
| 236 |
|
| 237 |
client_t *clients; |
| 238 |
int numSnapshotEntities; |
| 239 |
int nextSnapshotEntities; |
| 240 |
entityState_t *snapshotEntities; |
| 241 |
int nextHeartbeatTime; |
| 242 |
challenge_t challenges[MAX_CHALLENGES]; |
| 243 |
netadr_t redirectAddress; |
| 244 |
#ifndef STANDALONE |
| 245 |
netadr_t authorizeAddress; |
| 246 |
#endif |
| 247 |
int masterResolveTime[MAX_MASTER_SERVERS]; |
| 248 |
} serverStatic_t; |
| 249 |
|
| 250 |
#define SERVER_MAXBANS 1024 |
| 251 |
|
| 252 |
typedef struct |
| 253 |
{ |
| 254 |
netadr_t ip; |
| 255 |
|
| 256 |
int subnet; |
| 257 |
|
| 258 |
qboolean isexception; |
| 259 |
} serverBan_t; |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
extern serverStatic_t svs; |
| 264 |
extern server_t sv; |
| 265 |
extern vm_t *gvm; |
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 392 |
|
| 393 |
void SV_Heartbeat_f( void ); |
| 394 |
|
| 395 |
|
| 396 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 439 |
|
| 440 |
|
| 441 |
void SV_ClearWorld (void); |
| 442 |
|
| 443 |
|
| 444 |
void SV_UnlinkEntity( sharedEntity_t *ent ); |
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
void SV_LinkEntity( sharedEntity_t *ent ); |
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 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 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
int SV_PointContents( const vec3_t p, int passEntityNum ); |
| 472 |
|
| 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 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 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 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 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); |