/
noire-dev
/
SourceTech
Обзор
Документация
Войти
/
noire-dev
/
SourceTech
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
sourcetech
code/server/sv_client.c
1 704 строки
48 KB
noire-dev
Update: 2025-11-27 17:57 Clean
27 ноя 2025, 08:57
27 ноя 2025, 08:57
2eb9cc0
Код
Авторство
О чём код?
/* =========================================================================== Copyright (C) 1999-2005 Id Software, Inc. This file is part of Quake III Arena source code. Quake III Arena source code is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Quake III Arena source code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Quake III Arena source code; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA =========================================================================== */ // sv_client.c -- server code for dealing with clients #include "server.h" static void SV_CloseDownload( client_t *cl ); // // Server-side Stateless Challenges // backported from https://github.com/JACoders/OpenJK/pull/832 // #define TS_SHIFT 14 // ~16 seconds to reply to the challenge /* ================= SV_CreateChallenge Create an unforgeable, temporal challenge for the given client address ================= */ static int SV_CreateChallenge( int timestamp, const netadr_t *from ) { int challenge; // Create an unforgeable, temporal challenge for this client using HMAC(secretKey, clientParams + timestamp) // Use first 4 bytes of the HMAC digest as an int (client only deals with numeric challenges) // The most-significant bit stores whether the timestamp is odd or even. This lets later verification code handle the // case where the engine timestamp has incremented between the time this challenge is sent and the client replies. challenge = Com_MD5Addr( from, timestamp ); challenge &= 0x7FFFFFFF; challenge |= (unsigned int)(timestamp & 0x1) << 31; return challenge; } /* ================= SV_CreateChallenge Verify a challenge received by the client matches the expected challenge ================= */ static qboolean SV_VerifyChallenge( int receivedChallenge, const netadr_t *from ) { int currentTimestamp = svs.time >> TS_SHIFT; int currentPeriod = currentTimestamp & 0x1; // Use the current timestamp for verification if the current period matches the client challenge's period. // Otherwise, use the previous timestamp in case the current timestamp incremented in the time between the // client being sent a challenge and the client's reply that's being verified now. int challengePeriod = ((unsigned int)receivedChallenge >> 31) & 0x1; int challengeTimestamp = currentTimestamp - ( currentPeriod ^ challengePeriod ); int expectedChallenge = SV_CreateChallenge( challengeTimestamp, from ); return (receivedChallenge == expectedChallenge) ? qtrue : qfalse; } /* ================= SV_InitChallenger ================= */ void SV_InitChallenger( void ) { Com_MD5Init(); } /* ================= SV_GetChallenge A "getchallenge" OOB command has been received Returns a challenge number that can be used in a subsequent connectResponse command. We do this to prevent denial of service attacks that flood the server with invalid connection IPs. With a challenge, they must give a valid IP address. If we are authorizing, a challenge request will cause a packet to be sent to the authorize server. When an authorizeip is returned, a challenge response will be sent to that ip. ================= */ void SV_GetChallenge( const netadr_t *from ) { int challenge; int clientChallenge; // Prevent using getchallenge as an amplifier if ( SVC_RateLimitAddress( from, 10, 1000 ) ) { if ( com_developer->integer ) { Com_Printf( "SV_GetChallenge: rate limit from %s exceeded, dropping request\n", NET_AdrToString( from ) ); } return; } // Create a unique challenge for this client without storing state on the server challenge = SV_CreateChallenge( svs.time >> TS_SHIFT, from ); if ( Cmd_Argc() < 2 ) { // legacy client query, don't send unneeded information NET_OutOfBandPrint( NS_SERVER, from, "challengeResponse %i", challenge ); } else { // Grab the client's challenge to echo back (if given) clientChallenge = atoi( Cmd_Argv( 1 ) ); NET_OutOfBandPrint( NS_SERVER, from, "challengeResponse %i %i", challenge, clientChallenge ); } } static const char *SV_GetStateName( clientState_t state ) { switch ( state ) { case CS_FREE: return "CS_FREE"; case CS_ZOMBIE: return "CS_ZOMBIE"; case CS_CONNECTED: return "CS_CONNECTED"; case CS_PRIMED: return "CS_PRIMED"; case CS_ACTIVE: return "CS_ACTIVE"; default: return "CS_UNKNOWN"; } } void SV_PrintClientStateChange( const client_t *cl, clientState_t newState ) { if ( cl->state == newState ) { return; } #ifndef _DEBUG if ( com_developer->integer == 0 ) { return; } #endif // !_DEBUG if ( cl->name[0] != '\0' ) { Com_Printf( "Going from %s to %s for %s\n", SV_GetStateName( cl->state ), SV_GetStateName( newState ), cl->name ); } else { Com_Printf( "Going from %s to %s for client %d\n", SV_GetStateName( cl->state ), SV_GetStateName( newState ), (int)(cl - svs.clients) ); } } /* ================== SV_DirectConnect A "connect" OOB command has been received ================== */ void SV_DirectConnect( const netadr_t *from ) { static rateLimit_t bucket; char userinfo[MAX_INFO_STRING]; int i, n; client_t *cl, *newcl; int clientNum; int qport; int challenge; const char *password; int startIndex; intptr_t denied; int count; const char *ip, *info, *v; Com_DPrintf( "SVC_DirectConnect()\n" ); // Prevent using connect as an amplifier if ( SVC_RateLimitAddress( from, 10, 1000 ) ) { if ( com_developer->integer ) { Com_Printf( "SV_DirectConnect: rate limit from %s exceeded, dropping request\n", NET_AdrToString( from ) ); } return; } // check for concurrent connections for ( i = 0, n = 0; i < sv.maxclients; i++ ) { const netadr_t *addr = &svs.clients[ i ].netchan.remoteAddress; if ( addr->type != NA_BOT && NET_CompareBaseAdr( addr, from ) ) { if ( svs.clients[ i ].state >= CS_CONNECTED && !svs.clients[ i ].justConnected ) { if ( ++n >= sv_maxclientsPerIP->integer ) { // avoid excessive outgoing traffic if ( !SVC_RateLimit( &bucket, 10, 200 ) ) { NET_OutOfBandPrint( NS_SERVER, from, "print\nToo many connections.\n" ); } return; } } } } // verify challenge in first place info = Cmd_Argv( 1 ); v = Info_ValueForKey( info, "challenge" ); if ( *v == '\0' ) { if ( !SVC_RateLimit( &bucket, 10, 200 ) ) { NET_OutOfBandPrint( NS_SERVER, from, "print\nMissing challenge in userinfo.\n" ); } return; } challenge = atoi( v ); // see if the challenge is valid (localhost clients don't need to challenge) if ( !NET_IsLocalAddress( from ) ) { // Verify the received challenge against the expected challenge if ( !SV_VerifyChallenge( challenge, from ) ) { // avoid excessive outgoing traffic if ( !SVC_RateLimit( &bucket, 10, 200 ) ) { NET_OutOfBandPrint( NS_SERVER, from, "print\nIncorrect challenge, please reconnect.\n" ); } return; } } Q_strncpyz( userinfo, info, sizeof( userinfo ) ); v = Info_ValueForKey( userinfo, "qport" ); if ( *v == '\0' ) { if ( !SVC_RateLimit( &bucket, 10, 200 ) ) { NET_OutOfBandPrint( NS_SERVER, from, "print\nMissing qport in userinfo.\n" ); } return; } qport = atoi( Info_ValueForKey( userinfo, "qport" ) ); // we don't need these keys after connection, release some space in userinfo Info_RemoveKey( userinfo, "challenge" ); Info_RemoveKey( userinfo, "qport" ); Info_RemoveKey( userinfo, "client" ); // don't let "ip" overflow userinfo string if ( NET_IsLocalAddress( from ) ) ip = "localhost"; else ip = NET_AdrToString( from ); if ( !Info_SetValueForKey( userinfo, "ip", ip ) ) { // avoid excessive outgoing traffic if ( !SVC_RateLimit( &bucket, 10, 200 ) ) { NET_OutOfBandPrint( NS_SERVER, from, "print\nUserinfo string length exceeded. " "Try removing setu cvars from your config.\n" ); } return; } // run userinfo filter v = SV_RunFilters( userinfo, from ); if ( *v != '\0' ) { NET_OutOfBandPrint( NS_SERVER, from, "print\n%s\n", v ); Com_DPrintf( "Engine rejected a connection: %s.\n", v ); return; } // restore burst capacity SVC_RateRestoreBurstAddress( from, 10, 1000 ); // quick reject newcl = NULL; for ( i = 0, cl = svs.clients; i < sv.maxclients; i++, cl++ ) { if ( NET_CompareAdr( from, &cl->netchan.remoteAddress ) ) { int elapsed = svs.time - cl->lastConnectTime; if ( elapsed < ( sv_reconnectlimit->integer * 1000 ) && elapsed >= 0 ) { int remains = ( ( sv_reconnectlimit->integer * 1000 ) - elapsed + 999 ) / 1000; if ( com_developer->integer ) { Com_Printf( "%s:reconnect rejected : too soon\n", NET_AdrToString( from ) ); } // avoid excessive outgoing traffic if ( !SVC_RateLimit( &bucket, 10, 200 ) ) { NET_OutOfBandPrint( NS_SERVER, from, "print\nReconnecting, please wait %i second%s.\n", remains, (remains != 1) ? "s" : "" ); } return; } newcl = cl; // we may reuse this slot break; } } // if there is already a slot for this ip, reuse it for ( i = 0, cl = svs.clients; i < sv.maxclients; i++, cl++ ) { if ( cl->state == CS_FREE ) { continue; } if ( NET_CompareAdr( from, &cl->netchan.remoteAddress ) && cl->netchan.qport == qport ) { // both qport and netport should match for a reconnecting client Com_Printf( "%s:reconnect\n", NET_AdrToString( from ) ); newcl = cl; if ( newcl->state >= CS_CONNECTED ) { // call QVM disconnect function before calling connect again // fixes issues such as disappearing CTF flags in unpatched mods VM_Call( gvm, 1, GAME_CLIENT_DISCONNECT, newcl - svs.clients ); // don't leak memory or file handles due to e.g. downloads in progress SV_FreeClient( newcl ); } goto gotnewcl; } } // find a client slot // if "sv_privateClients" is set > 0, then that number // of client slots will be reserved for connections that // have "password" set to the value of "sv_privatePassword" // Info requests will report the maxclients as if the private // slots didn't exist, to prevent people from trying to connect // to a full server. // This is to allow us to reserve a couple slots here on our // servers so we can play without having to kick people. // check for privateClient password password = Info_ValueForKey( userinfo, "password" ); if ( *password && !strcmp( password, sv_privatePassword->string ) ) { startIndex = 0; } else { // skip past the reserved slots startIndex = sv_privateClients->integer; } if ( newcl && newcl >= svs.clients + startIndex && newcl->state == CS_FREE ) { Com_Printf( "%s: reuse slot %i\n", NET_AdrToString( from ), (int)(newcl - svs.clients) ); goto gotnewcl; } // select least used free slot n = 0; newcl = NULL; for ( i = startIndex; i < sv.maxclients; i++ ) { cl = &svs.clients[i]; if ( cl->state == CS_FREE && ( newcl == NULL || svs.time - cl->lastDisconnectTime > n ) ) { n = svs.time - cl->lastDisconnectTime; newcl = cl; } } if ( !newcl ) { if ( NET_IsLocalAddress( from ) ) { count = 0; for ( i = startIndex; i < sv.maxclients; i++ ) { cl = &svs.clients[i]; if (cl->netchan.remoteAddress.type == NA_BOT) { count++; } } // if they're all bots if (count >= sv.maxclients - startIndex) { SV_DropClient(&svs.clients[sv.maxclients - 1], "only bots on server"); newcl = &svs.clients[sv.maxclients - 1]; } else { Com_Error( ERR_DROP, "server is full on local connect" ); return; } } else { NET_OutOfBandPrint( NS_SERVER, from, "print\nServer is full.\n" ); Com_DPrintf ("Rejected a connection.\n"); return; } } gotnewcl: // build a new connection // accept the new client // this is the only place a client_t is ever initialized // we got a newcl, so reset the reliableSequence and reliableAcknowledge Com_Memset( newcl, 0, sizeof( *newcl ) ); clientNum = newcl - svs.clients; // save the challenge newcl->challenge = challenge; // save the address Netchan_Setup( NS_SERVER, &newcl->netchan, from, qport, challenge ); // init the netchan queue newcl->netchan_end_queue = &newcl->netchan_start_queue; // save the userinfo Q_strncpyz( newcl->userinfo, userinfo, sizeof(newcl->userinfo) ); SV_UserinfoChanged( newcl, qtrue, qfalse ); // update userinfo, do not run filter // get the game a chance to reject this connection or modify the userinfo denied = VM_Call( gvm, 3, GAME_CLIENT_CONNECT, clientNum, qtrue, qfalse ); // firstTime = qtrue if ( denied ) { // we can't just use VM_ArgPtr, because that is only valid inside a VM_Call const char *str = GVM_ArgPtr( denied ); NET_OutOfBandPrint( NS_SERVER, from, "print\n%s\n", str ); Com_DPrintf( "Game rejected a connection: %s.\n", str ); return; } // send the connect packet to the client NET_OutOfBandPrint( NS_SERVER, from, "connectResponse %d", challenge ); SV_PrintClientStateChange( newcl, CS_CONNECTED ); newcl->state = CS_CONNECTED; newcl->lastSnapshotTime = svs.time - 9999; // generate a snapshot immediately newcl->lastPacketTime = svs.time; newcl->lastConnectTime = svs.time; newcl->lastDisconnectTime = svs.time; SVC_RateRestoreToxicAddress( &newcl->netchan.remoteAddress, 10, 1000 ); newcl->justConnected = qtrue; // when we receive the first packet from the client, we will // notice that it is from a different serverid and that the // gamestate message was not just sent, forcing a retransmit newcl->gamestateMessageNum = newcl->messageAcknowledge - 1; // force gamestate retransmit // if this was the first client on the server, or the last client // the server can hold, send a heartbeat to the master. count = 0; for ( i = 0, cl = svs.clients ; i < sv.maxclients; i++, cl++) { if ( svs.clients[i].state >= CS_CONNECTED ) { count++; } } if ( count == 1 || count == sv.maxclients ) { SV_Heartbeat_f(); } } /* ===================== SV_FreeClient Destructor for data allocated in a client structure ===================== */ void SV_FreeClient(client_t *client) { SV_Netchan_FreeQueue(client); SV_CloseDownload(client); } /* ===================== SV_DropClient Called when the player is totally leaving the server, either willingly or unwillingly. This is NOT called if the entire server is quitting or crashing -- SV_FinalMessage() will handle that ===================== */ void SV_DropClient( client_t *drop, const char *reason ) { char name[ sizeof( drop->name ) ]; qboolean isBot; int i; if ( drop->state == CS_ZOMBIE ) { return; // already dropped } isBot = drop->netchan.remoteAddress.type == NA_BOT; Q_strncpyz( name, drop->name, sizeof( name ) ); // for further DPrintf() because drop->name will be nuked in SV_SetUserinfo() // Free all allocated data on the client structure SV_FreeClient( drop ); // tell everyone why they got dropped if ( reason ) { SV_SendServerCommand( NULL, "print \"%s" S_COLOR_WHITE " %s\n\"", name, reason ); } // call the prog function for removing a client // this will remove the body, among other things VM_Call( gvm, 1, GAME_CLIENT_DISCONNECT, drop - svs.clients ); // add the disconnect command if ( reason ) { SV_SendServerCommand( drop, "disconnect \"%s\"", reason ); } if ( isBot ) { SV_BotFreeClient( drop - svs.clients ); } // nuke user info SV_SetUserinfo( drop - svs.clients, "" ); drop->justConnected = qfalse; drop->lastDisconnectTime = svs.time; if ( isBot ) { // bots shouldn't go zombie, as there's no real net connection. drop->state = CS_FREE; } else { Q_strncpyz( drop->name, name, sizeof( name ) ); SV_PrintClientStateChange( drop, CS_ZOMBIE ); drop->state = CS_ZOMBIE; // become free in a few seconds } if ( !reason ) { return; } // if this was the last client on the server, send a heartbeat // to the master so it is known the server is empty // send a heartbeat now so the master will get up to date info for ( i = 0; i < sv.maxclients; i++ ) { if ( svs.clients[i].state >= CS_CONNECTED ) { break; } } if ( i == sv.maxclients ) { SV_Heartbeat_f(); } } /* ================ SV_RemainingGameState estimates free space available for additional systeminfo keys ================ */ int SV_RemainingGameState( void ) { int len; int start, i; entityState_t nullstate; const svEntity_t *svEnt; msg_t msg; byte msgBuffer[ MAX_MSGLEN_BUF ]; MSG_Init( &msg, msgBuffer, MAX_MSGLEN ); MSG_WriteLong( &msg, 7 ); // last client command for ( i = 0; i < 256; i++ ) // simulate dummy client commands MSG_WriteByte( &msg, i & 127 ); // send the gamestate MSG_WriteByte( &msg, svc_gamestate ); MSG_WriteLong( &msg, 7 ); // client->reliableSequence // write the configstrings for ( start = 0 ; start < MAX_CONFIGSTRINGS ; start++ ) { if ( start == CS_SERVERINFO ) { MSG_WriteByte( &msg, svc_configstring ); MSG_WriteShort( &msg, start ); MSG_WriteBigString( &msg, Cvar_InfoString( CVAR_SERVERINFO, NULL ) ); continue; } if ( start == CS_SYSTEMINFO ) { MSG_WriteByte( &msg, svc_configstring ); MSG_WriteShort( &msg, start ); MSG_WriteBigString( &msg, Cvar_InfoString( CVAR_SYSTEMINFO, NULL ) ); continue; } if ( sv.configstrings[start][0] ) { MSG_WriteByte( &msg, svc_configstring ); MSG_WriteShort( &msg, start ); MSG_WriteBigString( &msg, sv.configstrings[start] ); } } // write the baselines Com_Memset( &nullstate, 0, sizeof( nullstate ) ); for ( start = 0 ; start < MAX_GENTITIES; start++ ) { if ( !sv.baselineUsed[ start ] ) { continue; } svEnt = &sv.svEntities[ start ]; MSG_WriteByte( &msg, svc_baseline ); MSG_WriteDeltaEntity( &msg, &nullstate, &svEnt->baseline, qtrue ); } MSG_WriteByte( &msg, svc_EOF ); MSG_WriteLong( &msg, 7 ); // client num // write the checksum feed MSG_WriteLong( &msg, sv.checksumFeed ); // finalize packet MSG_WriteByte( &msg, svc_EOF ); len = PAD( msg.bit, 8 ) / 8; // reserve some space for potential userinfo expansion len += 512; return MAX_MSGLEN - len; } /* ================ SV_SendClientGameState Sends the first message from the server to a connected client. This will be sent on the initial connection and upon each new map load. It will be resent if the client acknowledges a later message but has the wrong gamestate. ================ */ static void SV_SendClientGameState( client_t *client ) { int start; entityState_t nullstate; const svEntity_t *svEnt; msg_t msg; byte msgBuffer[ MAX_MSGLEN_BUF ]; qboolean csUpdated; Com_DPrintf( "SV_SendClientGameState() for %s\n", client->name ); SV_PrintClientStateChange( client, CS_PRIMED ); client->state = CS_PRIMED; client->downloading = qfalse; // to start generating delta for packet entities client->gentity = SV_GentityNum( client - svs.clients ); // when we receive the first packet from the client, we will // notice that it is from a different serverid and that the // gamestate message was not just sent, forcing a retransmit client->gamestateMessageNum = client->netchan.outgoingSequence; // accept usercmds starting from current server time only Com_Memset( &client->lastUsercmd, 0x0, sizeof( client->lastUsercmd ) ); client->lastUsercmd.serverTime = sv.time - 1; MSG_Init( &msg, msgBuffer, MAX_MSGLEN ); // NOTE, MRE: all server->client messages now acknowledge // let the client know which reliable clientCommands we have received MSG_WriteLong( &msg, client->lastClientCommand ); // send any server commands waiting to be sent first. // we have to do this cause we send the client->reliableSequence // with a gamestate and it sets the clc.serverCommandSequence at // the client side SV_UpdateServerCommandsToClient( client, &msg ); // send the gamestate MSG_WriteByte( &msg, svc_gamestate ); MSG_WriteLong( &msg, client->reliableSequence ); // write the configstrings csUpdated = qfalse; for ( start = 0 ; start < MAX_CONFIGSTRINGS ; start++ ) { if ( *sv.configstrings[ start ] != '\0' ) { MSG_WriteByte( &msg, svc_configstring ); MSG_WriteShort( &msg, start ); MSG_WriteBigString( &msg, sv.configstrings[start] ); } if ( client->csUpdated[start] ) { csUpdated = qtrue; } client->csUpdated[start] = qfalse; } if ( client->gamestateAck == GSA_INIT ) { // inital submission, accept any messageAcknowledge with matching serverId client->gamestateAck = GSA_SENT_ONCE; } else { if ( client->gamestateAck == GSA_SENT_ONCE && !csUpdated ) { // if no configstrings being updated since last submission then assume that we're (re)sending identical gamestate } else { // expect exact messageAcknowledge client->gamestateAck = GSA_SENT_MANY; } } // write the baselines Com_Memset( &nullstate, 0, sizeof( nullstate ) ); for ( start = 0 ; start < MAX_GENTITIES; start++ ) { if ( !sv.baselineUsed[ start ] ) { continue; } svEnt = &sv.svEntities[ start ]; MSG_WriteByte( &msg, svc_baseline ); MSG_WriteDeltaEntity( &msg, &nullstate, &svEnt->baseline, qtrue ); } MSG_WriteByte( &msg, svc_EOF ); MSG_WriteLong( &msg, client - svs.clients ); // write the checksum feed MSG_WriteLong( &msg, sv.checksumFeed ); // it is important to handle gamestate overflow // but at this stage client can't process any reliable commands // so at least try to inform him in console and release connection slot if ( msg.overflowed ) { if ( client->netchan.remoteAddress.type == NA_LOOPBACK ) { Com_Error( ERR_DROP, "gamestate overflow" ); } else { NET_OutOfBandPrint( NS_SERVER, &client->netchan.remoteAddress, "print\n" S_COLOR_RED "SERVER ERROR: gamestate overflow\n" ); SV_DropClient( client, "gamestate overflow" ); } return; } // deliver this to the client SV_SendMessageToClient( &msg, client ); } /* ================== SV_ClientEnterWorld ================== */ void SV_ClientEnterWorld( client_t *client ) { sharedEntity_t *ent; qboolean isBot; int clientNum; isBot = client->netchan.remoteAddress.type == NA_BOT; if ( !isBot ) { SV_PrintClientStateChange( client, CS_ACTIVE ); } else { // client->serverId = sv.serverId; } client->state = CS_ACTIVE; client->gamestateAck = GSA_ACKED; client->oldServerTime = 0; // resend all configstrings using the cs commands since these are // no longer sent when the client is CS_PRIMED if ( !isBot ) { SV_UpdateConfigstrings( client ); } // set up the entity for the client clientNum = client - svs.clients; ent = SV_GentityNum( clientNum ); ent->s.number = clientNum; client->gentity = ent; client->deltaMessage = client->netchan.outgoingSequence - (PACKET_BACKUP + 1); // force delta reset client->lastSnapshotTime = svs.time - 9999; // generate a snapshot immediately // call the game begin function VM_Call( gvm, 1, GAME_CLIENT_BEGIN, clientNum ); } /* ============================================================ CLIENT COMMAND EXECUTION ============================================================ */ /* ================== SV_CloseDownload clear/free any download vars ================== */ static void SV_CloseDownload( client_t *cl ) { int i; // EOF if ( cl->download != FS_INVALID_HANDLE ) { FS_FCloseFile( cl->download ); cl->download = FS_INVALID_HANDLE; } *cl->downloadName = '\0'; // Free the temporary buffer space for (i = 0; i < MAX_DOWNLOAD_WINDOW; i++) { if (cl->downloadBlocks[i]) { Z_Free( cl->downloadBlocks[i] ); cl->downloadBlocks[i] = NULL; } } } /* ================== SV_StopDownload_f Abort a download if in progress ================== */ static void SV_StopDownload_f( client_t *cl ) { if (*cl->downloadName) Com_DPrintf( "clientDownload: %d : file \"%s\" aborted\n", (int) (cl - svs.clients), cl->downloadName ); SV_CloseDownload( cl ); } /* ================== SV_DoneDownload_f Downloads are finished ================== */ static void SV_DoneDownload_f( client_t *cl ) { if ( cl->state == CS_ACTIVE ) return; Com_DPrintf( "clientDownload: %s Done\n", cl->name ); // resend the game state to update any clients that entered during the download SV_SendClientGameState( cl ); } /* ================== SV_NextDownload_f The argument will be the last acknowledged block from the client, it should be the same as cl->downloadClientBlock ================== */ static void SV_NextDownload_f( client_t *cl ) { int block = atoi( Cmd_Argv(1) ); if (block == cl->downloadClientBlock) { Com_DPrintf( "clientDownload: %d : client acknowledge of block %d\n", (int) (cl - svs.clients), block ); // Find out if we are done. A zero-length block indicates EOF if (cl->downloadBlockSize[cl->downloadClientBlock % MAX_DOWNLOAD_WINDOW] == 0) { Com_Printf( "clientDownload: %d : file \"%s\" completed\n", (int) (cl - svs.clients), cl->downloadName ); SV_CloseDownload( cl ); return; } cl->downloadSendTime = svs.time; cl->downloadClientBlock++; return; } // We aren't getting an acknowledge for the correct block, drop the client // FIXME: this is bad... the client will never parse the disconnect message // because the cgame isn't loaded yet SV_DropClient( cl, "broken download" ); } /* ================== SV_BeginDownload_f ================== */ static void SV_BeginDownload_f( client_t *cl ) { // Kill any existing download SV_CloseDownload( cl ); // cl->downloadName is non-zero now, SV_WriteDownloadToClient will see this and open // the file itself Q_strncpyz( cl->downloadName, Cmd_Argv(1), sizeof(cl->downloadName) ); SV_PrintClientStateChange( cl, CS_CONNECTED ); cl->state = CS_CONNECTED; cl->gentity = NULL; cl->downloading = qtrue; if ( cl->gamestateAck == GSA_ACKED ) { cl->gamestateAck = GSA_SENT_ONCE; } } /* ================== SV_WriteDownloadToClient Check to see if the client wants a file, open it if needed and start pumping the client Fill up msg with data, return number of download blocks added ================== */ static int SV_WriteDownloadToClient( client_t *cl ) { int curindex; int unreferenced = 1; char errorMessage[1024]; char pakbuf[MAX_QPATH], *pakptr; msg_t msg; byte msgBuffer[MAX_DOWNLOAD_BLKSIZE*2+8]; if ( cl->download == FS_INVALID_HANDLE ) { qboolean idPack = qfalse; qboolean missionPack = qfalse; // Chop off filename extension. Q_strncpyz( pakbuf, cl->downloadName, sizeof( pakbuf ) ); pakptr = strrchr( pakbuf, '.' ); if(pakptr) { *pakptr = '\0'; // Check for pk3 filename extension if ( !Q_stricmp( pakptr + 1, "pk3" ) ){ // Check whether the file appears in the list of referenced // paks to prevent downloading of arbitrary files. Cmd_TokenizeStringIgnoreQuotes( sv_referencedPakNames->string ); } } cl->download = FS_INVALID_HANDLE; // We open the file here if ( !(sv_allowDownload->integer & DLF_ENABLE) || (sv_allowDownload->integer & DLF_NO_UDP) || idPack || unreferenced || ( cl->downloadSize = FS_SV_FOpenFileRead( cl->downloadName, &cl->download ) ) < 0 ) { // cannot auto-download file if(unreferenced) { Com_Printf("clientDownload: %d : \"%s\" is not referenced and cannot be downloaded.\n", (int) (cl - svs.clients), cl->downloadName); Com_sprintf(errorMessage, sizeof(errorMessage), "File \"%s\" is not referenced and cannot be downloaded.", cl->downloadName); } else if (idPack) { Com_Printf("clientDownload: %d : \"%s\" cannot download id pk3 files\n", (int) (cl - svs.clients), cl->downloadName); if (missionPack) { Com_sprintf(errorMessage, sizeof(errorMessage), "Cannot autodownload Team Arena file \"%s\"\n" "The Team Arena mission pack can be found in your local game store.", cl->downloadName); } else { Com_sprintf(errorMessage, sizeof(errorMessage), "Cannot autodownload id pk3 file \"%s\"", cl->downloadName); } } else if ( !(sv_allowDownload->integer & DLF_ENABLE) || (sv_allowDownload->integer & DLF_NO_UDP) ) { Com_Printf("clientDownload: %d : \"%s\" download disabled\n", (int) (cl - svs.clients), cl->downloadName); Com_sprintf(errorMessage, sizeof(errorMessage), "Could not download \"%s\" because autodownloading is disabled on the server.\n\n" "Set autodownload to No in your settings and you might be " "able to join the game anyway.\n", cl->downloadName); } else { // NOTE TTimo this is NOT supposed to happen unless bug in our filesystem scheme? // if the pk3 is referenced, it must have been found somewhere in the filesystem Com_Printf("clientDownload: %d : \"%s\" file not found on server\n", (int) (cl - svs.clients), cl->downloadName); Com_sprintf(errorMessage, sizeof(errorMessage), "File \"%s\" not found on server for autodownloading.\n", cl->downloadName); } MSG_Init( &msg, msgBuffer, sizeof( msgBuffer ) - 8 ); MSG_WriteLong( &msg, cl->lastClientCommand ); MSG_WriteByte( &msg, svc_download ); MSG_WriteShort( &msg, 0 ); // client is expecting block zero MSG_WriteLong( &msg, -1 ); // illegal file size MSG_WriteString( &msg, errorMessage ); MSG_WriteByte( &msg, svc_EOF ); SV_Netchan_Transmit( cl, &msg ); *cl->downloadName = '\0'; if ( cl->download != FS_INVALID_HANDLE ) { FS_FCloseFile( cl->download ); cl->download = FS_INVALID_HANDLE; } return 1; } Com_Printf( "clientDownload: %d : beginning \"%s\"\n", (int) (cl - svs.clients), cl->downloadName ); cl->downloadCurrentBlock = cl->downloadClientBlock = cl->downloadXmitBlock = 0; cl->downloadCount = 0; cl->downloadEOF = qfalse; } // Perform any reads that we need to while (cl->downloadCurrentBlock - cl->downloadClientBlock < MAX_DOWNLOAD_WINDOW && cl->downloadSize != cl->downloadCount) { curindex = (cl->downloadCurrentBlock % MAX_DOWNLOAD_WINDOW); if (!cl->downloadBlocks[curindex]) cl->downloadBlocks[curindex] = Z_Malloc( MAX_DOWNLOAD_BLKSIZE ); cl->downloadBlockSize[curindex] = FS_Read( cl->downloadBlocks[curindex], MAX_DOWNLOAD_BLKSIZE, cl->download ); if (cl->downloadBlockSize[curindex] < 0) { // EOF right now cl->downloadCount = cl->downloadSize; break; } cl->downloadCount += cl->downloadBlockSize[curindex]; // Load in next block cl->downloadCurrentBlock++; } // Check to see if we have eof condition and add the EOF block if (cl->downloadCount == cl->downloadSize && !cl->downloadEOF && cl->downloadCurrentBlock - cl->downloadClientBlock < MAX_DOWNLOAD_WINDOW) { cl->downloadBlockSize[cl->downloadCurrentBlock % MAX_DOWNLOAD_WINDOW] = 0; cl->downloadCurrentBlock++; cl->downloadEOF = qtrue; // We have added the EOF block } if (cl->downloadClientBlock == cl->downloadCurrentBlock) return 0; // Nothing to transmit // Write out the next section of the file, if we have already reached our window, // automatically start retransmitting if (cl->downloadXmitBlock == cl->downloadCurrentBlock) { // We have transmitted the complete window, should we start resending? if (svs.time - cl->downloadSendTime > 1000) cl->downloadXmitBlock = cl->downloadClientBlock; else return 0; } // Send current block curindex = (cl->downloadXmitBlock % MAX_DOWNLOAD_WINDOW); MSG_Init( &msg, msgBuffer, sizeof( msgBuffer ) - 8 ); MSG_WriteLong( &msg, cl->lastClientCommand ); MSG_WriteByte( &msg, svc_download ); MSG_WriteShort( &msg, cl->downloadXmitBlock ); // block zero is special, contains file size if ( cl->downloadXmitBlock == 0 ) MSG_WriteLong( &msg, cl->downloadSize ); MSG_WriteShort( &msg, cl->downloadBlockSize[curindex] ); // Write the block if ( cl->downloadBlockSize[curindex] > 0 ) MSG_WriteData( &msg, cl->downloadBlocks[curindex], cl->downloadBlockSize[curindex] ); MSG_WriteByte( &msg, svc_EOF ); SV_Netchan_Transmit( cl, &msg ); Com_DPrintf( "clientDownload: %d : writing block %d\n", (int) (cl - svs.clients), cl->downloadXmitBlock ); // Move on to the next block // It will get sent with next snap shot. The rate will keep us in line. cl->downloadXmitBlock++; cl->downloadSendTime = svs.time; return 1; } /* ================== SV_SendQueuedMessages Send one round of fragments, or queued messages to all clients that have data pending. Return the shortest time interval for sending next packet to client ================== */ int SV_SendQueuedMessages( void ) { int i, retval = -1, nextFragT; client_t *cl; for( i = 0; i < sv.maxclients; i++ ) { cl = &svs.clients[i]; if ( cl->state ) { nextFragT = SV_RateMsec(cl); if(!nextFragT) nextFragT = SV_Netchan_TransmitNextFragment(cl); if(nextFragT >= 0 && (retval == -1 || retval > nextFragT)) retval = nextFragT; } } return retval; } /* ================== SV_SendDownloadMessages Send one round of download messages to all clients ================== */ int SV_SendDownloadMessages( void ) { int i, numDLs = 0; client_t *cl; for( i = 0; i < sv.maxclients; i++ ) { cl = &svs.clients[ i ]; if ( cl->state >= CS_CONNECTED && *cl->downloadName ) { numDLs += SV_WriteDownloadToClient( cl ); } } return numDLs; } /* ================= SV_Disconnect_f The client is going to disconnect, so remove the connection immediately FIXME: move to game? ================= */ static void SV_Disconnect_f( client_t *cl ) { SV_DropClient( cl, "disconnected" ); } /* ================= SV_UserinfoChanged Pull specific info from a newly changed userinfo string into a more C friendly form. ================= */ void SV_UserinfoChanged( client_t *cl, qboolean updateUserinfo, qboolean runFilter ) { char buf[ MAX_NAME_LENGTH ]; const char *val; const char *ip; int i; if ( cl->netchan.remoteAddress.type == NA_BOT ) { cl->lastSnapshotTime = svs.time - 9999; // generate a snapshot immediately cl->snapshotMsec = 1000 / sv_fps->integer; cl->rate = 0; return; } // rate command // if the client is on the same subnet as the server and we aren't running an // internet public server, assume they don't need a rate choke if ( cl->netchan.remoteAddress.type == NA_LOOPBACK || cl->netchan.isLANAddress ) { cl->rate = 0; // lans should not rate limit } else { val = Info_ValueForKey( cl->userinfo, "rate" ); if ( val[0] ) cl->rate = atoi( val ); else cl->rate = 10000; // was 3000 if ( sv_maxRate->integer ) { if ( cl->rate > sv_maxRate->integer ) cl->rate = sv_maxRate->integer; } if ( sv_minRate->integer ) { if ( cl->rate < sv_minRate->integer ) cl->rate = sv_minRate->integer; } } // snaps command val = Info_ValueForKey( cl->userinfo, "snaps" ); if ( val[0] && !NET_IsLocalAddress( &cl->netchan.remoteAddress ) ) i = atoi( val ); else i = sv_fps->integer; // sync with server // range check if ( i < 1 ) i = 1; else if ( i > sv_fps->integer ) i = sv_fps->integer; i = 1000 / i; // from FPS to milliseconds if ( i != cl->snapshotMsec ) { // Reset last sent snapshot so we avoid desync between server frame time and snapshot send time cl->lastSnapshotTime = svs.time - 9999; // generate a snapshot immediately cl->snapshotMsec = i; } val = Info_ValueForKey( cl->userinfo, "viewdistance" ); i = atoi( val ); // range check if ( i < 1 ) i = 1; else if ( i > 180 ) i = 180; cl->viewDistance = i; if ( !updateUserinfo ) return; // name for C code val = Info_ValueForKey( cl->userinfo, "name" ); // truncate if it is too long as it may cause memory corruption in OSP mod if ( gvm->forceDataMask && strlen( val ) >= sizeof( buf ) ) { Q_strncpyz( buf, val, sizeof( buf ) ); Info_SetValueForKey( cl->userinfo, "name", buf ); val = buf; } Q_strncpyz( cl->name, val, sizeof( cl->name ) ); val = Info_ValueForKey( cl->userinfo, "handicap" ); if ( val[0] ) { i = atoi( val ); if ( i <= 0 || i > 100 || strlen( val ) > 4 ) { Info_SetValueForKey( cl->userinfo, "handicap", "100" ); } } // TTimo // maintain the IP information // the banning code relies on this being consistently present if ( NET_IsLocalAddress( &cl->netchan.remoteAddress ) ) ip = "localhost"; else ip = NET_AdrToString( &cl->netchan.remoteAddress ); if ( !Info_SetValueForKey( cl->userinfo, "ip", ip ) ) SV_DropClient( cl, "userinfo string length exceeded" ); if ( runFilter ) { val = SV_RunFilters( cl->userinfo, &cl->netchan.remoteAddress ); if ( *val != '\0' ) { SV_DropClient( cl, val ); } } } /* ================== SV_UpdateUserinfo_f ================== */ static void SV_UpdateUserinfo_f( client_t *cl ) { const char *info; info = Cmd_Argv( 1 ); if ( Cmd_Argc() != 2 || *info == '\0' ) { // this is something erroneous, client should never send that return; } Q_strncpyz( cl->userinfo, info, sizeof( cl->userinfo ) ); SV_UserinfoChanged( cl, qtrue, qtrue ); // update userinfo, run filter // call prog code to allow overrides VM_Call( gvm, 1, GAME_CLIENT_USERINFO_CHANGED, cl - svs.clients ); } extern int SV_Strlen( const char *str ); /* ================= SV_NetError_f Called when the client detects network issues and requests to reset or recover the network state dynamically during gameplay. This triggers mechanisms to restore smooth gameplay by adjusting network-dependent parameters such as view distance or update rates. ================= */ static void SV_NetError_f( client_t *client ) { client->netError = qtrue; client->dynamicViewDistance = 1; } typedef struct { const char *name; void (*func)( client_t *cl ); } ucmd_t; static const ucmd_t ucmds[] = { {"userinfo", SV_UpdateUserinfo_f}, {"disconnect", SV_Disconnect_f}, {"download", SV_BeginDownload_f}, {"nextdl", SV_NextDownload_f}, {"stopdl", SV_StopDownload_f}, {"donedl", SV_DoneDownload_f}, {"neterror", SV_NetError_f}, {NULL, NULL} }; /* ================ SV_FloodProtect ================ */ static qboolean SV_FloodProtect( client_t *cl ) { if ( sv_floodProtect->integer ) { return SVC_RateLimit( &cl->cmd_rate, 8, 500 ); } else { return qfalse; } } /* ================== SV_ExecuteClientCommand Also called by bot code ================== */ qboolean SV_ExecuteClientCommand( client_t *cl, const char *s ) { const ucmd_t *ucmd; qboolean bFloodProtect; qboolean isBot; Cmd_TokenizeString( s ); // malicious users may try using too many string commands // to lag other players. If we decide that we want to stall // the command, we will stop processing the rest of the packet, // including the usercmd. This causes flooders to lag themselves // but not other people // We don't do this when the client hasn't been active yet since it's // normal to spam a lot of commands when downloading isBot = cl->netchan.remoteAddress.type == NA_BOT ? qtrue: qfalse; bFloodProtect = !isBot && cl->state >= CS_ACTIVE; // see if it is a server level command for ( ucmd = ucmds; ucmd->name; ucmd++ ) { if ( !strcmp( Cmd_Argv(0), ucmd->name ) ) { if ( ucmd->func == SV_UpdateUserinfo_f ) { if ( bFloodProtect ) { if ( SVC_RateLimit( &cl->info_rate, 5, 1000 ) ) { return qfalse; // lag flooder } } } ucmd->func( cl ); bFloodProtect = qfalse; break; } } // if ( !isBot && ( !cl->gamestateAcked || sv.serverId != cl->serverId ) ) { // Com_Printf( "%s: ignoring pre map_restart / outdated client command '%s'\n", cl->name, s ); // return qtrue; // } #ifndef DEDICATED if ( !com_cl_running->integer && bFloodProtect && SV_FloodProtect( cl ) ) { #else if ( bFloodProtect && SV_FloodProtect( cl ) ) { #endif // ignore any other text messages from this client but let them keep playing Com_DPrintf( "client text ignored for %s: %s\n", cl->name, Cmd_Argv(0) ); } else { // pass unknown strings to the game if ( !ucmd->name && sv.state == SS_GAME && cl->state >= CS_PRIMED ) { if ( gvm->forceDataMask ) Cmd_Args_Sanitize( "\n\r;" ); // handle ';' for OSP else Cmd_Args_Sanitize( "\n\r" ); VM_Call( gvm, 1, GAME_CLIENT_COMMAND, cl - svs.clients ); } } return qtrue; } /* =============== SV_ClientCommand =============== */ static qboolean SV_ClientCommand( client_t *cl, msg_t *msg ) { int seq; const char *s; seq = MSG_ReadLong( msg ); s = MSG_ReadString( msg ); // see if we have already executed it if ( seq - cl->lastClientCommand <= 0 ) { return qtrue; } Com_DPrintf( "clientCommand: %s : %i : %s\n", cl->name, seq, s ); // drop the connection if we have somehow lost commands if ( seq - cl->lastClientCommand > 1 ) { Com_Printf( "Client %s lost %i clientCommands\n", cl->name, seq - cl->lastClientCommand - 1 ); SV_DropClient( cl, "Lost reliable commands" ); return qfalse; } if ( !SV_ExecuteClientCommand( cl, s ) ) { return qfalse; } cl->lastClientCommand = seq; Q_strncpyz( cl->lastClientCommandString, s, sizeof( cl->lastClientCommandString ) ); return qtrue; // continue procesing } //================================================================================== /* ================== SV_ClientThink Also called by bot code ================== */ void SV_ClientThink (client_t *cl, usercmd_t *cmd) { cl->lastUsercmd = *cmd; if ( cl->state != CS_ACTIVE ) { return; // may have been kicked during the last usercmd } VM_Call( gvm, 1, GAME_CLIENT_THINK, cl - svs.clients ); } /* ================== SV_UserMove The message usually contains all the movement commands that were in the last three packets, so that the information in dropped packets can be recovered. On very fast clients, there may be multiple usercmd packed into each of the backup packets. ================== */ static void SV_UserMove( client_t *cl, msg_t *msg, qboolean delta ) { int i, key; int cmdCount; static const usercmd_t nullcmd = { 0 }; usercmd_t cmds[MAX_PACKET_USERCMDS], *cmd; const usercmd_t *oldcmd; if ( delta ) { cl->deltaMessage = cl->messageAcknowledge; } else { cl->deltaMessage = cl->netchan.outgoingSequence - ( PACKET_BACKUP + 1 ); // force delta reset } cmdCount = MSG_ReadByte( msg ); if ( cmdCount < 1 ) { Com_Printf( "cmdCount < 1\n" ); return; } if ( cmdCount > MAX_PACKET_USERCMDS ) { Com_Printf( "cmdCount > MAX_PACKET_USERCMDS\n" ); return; } // use the checksum feed in the key key = sv.checksumFeed; // also use the message acknowledge key ^= cl->messageAcknowledge; // also use the last acknowledged server command in the key key ^= MSG_HashKey(cl->reliableCommands[ cl->reliableAcknowledge & (MAX_RELIABLE_COMMANDS-1) ], 32); oldcmd = &nullcmd; for ( i = 0 ; i < cmdCount ; i++ ) { cmd = &cmds[i]; MSG_ReadDeltaUsercmdKey( msg, key, oldcmd, cmd ); oldcmd = cmd; } // save time for ping calculation if ( cl->frames[ cl->messageAcknowledge & PACKET_MASK ].messageAcked == 0 ) { cl->frames[ cl->messageAcknowledge & PACKET_MASK ].messageAcked = Sys_Milliseconds(); } // if this is the first usercmd we have received // this gamestate, put the client into the world if ( cl->state == CS_PRIMED ) { SV_ClientEnterWorld( cl ); // the moves can be processed normally } if ( cl->state != CS_ACTIVE ) { cl->deltaMessage = cl->netchan.outgoingSequence - ( PACKET_BACKUP + 1 ); // force delta reset return; } // usually, the first couple commands will be duplicates // of ones we have previously received, but the servertimes // in the commands will cause them to be immediately discarded for ( i = 0; i < cmdCount; i++ ) { // if this is a cmd from before a map_restart ignore it if ( cmds[i].serverTime - cmds[cmdCount-1].serverTime > 0 ) { continue; } // extremely lagged or cmd from before a map_restart //if ( cmds[i].serverTime > svs.time + 3000 ) { // continue; //} // don't execute if this is an old cmd which is already executed // these old cmds are included when cl_packetdup > 0 //if ( cmds[i].serverTime <= cl->lastUsercmd.serverTime ) { if ( cmds[i].serverTime - cl->lastUsercmd.serverTime <= 0 ) { continue; } SV_ClientThink( cl, &cmds[ i ] ); } } /* =========================================================================== USER CMD EXECUTION =========================================================================== */ /* =================== SV_ExecuteClientMessage Parse a client packet =================== */ void SV_ExecuteClientMessage( client_t *cl, msg_t *msg ) { int c; int serverId; int reliableAcknowledge; MSG_Bitstream( msg ); serverId = MSG_ReadLong( msg ); cl->messageAcknowledge = MSG_ReadLong( msg ); //if ( cl->messageAcknowledge < 0 ) { if ( cl->netchan.outgoingSequence - cl->messageAcknowledge <= 0 ) { // usually only hackers create messages like this // it is more annoying for them to let them hanging #ifdef _DEBUG SV_DropClient( cl, "DEBUG: illegible client message" ); #endif return; } reliableAcknowledge = MSG_ReadLong( msg ); if ( cl->reliableSequence - reliableAcknowledge < 0 ) { #ifdef _DEBUG SV_DropClient( cl, "DEBUG: illegible client message" ); #endif return; } // NOTE: when the client message is fux0red the acknowledgement numbers // can be out of range, this could cause the server to send thousands of server // commands which the server thinks are not yet acknowledged in SV_UpdateServerCommandsToClient if ( cl->reliableSequence - reliableAcknowledge > MAX_RELIABLE_COMMANDS ) { // usually only hackers create messages like this // it is more annoying for them to let them hanging #ifdef _DEBUG SV_DropClient( cl, "DEBUG: illegible client message" ); #else Com_Printf( S_COLOR_YELLOW "WARNING: dropping %i commands from %s\n", cl->reliableSequence - cl->reliableAcknowledge, cl->name ); #endif cl->reliableAcknowledge = cl->reliableSequence; return; } cl->reliableAcknowledge = reliableAcknowledge; cl->justConnected = qfalse; // cl->serverId = serverId; // if this is a usercmd from a previous gamestate, // ignore it or retransmit the current gamestate // // if the client was downloading, let it stay at whatever serverId and // gamestate it was at. This allows it to keep downloading even when // the gamestate changes. After the download is finished, we'll // notice and send it a new game state // if ( cl->state == CS_CONNECTED ) { if ( !cl->downloading ) { // send initial gamestate, client may not acknowledge it in next command but start downloading after SV_ClientCommand() if ( !SVC_RateLimit( &cl->gamestate_rate, 2, 1000 ) ) { SV_SendClientGameState( cl ); } return; } } else if ( cl->gamestateAck != GSA_ACKED ) { // early check for gamestate acknowledge if ( serverId == sv.serverId ) { const int delta = cl->messageAcknowledge - cl->gamestateMessageNum; if ( delta == 0 || ( delta > 0 && cl->gamestateAck == GSA_SENT_ONCE ) ) { cl->gamestateAck = GSA_ACKED; // this client has acknowledged the new gamestate so it's // safe to start sending it the real time again Com_DPrintf( "%s acknowledged gamestate with delta %i\n", cl->name, delta ); cl->oldServerTime = 0; } } } // else if ( cl->state == CS_PRIMED ) { // in case of download intention client replies with (messageAcknowledge - gamestateMessageNum) >= 0 and (serverId == sv.serverId), sv.serverId can drift away later // in case of lost gamestate client replies with (messageAcknowledge - gamestateMessageNum) > 0 and (serverId == sv.serverId) // in case of disconnect/etc. client replies with any serverId //} // read optional clientCommand strings do { c = MSG_ReadByte( msg ); if ( c != clc_clientCommand ) { break; } if ( !SV_ClientCommand( cl, msg ) ) { return; // we couldn't execute it because of the flood protection } if ( cl->state == CS_ZOMBIE ) { return; // disconnect command } } while ( 1 ); if ( cl->gamestateAck != GSA_ACKED ) { // late check for gamestate resend if ( cl->state == CS_PRIMED && cl->messageAcknowledge - cl->gamestateMessageNum > 0 ) { Com_DPrintf( "%s: dropped gamestate, resending\n", cl->name ); if ( !SVC_RateLimit( &cl->gamestate_rate, 2, 1000 ) ) { SV_SendClientGameState( cl ); } } return; } // read the usercmd_t if ( c == clc_move ) { SV_UserMove( cl, msg, qtrue ); } else if ( c == clc_moveNoDelta ) { SV_UserMove( cl, msg, qfalse ); } else if ( c != clc_EOF ) { Com_Printf( "WARNING: bad command byte %i for client %i\n", c, (int) (cl - svs.clients) ); } // if ( msg->readcount != msg->cursize ) { // Com_Printf( "WARNING: Junk at end of packet for client %i\n", cl - svs.clients ); // } }