More correctly handle non-standard protocol values
Made global DEMOEXT definition really working
This commit is contained in:
parent
d6014532c0
commit
011688aa93
|
@ -253,10 +253,15 @@ void CL_StopRecord_f( void ) {
|
|||
clc.recordfile = FS_INVALID_HANDLE;
|
||||
|
||||
// select proper extension
|
||||
if ( clc.dm68compat || clc.demoplaying )
|
||||
protocol = PROTOCOL_VERSION;
|
||||
else
|
||||
if ( clc.dm68compat || clc.demoplaying ) {
|
||||
protocol = OLD_PROTOCOL_VERSION;
|
||||
} else {
|
||||
protocol = NEW_PROTOCOL_VERSION;
|
||||
}
|
||||
|
||||
if ( com_protocol->integer != DEFAULT_PROTOCOL_VERSION ) {
|
||||
protocol = com_protocol->integer;
|
||||
}
|
||||
|
||||
Com_sprintf( tempName, sizeof( tempName ), "%s.tmp", clc.recordName );
|
||||
|
||||
|
@ -579,7 +584,7 @@ static void CL_Record_f( void ) {
|
|||
ext = COM_GetExtension( demoName );
|
||||
if ( *ext ) {
|
||||
// strip demo extension
|
||||
sprintf( demoExt, "%s%d", DEMOEXT, PROTOCOL_VERSION );
|
||||
sprintf( demoExt, "%s%d", DEMOEXT, OLD_PROTOCOL_VERSION );
|
||||
if ( Q_stricmp( ext, demoExt ) == 0 ) {
|
||||
*(strrchr( demoName, '.' )) = '\0';
|
||||
} else {
|
||||
|
@ -648,11 +653,11 @@ CL_CompleteRecordName
|
|||
*/
|
||||
static void CL_CompleteRecordName( char *args, int argNum )
|
||||
{
|
||||
if( argNum == 2 )
|
||||
if ( argNum == 2 )
|
||||
{
|
||||
char demoExt[ 16 ];
|
||||
|
||||
Com_sprintf( demoExt, sizeof( demoExt ), ".dm_%d", PROTOCOL_VERSION );
|
||||
Com_sprintf( demoExt, sizeof( demoExt ), ".%s%d", DEMOEXT, com_protocol->integer );
|
||||
Field_CompleteFilename( "demos", demoExt, qtrue, FS_MATCH_EXTERN | FS_MATCH_STICK );
|
||||
}
|
||||
}
|
||||
|
@ -759,7 +764,7 @@ void CL_ReadDemoMessage( void ) {
|
|||
CL_WalkDemoExt
|
||||
====================
|
||||
*/
|
||||
static int CL_WalkDemoExt( const char *arg, char *name, fileHandle_t *handle )
|
||||
static int CL_WalkDemoExt( const char *arg, char *name, int name_len, fileHandle_t *handle )
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -768,7 +773,7 @@ static int CL_WalkDemoExt( const char *arg, char *name, fileHandle_t *handle )
|
|||
|
||||
while ( demo_protocols[ i ] )
|
||||
{
|
||||
Com_sprintf( name, MAX_OSPATH, "demos/%s.dm_%d", arg, demo_protocols[ i ] );
|
||||
Com_sprintf( name, name_len, "demos/%s.%s%d", arg, DEMOEXT, demo_protocols[ i ] );
|
||||
FS_BypassPure();
|
||||
FS_FOpenFileRead( name, handle, qtrue );
|
||||
FS_RestorePure();
|
||||
|
@ -792,12 +797,17 @@ CL_DemoExtCallback
|
|||
*/
|
||||
static qboolean CL_DemoNameCallback_f( const char *filename, int length )
|
||||
{
|
||||
const int ext_len = strlen( "." DEMOEXT );
|
||||
const int num_len = 2;
|
||||
int version;
|
||||
|
||||
if ( length < 7 || Q_stricmpn( filename + length - 6, ".dm_", 4 ) )
|
||||
if ( length <= ext_len + num_len || Q_stricmpn( filename + length - (ext_len + num_len), "." DEMOEXT, ext_len ) != 0 )
|
||||
return qfalse;
|
||||
|
||||
version = atoi( filename + length - 2 );
|
||||
version = atoi( filename + length - num_len );
|
||||
if ( version == com_protocol->integer )
|
||||
return qtrue;
|
||||
|
||||
if ( version < 66 || version > NEW_PROTOCOL_VERSION )
|
||||
return qfalse;
|
||||
|
||||
|
@ -812,10 +822,10 @@ CL_CompleteDemoName
|
|||
*/
|
||||
static void CL_CompleteDemoName( char *args, int argNum )
|
||||
{
|
||||
if( argNum == 2 )
|
||||
if ( argNum == 2 )
|
||||
{
|
||||
FS_SetFilenameCallback( CL_DemoNameCallback_f );
|
||||
Field_CompleteFilename( "demos", ".dm_??", qfalse, FS_MATCH_ANY | FS_MATCH_STICK );
|
||||
Field_CompleteFilename( "demos", "." DEMOEXT "??", qfalse, FS_MATCH_ANY | FS_MATCH_STICK );
|
||||
FS_SetFilenameCallback( NULL );
|
||||
}
|
||||
}
|
||||
|
@ -871,16 +881,17 @@ static void CL_PlayDemo_f( void ) {
|
|||
Com_Printf("Protocol %d not supported for demos\n", protocol );
|
||||
len = ext_test - arg;
|
||||
|
||||
if(len >= ARRAY_LEN(retry))
|
||||
len = ARRAY_LEN(retry) - 1;
|
||||
if ( len > ARRAY_LEN( retry ) - 1 ) {
|
||||
len = ARRAY_LEN( retry ) - 1;
|
||||
}
|
||||
|
||||
Q_strncpyz( retry, arg, len + 1);
|
||||
retry[len] = '\0';
|
||||
protocol = CL_WalkDemoExt( retry, name, &hFile );
|
||||
protocol = CL_WalkDemoExt( retry, name, sizeof( name ), &hFile );
|
||||
}
|
||||
}
|
||||
else
|
||||
protocol = CL_WalkDemoExt( arg, name, &hFile );
|
||||
protocol = CL_WalkDemoExt( arg, name, sizeof( name ), &hFile );
|
||||
|
||||
if ( hFile == FS_INVALID_HANDLE ) {
|
||||
Com_Printf( S_COLOR_YELLOW "couldn't open %s\n", name );
|
||||
|
@ -2303,12 +2314,12 @@ static void CL_CheckForResend( void ) {
|
|||
notOverflowed = qtrue;
|
||||
}
|
||||
|
||||
if ( com_protocol->integer != PROTOCOL_VERSION ) {
|
||||
if ( com_protocol->integer != DEFAULT_PROTOCOL_VERSION ) {
|
||||
notOverflowed &= Info_SetValueForKey_s( info, MAX_USERINFO_LENGTH, "protocol",
|
||||
com_protocol->string );
|
||||
} else {
|
||||
notOverflowed &= Info_SetValueForKey_s( info, MAX_USERINFO_LENGTH, "protocol",
|
||||
clc.compat ? XSTRING( PROTOCOL_VERSION ) : XSTRING( NEW_PROTOCOL_VERSION ) );
|
||||
clc.compat ? XSTRING( OLD_PROTOCOL_VERSION ) : XSTRING( NEW_PROTOCOL_VERSION ) );
|
||||
}
|
||||
|
||||
notOverflowed &= Info_SetValueForKey_s( info, MAX_USERINFO_LENGTH, "qport",
|
||||
|
@ -2619,44 +2630,45 @@ static qboolean CL_ConnectionlessPacket( const netadr_t *from, msg_t *msg ) {
|
|||
}
|
||||
|
||||
// challenge from the server we are connecting to
|
||||
if (!Q_stricmp(c, "challengeResponse"))
|
||||
{
|
||||
char *strver;
|
||||
int ver;
|
||||
if ( !Q_stricmp(c, "challengeResponse" ) ) {
|
||||
|
||||
if ( cls.state != CA_CONNECTING )
|
||||
{
|
||||
if ( cls.state != CA_CONNECTING ) {
|
||||
Com_DPrintf( "Unwanted challenge response received. Ignored.\n" );
|
||||
return qfalse;
|
||||
}
|
||||
|
||||
c = Cmd_Argv( 2 );
|
||||
if ( *c )
|
||||
if ( *c != '\0' )
|
||||
challenge = atoi( c );
|
||||
|
||||
clc.compat = qtrue;
|
||||
strver = Cmd_Argv( 3 ); // analyze server protocol version
|
||||
if ( *strver ) {
|
||||
ver = atoi( strver );
|
||||
if ( ver != PROTOCOL_VERSION ) {
|
||||
if ( ver == NEW_PROTOCOL_VERSION ) {
|
||||
clc.compat = qtrue;
|
||||
s = Cmd_Argv( 3 ); // analyze server protocol version
|
||||
if ( *s != '\0' ) {
|
||||
int sv_proto = atoi( s );
|
||||
if ( sv_proto > OLD_PROTOCOL_VERSION ) {
|
||||
if ( sv_proto == NEW_PROTOCOL_VERSION || sv_proto == com_protocol->integer ) {
|
||||
clc.compat = qfalse;
|
||||
} else {
|
||||
int cl_proto = com_protocol->integer;
|
||||
if ( cl_proto == DEFAULT_PROTOCOL_VERSION ) {
|
||||
// we support new protocol features by default
|
||||
cl_proto = NEW_PROTOCOL_VERSION;
|
||||
}
|
||||
Com_Printf( S_COLOR_YELLOW "Warning: Server reports protocol version %d, "
|
||||
"we have %d. Trying legacy protocol %d.\n",
|
||||
ver, NEW_PROTOCOL_VERSION, PROTOCOL_VERSION );
|
||||
"we have %d. Trying legacy protocol %d.\n",
|
||||
sv_proto, cl_proto, OLD_PROTOCOL_VERSION );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( clc.compat )
|
||||
{
|
||||
if( !NET_CompareAdr( from, &clc.serverAddress ) )
|
||||
if ( !NET_CompareAdr( from, &clc.serverAddress ) )
|
||||
{
|
||||
// This challenge response is not coming from the expected address.
|
||||
// Check whether we have a matching client challenge to prevent
|
||||
// connection hi-jacking.
|
||||
if( !*c || challenge != clc.challenge )
|
||||
if ( *c == '\0' || challenge != clc.challenge )
|
||||
{
|
||||
Com_DPrintf( "Challenge response received from unexpected source. Ignored.\n" );
|
||||
return qfalse;
|
||||
|
@ -2665,7 +2677,7 @@ static qboolean CL_ConnectionlessPacket( const netadr_t *from, msg_t *msg ) {
|
|||
}
|
||||
else
|
||||
{
|
||||
if( !*c || challenge != clc.challenge )
|
||||
if ( *c == '\0' || challenge != clc.challenge )
|
||||
{
|
||||
Com_Printf( "Bad challenge for challengeResponse. Ignored.\n" );
|
||||
return qfalse;
|
||||
|
@ -2725,7 +2737,7 @@ static qboolean CL_ConnectionlessPacket( const netadr_t *from, msg_t *msg ) {
|
|||
if ( *c != '\0' ) {
|
||||
int protocol = atoi( c );
|
||||
if ( protocol > 0 ) {
|
||||
if ( protocol == PROTOCOL_VERSION ) {
|
||||
if ( protocol <= OLD_PROTOCOL_VERSION ) {
|
||||
clc.compat = qtrue;
|
||||
} else {
|
||||
clc.compat = qfalse;
|
||||
|
@ -4102,7 +4114,7 @@ static void CL_ServerInfoPacket( const netadr_t *from, msg_t *msg ) {
|
|||
|
||||
// if this isn't the correct protocol version, ignore it
|
||||
prot = atoi( Info_ValueForKey( infoString, "protocol" ) );
|
||||
if ( prot != PROTOCOL_VERSION && prot != NEW_PROTOCOL_VERSION ) {
|
||||
if ( prot != OLD_PROTOCOL_VERSION && prot != NEW_PROTOCOL_VERSION && prot != com_protocol->integer ) {
|
||||
Com_DPrintf( "Different protocol info packet: %s\n", infoString );
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
#include "../client/keys.h"
|
||||
|
||||
const int demo_protocols[] = { 66, 67, PROTOCOL_VERSION, NEW_PROTOCOL_VERSION, 0 };
|
||||
const int demo_protocols[] = { 66, 67, OLD_PROTOCOL_VERSION, NEW_PROTOCOL_VERSION, 0 };
|
||||
|
||||
#define USE_MULTI_SEGMENT // allocate additional zone segments on demand
|
||||
|
||||
|
@ -3611,7 +3611,7 @@ void Com_Init( char *commandLine ) {
|
|||
Cvar_Get( "sv_master2", "master.ioquake3.org", CVAR_INIT );
|
||||
Cvar_Get( "sv_master3", "master.maverickservers.com", CVAR_INIT );
|
||||
|
||||
com_protocol = Cvar_Get( "protocol", XSTRING( PROTOCOL_VERSION ), 0 );
|
||||
com_protocol = Cvar_Get( "protocol", XSTRING( DEFAULT_PROTOCOL_VERSION ), 0 );
|
||||
if ( Q_stristr( com_protocol->string, "-compat" ) > com_protocol->string ) {
|
||||
// strip -compat suffix
|
||||
Cvar_Set2( "protocol", va( "%i", com_protocol->integer ), qtrue );
|
||||
|
|
|
@ -281,11 +281,13 @@ PROTOCOL
|
|||
==============================================================
|
||||
*/
|
||||
|
||||
#define PROTOCOL_VERSION 68
|
||||
#define OLD_PROTOCOL_VERSION 68
|
||||
// new protocol with UDP spoofing protection:
|
||||
#define NEW_PROTOCOL_VERSION 71
|
||||
// 1.31 - 67
|
||||
|
||||
#define DEFAULT_PROTOCOL_VERSION OLD_PROTOCOL_VERSION
|
||||
|
||||
|
||||
// maintain a list of compatible protocols for demo playing
|
||||
// NOTE: that stuff only works with two digits protocols
|
||||
|
|
|
@ -431,14 +431,13 @@ void SV_DirectConnect( const netadr_t *from ) {
|
|||
client_t *cl, *newcl;
|
||||
//sharedEntity_t *ent;
|
||||
int clientNum;
|
||||
int version;
|
||||
int qport;
|
||||
int challenge;
|
||||
char *password;
|
||||
int startIndex;
|
||||
intptr_t denied;
|
||||
int count;
|
||||
int server_protocol;
|
||||
int cl_proto, sv_proto;
|
||||
const char *ip, *info, *v;
|
||||
qboolean compat;
|
||||
qboolean longstr;
|
||||
|
@ -518,27 +517,28 @@ void SV_DirectConnect( const netadr_t *from ) {
|
|||
}
|
||||
return;
|
||||
}
|
||||
version = atoi( v );
|
||||
cl_proto = atoi( v );
|
||||
|
||||
server_protocol = com_protocol->integer;
|
||||
if ( server_protocol == PROTOCOL_VERSION )
|
||||
sv_proto = com_protocol->integer;
|
||||
if ( sv_proto == DEFAULT_PROTOCOL_VERSION )
|
||||
{
|
||||
server_protocol = NEW_PROTOCOL_VERSION;
|
||||
// we support new protocol features by default
|
||||
sv_proto = NEW_PROTOCOL_VERSION;
|
||||
}
|
||||
|
||||
if ( version == PROTOCOL_VERSION )
|
||||
if ( cl_proto <= OLD_PROTOCOL_VERSION )
|
||||
compat = qtrue;
|
||||
else
|
||||
{
|
||||
if ( version != server_protocol )
|
||||
if ( cl_proto != sv_proto )
|
||||
{
|
||||
// avoid excessive outgoing traffic
|
||||
if ( !SVC_RateLimit( &bucket, 10, 200 ) )
|
||||
{
|
||||
NET_OutOfBandPrint( NS_SERVER, from, "print\nServer uses protocol version %i "
|
||||
"(yours is %i).\n", server_protocol, version );
|
||||
"(yours is %i).\n", sv_proto, cl_proto );
|
||||
}
|
||||
Com_DPrintf( " rejected connect from version %i\n", version );
|
||||
Com_DPrintf( " rejected connect from version %i\n", cl_proto );
|
||||
return;
|
||||
}
|
||||
compat = qfalse;
|
||||
|
@ -757,7 +757,7 @@ gotnewcl:
|
|||
|
||||
// send the connect packet to the client
|
||||
if ( longstr /*&& !compat*/ ) {
|
||||
NET_OutOfBandPrint( NS_SERVER, from, "connectResponse %d %d", challenge, server_protocol );
|
||||
NET_OutOfBandPrint( NS_SERVER, from, "connectResponse %d %d", challenge, sv_proto );
|
||||
} else {
|
||||
NET_OutOfBandPrint( NS_SERVER, from, "connectResponse %d", challenge );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue