mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 03:24:56 +08:00
engine: client: refactor connection to the server, always send bandwidth test and challenge from single function
This commit is contained in:
@@ -1233,7 +1233,7 @@ static void CL_CheckForResend( void )
|
||||
else if( cl_resend.value > CL_MAX_RESEND_TIME )
|
||||
Cvar_DirectSetValue( &cl_resend, CL_MAX_RESEND_TIME );
|
||||
|
||||
bandwidthTest = cls.legacymode == PROTO_CURRENT && cl_test_bandwidth.value && cls.connect_retry <= CL_TEST_RETRIES;
|
||||
bandwidthTest = cls.legacymode == PROTO_CURRENT && cl_test_bandwidth.value && cls.connect_retry <= CL_TEST_RETRIES && !cls.passed_bandwidth_test;
|
||||
resendTime = bandwidthTest ? 2.0f : cl_resend.value;
|
||||
|
||||
if(( host.realtime - cls.connect_time ) < resendTime )
|
||||
@@ -1267,12 +1267,8 @@ static void CL_CheckForResend( void )
|
||||
{
|
||||
// too many fails use default connection method
|
||||
Con_Printf( "Bandwidth test failed, fallback to default connecting method\n" );
|
||||
Con_Printf( "Connecting to %s... (retry #%i)\n", cls.servername, cls.connect_retry + 1 );
|
||||
CL_SendGetChallenge( adr );
|
||||
Cvar_DirectSetValue( &cl_dlmax, FRAGMENT_MIN_SIZE );
|
||||
cls.connect_time = host.realtime;
|
||||
cls.connect_retry++;
|
||||
return;
|
||||
bandwidthTest = false;
|
||||
}
|
||||
|
||||
cls.serveradr = adr;
|
||||
@@ -1417,6 +1413,7 @@ static void CL_Connect_f( void )
|
||||
cls.connect_time = MAX_HEARTBEAT; // CL_CheckForResend() will fire immediately
|
||||
cls.max_fragment_size = FRAGMENT_MAX_SIZE; // guess a we can establish connection with maximum fragment size
|
||||
cls.connect_retry = 0;
|
||||
cls.passed_bandwidth_test = false;
|
||||
cls.spectator = false;
|
||||
cls.signon = 0;
|
||||
}
|
||||
@@ -1677,6 +1674,7 @@ void CL_Disconnect( void )
|
||||
memset( &cls.serveradr, 0, sizeof( cls.serveradr ) );
|
||||
cls.set_lastdemo = false;
|
||||
cls.connect_retry = 0;
|
||||
cls.passed_bandwidth_test = false;
|
||||
cls.signon = 0;
|
||||
cls.legacymode = PROTO_CURRENT;
|
||||
|
||||
@@ -2287,14 +2285,11 @@ static void CL_HandleTestPacket( netadr_t from, sizebuf_t *msg )
|
||||
{
|
||||
// too many fails use default connection method
|
||||
Con_Printf( "hi-speed connection is failed, use default method\n" );
|
||||
CL_SendGetChallenge( from );
|
||||
Cvar_SetValue( "cl_dlmax", FRAGMENT_DEFAULT_SIZE );
|
||||
cls.connect_time = host.realtime;
|
||||
cls.connect_time = MAX_HEARTBEAT;
|
||||
return;
|
||||
}
|
||||
|
||||
// if we waiting more than cl_timeout or packet was trashed
|
||||
cls.connect_time = MAX_HEARTBEAT;
|
||||
return; // just wait for a next responce
|
||||
}
|
||||
|
||||
@@ -2306,12 +2301,11 @@ static void CL_HandleTestPacket( netadr_t from, sizebuf_t *msg )
|
||||
|
||||
if( crcValue == crcValue2 )
|
||||
{
|
||||
// packet was sucessfully delivered, adjust the fragment size and get challenge
|
||||
|
||||
// packet was sucessfully delivered, adjust the fragment size
|
||||
Con_DPrintf( "CRC %x is matched, get challenge, fragment size %d\n", crcValue, cls.max_fragment_size );
|
||||
CL_SendGetChallenge( from );
|
||||
Cvar_SetValue( "cl_dlmax", cls.max_fragment_size );
|
||||
cls.connect_time = host.realtime;
|
||||
cls.connect_time = MAX_HEARTBEAT;
|
||||
cls.passed_bandwidth_test = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2319,16 +2313,12 @@ static void CL_HandleTestPacket( netadr_t from, sizebuf_t *msg )
|
||||
{
|
||||
// too many fails use default connection method
|
||||
Con_Printf( "hi-speed connection is failed, use default method\n" );
|
||||
CL_SendGetChallenge( from );
|
||||
Cvar_SetValue( "cl_dlmax", FRAGMENT_MIN_SIZE );
|
||||
cls.connect_time = host.realtime;
|
||||
return;
|
||||
}
|
||||
|
||||
Msg( "got testpacket, CRC mismatched 0x%08x should be 0x%08x, trying next fragment size %d\n", crcValue2, crcValue, cls.max_fragment_size >> 1 );
|
||||
|
||||
// trying the next size of packet
|
||||
cls.connect_time = MAX_HEARTBEAT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2596,6 +2596,7 @@ void CL_ParseServerMessage( sizebuf_t *msg )
|
||||
else cls.state = ca_connecting;
|
||||
cl.background = old_background;
|
||||
cls.connect_time = MAX_HEARTBEAT;
|
||||
cls.passed_bandwidth_test = false;
|
||||
cls.connect_retry = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -405,6 +405,7 @@ void CL_ParseLegacyServerMessage( sizebuf_t *msg )
|
||||
else cls.state = ca_connecting;
|
||||
cl.background = old_background;
|
||||
cls.connect_time = MAX_HEARTBEAT;
|
||||
cls.passed_bandwidth_test = false;
|
||||
cls.connect_retry = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -550,6 +550,7 @@ typedef struct
|
||||
double connect_time; // for connection retransmits
|
||||
int max_fragment_size; // we needs to test a real network bandwidth
|
||||
int connect_retry; // how many times we send a connect packet to the server
|
||||
qboolean passed_bandwidth_test; // if testpacket matched CRC, stop test and send challenge
|
||||
qboolean spectator; // not a real player, just spectator
|
||||
|
||||
local_state_t spectator_state; // init as client startup
|
||||
|
||||
Reference in New Issue
Block a user