Browse Source

engine: common: move network cvars to static allocation

pull/2/head
Alibek Omarov 2 years ago
parent
commit
4ce2475602
  1. 29
      engine/common/net_chan.c
  2. 141
      engine/common/net_ws.c
  3. 4
      engine/common/net_ws.h
  4. 6
      engine/server/sv_main.c

29
engine/common/net_chan.c

@ -84,10 +84,10 @@ such as during the connection stage while waiting for the client to load,
then a packet only needs to be delivered if there is something in the then a packet only needs to be delivered if there is something in the
unacknowledged reliable unacknowledged reliable
*/ */
convar_t *net_showpackets; CVAR_DEFINE_AUTO( net_showpackets, "0", 0, "show network packets" );
convar_t *net_chokeloopback; CVAR_DEFINE_AUTO( net_chokeloop, "0", 0, "apply bandwidth choke to loopback packets" );
convar_t *net_showdrop; CVAR_DEFINE_AUTO( net_showdrop, "0", 0, "show packets that are dropped" );
convar_t *net_qport; CVAR_DEFINE_AUTO( net_qport, "0", FCVAR_READ_ONLY, "current quake netport" );
int net_drop; int net_drop;
netadr_t net_from; netadr_t net_from;
@ -243,15 +243,18 @@ Netchan_Init
*/ */
void Netchan_Init( void ) void Netchan_Init( void )
{ {
char buf[32];
int port; int port;
// pick a port value that should be nice and random // pick a port value that should be nice and random
port = COM_RandomLong( 1, 65535 ); port = COM_RandomLong( 1, 65535 );
Q_snprintf( buf, sizeof( buf ), "%i", port );
net_showpackets = Cvar_Get ("net_showpackets", "0", 0, "show network packets" ); Cvar_RegisterVariable( &net_showpackets );
net_chokeloopback = Cvar_Get( "net_chokeloop", "0", 0, "apply bandwidth choke to loopback packets" ); Cvar_RegisterVariable( &net_chokeloop );
net_showdrop = Cvar_Get( "net_showdrop", "0", 0, "show packets that are dropped" ); Cvar_RegisterVariable( &net_showdrop );
net_qport = Cvar_Getf( "net_qport", FCVAR_READ_ONLY, "current quake netport", "%i", port ); Cvar_RegisterVariable( &net_qport );
Cvar_DirectSet( &net_qport, buf );
net_mempool = Mem_AllocPool( "Network Pool" ); net_mempool = Mem_AllocPool( "Network Pool" );
@ -349,7 +352,7 @@ Returns true if the bandwidth choke isn't active
qboolean Netchan_CanPacket( netchan_t *chan, qboolean choke ) qboolean Netchan_CanPacket( netchan_t *chan, qboolean choke )
{ {
// never choke loopback packets. // never choke loopback packets.
if( !choke || ( !net_chokeloopback->value && NET_IsLocalAddress( chan->remote_address ) )) if( !choke || ( !net_chokeloop.value && NET_IsLocalAddress( chan->remote_address ) ))
{ {
chan->cleartime = host.realtime; chan->cleartime = host.realtime;
return true; return true;
@ -1699,7 +1702,7 @@ void Netchan_TransmitBits( netchan_t *chan, int length, byte *data )
chan->cleartime += ( MSG_GetNumBytesWritten( &send ) + UDP_HEADER_SIZE ) * fRate; chan->cleartime += ( MSG_GetNumBytesWritten( &send ) + UDP_HEADER_SIZE ) * fRate;
if( net_showpackets->value && net_showpackets->value != 2.0f ) if( net_showpackets.value && net_showpackets.value != 2.0f )
{ {
Con_Printf( " %s --> sz=%i seq=%i ack=%i rel=%i tm=%f\n" Con_Printf( " %s --> sz=%i seq=%i ack=%i rel=%i tm=%f\n"
, ns_strings[chan->sock] , ns_strings[chan->sock]
@ -1769,7 +1772,7 @@ qboolean Netchan_Process( netchan_t *chan, sizebuf_t *msg )
sequence_ack &= ~BIT( 30 ); sequence_ack &= ~BIT( 30 );
sequence_ack &= ~BIT( 31 ); sequence_ack &= ~BIT( 31 );
if( net_showpackets->value && net_showpackets->value != 3.0f ) if( net_showpackets.value && net_showpackets.value != 3.0f )
{ {
Con_Printf( " %s <-- sz=%i seq=%i ack=%i rel=%i tm=%f\n" Con_Printf( " %s <-- sz=%i seq=%i ack=%i rel=%i tm=%f\n"
, ns_strings[chan->sock] , ns_strings[chan->sock]
@ -1783,7 +1786,7 @@ qboolean Netchan_Process( netchan_t *chan, sizebuf_t *msg )
// discard stale or duplicated packets // discard stale or duplicated packets
if( sequence <= (uint)chan->incoming_sequence ) if( sequence <= (uint)chan->incoming_sequence )
{ {
if( net_showdrop->value ) if( net_showdrop.value )
{ {
const char *adr = NET_AdrToString( chan->remote_address ); const char *adr = NET_AdrToString( chan->remote_address );
@ -1796,7 +1799,7 @@ qboolean Netchan_Process( netchan_t *chan, sizebuf_t *msg )
// dropped packets don't keep the message from being used // dropped packets don't keep the message from being used
net_drop = sequence - ( chan->incoming_sequence + 1 ); net_drop = sequence - ( chan->incoming_sequence + 1 );
if( net_drop > 0 && net_showdrop->value ) if( net_drop > 0 && net_showdrop.value )
Con_Printf( "%s:dropped %i packets at %i\n", NET_AdrToString( chan->remote_address ), net_drop, sequence ); Con_Printf( "%s:dropped %i packets at %i\n", NET_AdrToString( chan->remote_address ), net_drop, sequence );
// if the current outgoing reliable message has been acknowledged // if the current outgoing reliable message has been acknowledged

141
engine/common/net_ws.c

@ -108,23 +108,24 @@ typedef struct
} net_state_t; } net_state_t;
static net_state_t net; static net_state_t net;
static convar_t *net_ipname; static CVAR_DEFINE_AUTO( net_address, "0", FCVAR_PRIVILEGED|FCVAR_READ_ONLY, "contain local address of current client" );
static convar_t *net_hostport; static CVAR_DEFINE( net_ipname, "ip", "localhost", FCVAR_PRIVILEGED, "network ip address" );
static convar_t *net_iphostport; static CVAR_DEFINE( net_iphostport, "ip_hostport", "0", FCVAR_READ_ONLY, "network ip host port" );
static convar_t *net_clientport; static CVAR_DEFINE( net_hostport, "hostport", "0", FCVAR_READ_ONLY, "network default host port" );
static convar_t *net_ipclientport; static CVAR_DEFINE( net_ipclientport, "ip_clientport", "0", FCVAR_READ_ONLY, "network ip client port" );
static convar_t *net_fakelag; static CVAR_DEFINE( net_clientport, "clientport", "0", FCVAR_READ_ONLY, "network default client port" );
static convar_t *net_fakeloss; static CVAR_DEFINE( net_fakelag, "fakelag", "0", FCVAR_PRIVILEGED, "lag all incoming network data (including loopback) by xxx ms." );
static convar_t *net_address; static CVAR_DEFINE( net_fakeloss, "fakeloss", "0", FCVAR_PRIVILEGED, "act like we dropped the packet this % of the time." );
convar_t *net_clockwindow; CVAR_DEFINE( net_clockwindow, "clockwindow", "0.5", FCVAR_PRIVILEGED, "timewindow to execute client moves" );
netadr_t net_local; netadr_t net_local;
netadr_t net6_local; netadr_t net6_local;
// cvars equivalents for IPv6 // cvars equivalents for IPv6
static convar_t *net_ip6name; static CVAR_DEFINE( net_ip6name, "ip6", "localhost", FCVAR_PRIVILEGED, "network ip6 address" );
static convar_t *net_ip6hostport; static CVAR_DEFINE( net_ip6hostport, "ip6_hostport", "0", FCVAR_READ_ONLY, "network ip6 host port" );
static convar_t *net_ip6clientport; static CVAR_DEFINE( net_ip6clientport, "ip6_clientport", "0", FCVAR_READ_ONLY, "network ip6 client port" );
static convar_t *net6_address; static CVAR_DEFINE_AUTO( net6_address, "0", FCVAR_PRIVILEGED|FCVAR_READ_ONLY, "contain local IPv6 address of current client" );
/* /*
==================== ====================
@ -1243,11 +1244,11 @@ static void NET_AdjustLag( void )
dt = bound( 0.0, dt, 0.1 ); dt = bound( 0.0, dt, 0.1 );
lasttime = host.realtime; lasttime = host.realtime;
if( host_developer.value || !net_fakelag->value ) if( host_developer.value || !net_fakelag.value )
{ {
if( net_fakelag->value != net.fakelag ) if( net_fakelag.value != net.fakelag )
{ {
diff = net_fakelag->value - net.fakelag; diff = net_fakelag.value - net.fakelag;
converge = dt * 200.0f; converge = dt * 200.0f;
if( fabs( diff ) < converge ) if( fabs( diff ) < converge )
converge = fabs( diff ); converge = fabs( diff );
@ -1288,14 +1289,14 @@ static qboolean NET_LagPacket( qboolean newdata, netsrc_t sock, netadr_t *from,
if( newdata ) if( newdata )
{ {
if( net_fakeloss->value != 0.0f ) if( net_fakeloss.value != 0.0f )
{ {
if( host_developer.value ) if( host_developer.value )
{ {
net.losscount[sock]++; net.losscount[sock]++;
if( net_fakeloss->value <= 0.0f ) if( net_fakeloss.value <= 0.0f )
{ {
ninterval = fabs( net_fakeloss->value ); ninterval = fabs( net_fakeloss.value );
if( ninterval < 2 ) ninterval = 2; if( ninterval < 2 ) ninterval = 2;
if(( net.losscount[sock] % ninterval ) == 0 ) if(( net.losscount[sock] % ninterval ) == 0 )
@ -1303,7 +1304,7 @@ static qboolean NET_LagPacket( qboolean newdata, netsrc_t sock, netadr_t *from,
} }
else else
{ {
if( COM_RandomLong( 0, 100 ) <= net_fakeloss->value ) if( COM_RandomLong( 0, 100 ) <= net_fakeloss.value )
return false; return false;
} }
} }
@ -1392,7 +1393,7 @@ qboolean NET_GetLong( byte *pData, int size, size_t *outSize, int splitsize )
for( i = 0; i < NET_MAX_FRAGMENTS; i++ ) for( i = 0; i < NET_MAX_FRAGMENTS; i++ )
net.split_flags[i] = -1; net.split_flags[i] = -1;
if( net_showpackets && net_showpackets->value == 4.0f ) if( net_showpackets.value == 4.0f )
Con_Printf( "<-- Split packet restart %i count %i seq\n", net.split.split_count, sequence_number ); Con_Printf( "<-- Split packet restart %i count %i seq\n", net.split.split_count, sequence_number );
} }
@ -1406,7 +1407,7 @@ qboolean NET_GetLong( byte *pData, int size, size_t *outSize, int splitsize )
net.split.split_count--; net.split.split_count--;
net.split_flags[packet_number] = sequence_number; net.split_flags[packet_number] = sequence_number;
if( net_showpackets && net_showpackets->value == 4.0f ) if( net_showpackets.value == 4.0f )
Con_Printf( "<-- Split packet %i of %i, %i bytes %i seq\n", packet_number + 1, packet_count, size, sequence_number ); Con_Printf( "<-- Split packet %i of %i, %i bytes %i seq\n", packet_number + 1, packet_count, size, sequence_number );
} }
else else
@ -1577,7 +1578,7 @@ int NET_SendLong( netsrc_t sock, int net_socket, const char *buf, size_t len, in
pPacket->packet_id = (packet_number << 8) + packet_count; pPacket->packet_id = (packet_number << 8) + packet_count;
memcpy( packet + sizeof( SPLITPACKET ), buf + ( packet_number * body_size ), size ); memcpy( packet + sizeof( SPLITPACKET ), buf + ( packet_number * body_size ), size );
if( net_showpackets && net_showpackets->value == 3.0f ) if( net_showpackets.value == 3.0f )
{ {
netadr_t adr; netadr_t adr;
@ -1813,14 +1814,14 @@ static void NET_OpenIP( qboolean change_port, int *sockets, const char *net_ifac
qboolean sv_nat = Cvar_VariableInteger("sv_nat"); qboolean sv_nat = Cvar_VariableInteger("sv_nat");
qboolean cl_nat = Cvar_VariableInteger("cl_nat"); qboolean cl_nat = Cvar_VariableInteger("cl_nat");
if( change_port && ( FBitSet( net_hostport->flags, FCVAR_CHANGED ) || sv_nat )) if( change_port && ( FBitSet( net_hostport.flags, FCVAR_CHANGED ) || sv_nat ))
{ {
// reopen socket to set random port // reopen socket to set random port
if( NET_IsSocketValid( sockets[NS_SERVER] )) if( NET_IsSocketValid( sockets[NS_SERVER] ))
closesocket( sockets[NS_SERVER] ); closesocket( sockets[NS_SERVER] );
sockets[NS_SERVER] = INVALID_SOCKET; sockets[NS_SERVER] = INVALID_SOCKET;
ClearBits( net_hostport->flags, FCVAR_CHANGED ); ClearBits( net_hostport.flags, FCVAR_CHANGED );
} }
if( !NET_IsSocketValid( sockets[NS_SERVER] )) if( !NET_IsSocketValid( sockets[NS_SERVER] ))
@ -1828,7 +1829,7 @@ static void NET_OpenIP( qboolean change_port, int *sockets, const char *net_ifac
port = hostport; port = hostport;
if( !port ) if( !port )
{ {
port = sv_nat ? PORT_ANY : net_hostport->value; port = sv_nat ? PORT_ANY : net_hostport.value;
if( !port ) if( !port )
port = PORT_SERVER; // forcing to default port = PORT_SERVER; // forcing to default
@ -1842,14 +1843,14 @@ static void NET_OpenIP( qboolean change_port, int *sockets, const char *net_ifac
// dedicated servers don't need client ports // dedicated servers don't need client ports
if( Host_IsDedicated( )) return; if( Host_IsDedicated( )) return;
if( change_port && ( FBitSet( net_clientport->flags, FCVAR_CHANGED ) || cl_nat )) if( change_port && ( FBitSet( net_clientport.flags, FCVAR_CHANGED ) || cl_nat ))
{ {
// reopen socket to set random port // reopen socket to set random port
if( NET_IsSocketValid( sockets[NS_CLIENT] )) if( NET_IsSocketValid( sockets[NS_CLIENT] ))
closesocket( sockets[NS_CLIENT] ); closesocket( sockets[NS_CLIENT] );
sockets[NS_CLIENT] = INVALID_SOCKET; sockets[NS_CLIENT] = INVALID_SOCKET;
ClearBits( net_clientport->flags, FCVAR_CHANGED ); ClearBits( net_clientport.flags, FCVAR_CHANGED );
} }
if( !NET_IsSocketValid( sockets[NS_CLIENT] )) if( !NET_IsSocketValid( sockets[NS_CLIENT] ))
@ -1857,7 +1858,7 @@ static void NET_OpenIP( qboolean change_port, int *sockets, const char *net_ifac
port = clientport; port = clientport;
if( !port ) if( !port )
{ {
port = cl_nat ? PORT_ANY : net_clientport->value; port = cl_nat ? PORT_ANY : net_clientport.value;
if( !port ) if( !port )
port = PORT_ANY; // forcing to default port = PORT_ANY; // forcing to default
@ -1865,7 +1866,7 @@ static void NET_OpenIP( qboolean change_port, int *sockets, const char *net_ifac
sockets[NS_CLIENT] = NET_IPSocket( net_iface, port, family ); sockets[NS_CLIENT] = NET_IPSocket( net_iface, port, family );
if( !NET_IsSocketValid( sockets[NS_CLIENT] )) if( !NET_IsSocketValid( sockets[NS_CLIENT] ))
sockets[NS_CLIENT] = NET_IPSocket( net_ipname->string, PORT_ANY, family ); sockets[NS_CLIENT] = NET_IPSocket( net_ipname.string, PORT_ANY, family );
} }
return; return;
@ -1901,8 +1902,8 @@ void NET_GetLocalAddress( void )
if( net.allow_ip ) if( net.allow_ip )
{ {
// If we have changed the ip var from the command line, use that instead. // If we have changed the ip var from the command line, use that instead.
if( Q_stricmp( net_ipname->string, "localhost" )) if( Q_stricmp( net_ipname.string, "localhost" ))
Q_strncpy( buff, net_ipname->string, sizeof( buff )); Q_strncpy( buff, net_ipname.string, sizeof( buff ));
else Q_strncpy( buff, hostname, sizeof( buff )); else Q_strncpy( buff, hostname, sizeof( buff ));
if( NET_StringToAdrEx( buff, &net_local, AF_INET )) if( NET_StringToAdrEx( buff, &net_local, AF_INET ))
@ -1914,7 +1915,7 @@ void NET_GetLocalAddress( void )
net_local.port = ((struct sockaddr_in *)&address)->sin_port; net_local.port = ((struct sockaddr_in *)&address)->sin_port;
net_addr_string = NET_AdrToString( net_local ); net_addr_string = NET_AdrToString( net_local );
Con_Printf( "Server IPv4 address %s\n", net_addr_string ); Con_Printf( "Server IPv4 address %s\n", net_addr_string );
Cvar_FullSet( "net_address", net_addr_string, net_address->flags ); Cvar_FullSet( "net_address", net_addr_string, net_address.flags );
} }
else Con_DPrintf( S_ERROR "Could not get TCP/IPv4 address. Reason: %s\n", NET_ErrorString( )); else Con_DPrintf( S_ERROR "Could not get TCP/IPv4 address. Reason: %s\n", NET_ErrorString( ));
} }
@ -1924,8 +1925,8 @@ void NET_GetLocalAddress( void )
if( net.allow_ip6 ) if( net.allow_ip6 )
{ {
// If we have changed the ip var from the command line, use that instead. // If we have changed the ip var from the command line, use that instead.
if( Q_stricmp( net_ip6name->string, "localhost" )) if( Q_stricmp( net_ip6name.string, "localhost" ))
Q_strncpy( buff, net_ip6name->string, sizeof( buff )); Q_strncpy( buff, net_ip6name.string, sizeof( buff ));
else Q_strncpy( buff, hostname, sizeof( buff )); else Q_strncpy( buff, hostname, sizeof( buff ));
if( NET_StringToAdrEx( buff, &net6_local, AF_INET6 )) if( NET_StringToAdrEx( buff, &net6_local, AF_INET6 ))
@ -1937,7 +1938,7 @@ void NET_GetLocalAddress( void )
net6_local.port = ((struct sockaddr_in6 *)&address)->sin6_port; net6_local.port = ((struct sockaddr_in6 *)&address)->sin6_port;
net_addr_string = NET_AdrToString( net6_local ); net_addr_string = NET_AdrToString( net6_local );
Con_Printf( "Server IPv6 address %s\n", net_addr_string ); Con_Printf( "Server IPv6 address %s\n", net_addr_string );
Cvar_FullSet( "net6_address", net_addr_string, net6_address->flags ); Cvar_FullSet( "net6_address", net_addr_string, net6_address.flags );
} }
else Con_DPrintf( S_ERROR "Could not get TCP/IPv6 address. Reason: %s\n", NET_ErrorString( )); else Con_DPrintf( S_ERROR "Could not get TCP/IPv6 address. Reason: %s\n", NET_ErrorString( ));
} }
@ -1969,10 +1970,10 @@ void NET_Config( qboolean multiplayer, qboolean changeport )
{ {
// open sockets // open sockets
if( net.allow_ip ) if( net.allow_ip )
NET_OpenIP( changeport, net.ip_sockets, net_ipname->string, net_iphostport->value, net_ipclientport->value, AF_INET ); NET_OpenIP( changeport, net.ip_sockets, net_ipname.string, net_iphostport.value, net_ipclientport.value, AF_INET );
if( net.allow_ip6 ) if( net.allow_ip6 )
NET_OpenIP( changeport, net.ip6_sockets, net_ip6name->string, net_ip6hostport->value, net_ip6clientport->value, AF_INET6 ); NET_OpenIP( changeport, net.ip6_sockets, net_ip6name.string, net_ip6hostport.value, net_ip6clientport.value, AF_INET6 );
// validate sockets for dedicated // validate sockets for dedicated
if( Host_IsDedicated( )) if( Host_IsDedicated( ))
@ -2100,21 +2101,26 @@ void NET_Init( void )
if( net.initialized ) return; if( net.initialized ) return;
net_clockwindow = Cvar_Get( "clockwindow", "0.5", FCVAR_PRIVILEGED, "timewindow to execute client moves" ); Cvar_RegisterVariable( &net_address );
net_address = Cvar_Get( "net_address", "0", FCVAR_PRIVILEGED|FCVAR_READ_ONLY, "contain local address of current client" ); Cvar_RegisterVariable( &net_ipname );
net_ipname = Cvar_Get( "ip", "localhost", FCVAR_PRIVILEGED, "network ip address" ); Cvar_RegisterVariable( &net_iphostport );
net_iphostport = Cvar_Get( "ip_hostport", "0", FCVAR_READ_ONLY, "network ip host port" ); Cvar_RegisterVariable( &net_hostport );
net_hostport = Cvar_Getf( "hostport", FCVAR_READ_ONLY, "network default host port", "%i", PORT_SERVER ); Cvar_RegisterVariable( &net_ipclientport );
net_ipclientport = Cvar_Get( "ip_clientport", "0", FCVAR_READ_ONLY, "network ip client port" ); Cvar_RegisterVariable( &net_clientport );
net_clientport = Cvar_Getf( "clientport", FCVAR_READ_ONLY, "network default client port", "%i", PORT_CLIENT ); Cvar_RegisterVariable( &net_fakelag );
net_fakelag = Cvar_Get( "fakelag", "0", FCVAR_PRIVILEGED, "lag all incoming network data (including loopback) by xxx ms." ); Cvar_RegisterVariable( &net_fakeloss );
net_fakeloss = Cvar_Get( "fakeloss", "0", FCVAR_PRIVILEGED, "act like we dropped the packet this % of the time." );
Q_snprintf( cmd, sizeof( cmd ), "%i", PORT_SERVER );
Cvar_DirectSet( &net_hostport, cmd );
Q_snprintf( cmd, sizeof( cmd ), "%i", PORT_CLIENT );
Cvar_DirectSet( &net_clientport, cmd );
// cvar equivalents for IPv6 // cvar equivalents for IPv6
net_ip6name = Cvar_Get( "ip6", "localhost", FCVAR_PRIVILEGED, "network ip6 address" ); Cvar_RegisterVariable( &net_ip6name );
net_ip6hostport = Cvar_Get( "ip6_hostport", "0", FCVAR_READ_ONLY, "network ip6 host port" ); Cvar_RegisterVariable( &net_ip6hostport );
net_ip6clientport = Cvar_Get( "ip6_clientport", "0", FCVAR_READ_ONLY, "network ip6 client port" ); Cvar_RegisterVariable( &net_ip6clientport );
net6_address = Cvar_Get( "net6_address", "0", FCVAR_PRIVILEGED|FCVAR_READ_ONLY, "contain local IPv6 address of current client" ); Cvar_RegisterVariable( &net6_address );
// prepare some network data // prepare some network data
for( i = 0; i < NS_COUNT; i++ ) for( i = 0; i < NS_COUNT; i++ )
@ -2150,11 +2156,11 @@ void NET_Init( void )
// specify custom ip // specify custom ip
if( Sys_GetParmFromCmdLine( "-ip", cmd )) if( Sys_GetParmFromCmdLine( "-ip", cmd ))
Cvar_FullSet( "ip", cmd, net_ipname->flags ); Cvar_FullSet( "ip", cmd, net_ipname.flags );
// specify custom ip6 // specify custom ip6
if( Sys_GetParmFromCmdLine( "-ip6", cmd )) if( Sys_GetParmFromCmdLine( "-ip6", cmd ))
Cvar_FullSet( "ip6", cmd, net_ip6name->flags ); Cvar_FullSet( "ip6", cmd, net_ip6name.flags );
// adjust clockwindow // adjust clockwindow
if( Sys_GetParmFromCmdLine( "-clockwindow", cmd )) if( Sys_GetParmFromCmdLine( "-clockwindow", cmd ))
@ -2246,10 +2252,10 @@ static struct http_static_s
} http; } http;
static convar_t *http_useragent; static CVAR_DEFINE_AUTO( http_useragent, "", FCVAR_ARCHIVE | FCVAR_PRIVILEGED, "User-Agent string" );
static convar_t *http_autoremove; static CVAR_DEFINE_AUTO( http_autoremove, "1", FCVAR_ARCHIVE | FCVAR_PRIVILEGED, "remove broken files" );
static convar_t *http_timeout; static CVAR_DEFINE_AUTO( http_timeout, "45", FCVAR_ARCHIVE | FCVAR_PRIVILEGED, "timeout for http downloader" );
static convar_t *http_maxconnections; static CVAR_DEFINE_AUTO( http_maxconnections, "4", FCVAR_ARCHIVE | FCVAR_PRIVILEGED, "maximum http connection number" );
/* /*
======================== ========================
@ -2304,7 +2310,7 @@ static void HTTP_FreeFile( httpfile_t *file, qboolean error )
} }
// Called because there was no servers to download, free file now // Called because there was no servers to download, free file now
if( http_autoremove->value == 1 ) // remove broken file if( http_autoremove.value == 1 ) // remove broken file
FS_Delete( incname ); FS_Delete( incname );
else // autoremove disabled, keep file else // autoremove disabled, keep file
Con_Printf( "cannot download %s from any server. " Con_Printf( "cannot download %s from any server. "
@ -2525,7 +2531,7 @@ void HTTP_Run( void )
{ {
char name[MAX_SYSPATH]; char name[MAX_SYSPATH];
if( iActiveCount > http_maxconnections->value ) if( iActiveCount > http_maxconnections.value )
continue; continue;
if( !curfile->server ) if( !curfile->server )
@ -2624,14 +2630,14 @@ void HTTP_Run( void )
{ {
string useragent; string useragent;
if( !COM_CheckStringEmpty( http_useragent->string ) || !Q_strcmp( http_useragent->string, "xash3d" )) if( !COM_CheckStringEmpty( http_useragent.string ) || !Q_strcmp( http_useragent.string, "xash3d" ))
{ {
Q_snprintf( useragent, sizeof( useragent ), "%s/%s (%s-%s; build %d; %s)", Q_snprintf( useragent, sizeof( useragent ), "%s/%s (%s-%s; build %d; %s)",
XASH_ENGINE_NAME, XASH_VERSION, Q_buildos( ), Q_buildarch( ), Q_buildnum( ), Q_buildcommit( )); XASH_ENGINE_NAME, XASH_VERSION, Q_buildos( ), Q_buildarch( ), Q_buildnum( ), Q_buildcommit( ));
} }
else else
{ {
Q_strncpy( useragent, http_useragent->string, sizeof( useragent )); Q_strncpy( useragent, http_useragent.string, sizeof( useragent ));
} }
curfile->query_length = Q_snprintf( curfile->buf, sizeof( curfile->buf ), curfile->query_length = Q_snprintf( curfile->buf, sizeof( curfile->buf ),
@ -2666,7 +2672,7 @@ void HTTP_Run( void )
curfile->blocktime += host.frametime; curfile->blocktime += host.frametime;
wait = true; wait = true;
if( curfile->blocktime > http_timeout->value ) if( curfile->blocktime > http_timeout.value )
{ {
Con_Printf( S_ERROR "timeout on request send:\n%s\n", curfile->buf ); Con_Printf( S_ERROR "timeout on request send:\n%s\n", curfile->buf );
HTTP_FreeFile( curfile, true ); HTTP_FreeFile( curfile, true );
@ -2708,7 +2714,7 @@ void HTTP_Run( void )
else else
curfile->blocktime += host.frametime; curfile->blocktime += host.frametime;
if( curfile->blocktime > http_timeout->value ) if( curfile->blocktime > http_timeout.value )
{ {
Con_Printf( S_ERROR "timeout on receiving data!\n"); Con_Printf( S_ERROR "timeout on receiving data!\n");
HTTP_FreeFile( curfile, true ); HTTP_FreeFile( curfile, true );
@ -2986,10 +2992,11 @@ void HTTP_Init( void )
Cmd_AddRestrictedCommand( "http_clear", HTTP_Clear_f, "cancel all downloads" ); Cmd_AddRestrictedCommand( "http_clear", HTTP_Clear_f, "cancel all downloads" );
Cmd_AddRestrictedCommand( "http_list", HTTP_List_f, "list all queued downloads" ); Cmd_AddRestrictedCommand( "http_list", HTTP_List_f, "list all queued downloads" );
Cmd_AddCommand( "http_addcustomserver", HTTP_AddCustomServer_f, "add custom fastdl server"); Cmd_AddCommand( "http_addcustomserver", HTTP_AddCustomServer_f, "add custom fastdl server");
http_useragent = Cvar_Get( "http_useragent", "", FCVAR_ARCHIVE | FCVAR_PRIVILEGED, "User-Agent string" );
http_autoremove = Cvar_Get( "http_autoremove", "1", FCVAR_ARCHIVE | FCVAR_PRIVILEGED, "remove broken files" ); Cvar_RegisterVariable( &http_useragent );
http_timeout = Cvar_Get( "http_timeout", "45", FCVAR_ARCHIVE | FCVAR_PRIVILEGED, "timeout for http downloader" ); Cvar_RegisterVariable( &http_autoremove );
http_maxconnections = Cvar_Get( "http_maxconnections", "4", FCVAR_ARCHIVE | FCVAR_PRIVILEGED, "maximum http connection number" ); Cvar_RegisterVariable( &http_timeout );
Cvar_RegisterVariable( &http_maxconnections );
// Read servers from fastdl.txt // Read servers from fastdl.txt
line = serverfile = (char *)FS_LoadFile( "fastdl.txt", 0, false ); line = serverfile = (char *)FS_LoadFile( "fastdl.txt", 0, false );

4
engine/common/net_ws.h

@ -50,8 +50,8 @@ typedef enum
#include "netadr.h" #include "netadr.h"
extern convar_t *net_showpackets; extern convar_t net_showpackets;
extern convar_t *net_clockwindow; extern convar_t net_clockwindow;
void NET_Init( void ); void NET_Init( void );
void NET_Shutdown( void ); void NET_Shutdown( void );

6
engine/server/sv_main.c

@ -273,12 +273,12 @@ void SV_CheckCmdTimes( void )
diff = cl->connecttime + cl->cmdtime - host.realtime; diff = cl->connecttime + cl->cmdtime - host.realtime;
if( diff > net_clockwindow->value ) if( diff > net_clockwindow.value )
{ {
cl->ignorecmdtime = net_clockwindow->value + host.realtime; cl->ignorecmdtime = net_clockwindow.value + host.realtime;
cl->cmdtime = host.realtime - cl->connecttime; cl->cmdtime = host.realtime - cl->connecttime;
} }
else if( diff < -net_clockwindow->value ) else if( diff < -net_clockwindow.value )
{ {
cl->cmdtime = host.realtime - cl->connecttime; cl->cmdtime = host.realtime - cl->connecttime;
} }

Loading…
Cancel
Save