Browse Source

Merge pull request #10 from YGGverse/sv-downloadurl-ipv6

Sv downloadurl ipv6
yggdrasil-inclusive yggdrasil-inclusive-1.0.0
d47081 10 months ago committed by GitHub
parent
commit
3fc219e2a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 67
      engine/common/net_ws.c
  2. 1
      engine/server/server.h
  3. 9
      engine/server/sv_custom.c
  4. 4
      engine/server/sv_main.c

67
engine/common/net_ws.c

@ -2553,7 +2553,13 @@ void HTTP_Run( void ) @@ -2553,7 +2553,13 @@ void HTTP_Run( void )
{
dword mode;
curfile->socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
// IPv6
if ( Q_strstr( curfile->server->host, ":" ))
curfile->socket = socket( AF_INET6, SOCK_STREAM, IPPROTO_TCP );
// IPv4
else
curfile->socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
// Now set non-blocking mode
// You may skip this if not supported by system,
@ -2575,9 +2581,21 @@ void HTTP_Run( void ) @@ -2575,9 +2581,21 @@ void HTTP_Run( void )
if( fResolving )
continue;
Q_snprintf( hostport, sizeof( hostport ), "%s:%d", curfile->server->host, curfile->server->port );
// IPv6
if ( Q_strstr( curfile->server->host, ":" ))
{
Q_snprintf( hostport, sizeof( hostport ), "[%s]:%d", curfile->server->host, curfile->server->port );
res = NET_StringToSockaddr( hostport, &addr, true, AF_INET );
res = NET_StringToSockaddr( hostport, &addr, true, AF_INET6 );
}
// IPv4
else
{
Q_snprintf( hostport, sizeof( hostport ), "%s:%d", curfile->server->host, curfile->server->port );
res = NET_StringToSockaddr( hostport, &addr, true, AF_INET );
}
if( res == NET_EAI_AGAIN )
{
@ -2780,24 +2798,43 @@ HTTP_ParseURL @@ -2780,24 +2798,43 @@ HTTP_ParseURL
*/
static httpserver_t *HTTP_ParseURL( const char *url )
{
httpserver_t *server;
int i;
httpserver_t *server = Z_Calloc( sizeof( httpserver_t ));
int i = 0;
url = Q_strstr( url, "http://" );
// IPv6
if( Q_strstr( url, "http://[" ) )
{
url += 8;
if( !url )
return NULL;
while( *url && ( *url != ']' ))
{
if( i > sizeof( server->host ))
return NULL;
url += 7;
server = Z_Calloc( sizeof( httpserver_t ));
i = 0;
server->host[i++] = *url++;
}
url++; // skip closing entity
}
while( *url && ( *url != ':' ) && ( *url != '/' ) && ( *url != '\r' ) && ( *url != '\n' ))
// IPv4
else
{
if( i > sizeof( server->host ))
return NULL;
if( Q_strstr( url, "http://" ) )
{
url += 7;
server->host[i++] = *url++;
while( *url && ( *url != ':' ) && ( *url != '/' ) && ( *url != '\r' ) && ( *url != '\n' ))
{
if( i > sizeof( server->host ))
return NULL;
server->host[i++] = *url++;
}
}
else
return NULL;
}
server->host[i] = 0;

1
engine/server/server.h

@ -414,6 +414,7 @@ extern convar_t sv_maxupdaterate; @@ -414,6 +414,7 @@ extern convar_t sv_maxupdaterate;
extern convar_t sv_minrate;
extern convar_t sv_maxrate;
extern convar_t sv_downloadurl;
extern convar_t sv_downloadurl_ipv6;
extern convar_t sv_newunit;
extern convar_t sv_clienttrace;
extern convar_t sv_failuretime;

9
engine/server/sv_custom.c

@ -562,7 +562,14 @@ void SV_SendResources( sv_client_t *cl, sizebuf_t *msg ) @@ -562,7 +562,14 @@ void SV_SendResources( sv_client_t *cl, sizebuf_t *msg )
MSG_WriteLong( msg, svs.spawncount );
MSG_WriteLong( msg, 0 );
if( COM_CheckString( sv_downloadurl.string ) && Q_strlen( sv_downloadurl.string ) < 256 )
if ( cl->netchan.remote_address.type6 == NA_IP6 && // If remote is IPv6 - check for sv_downloadurl_ipv6 first #1559
COM_CheckString( sv_downloadurl_ipv6.string ) && Q_strlen( sv_downloadurl_ipv6.string ) < 256 )
{
MSG_BeginServerCmd( msg, svc_resourcelocation );
MSG_WriteString( msg, sv_downloadurl_ipv6.string );
}
else if ( COM_CheckString( sv_downloadurl.string ) && Q_strlen( sv_downloadurl.string ) < 256 )
{
MSG_BeginServerCmd( msg, svc_resourcelocation );
MSG_WriteString( msg, sv_downloadurl.string );

4
engine/server/sv_main.c

@ -52,7 +52,8 @@ CVAR_DEFINE_AUTO( sv_allow_upload, "1", FCVAR_SERVER, "allow uploading custom re @@ -52,7 +52,8 @@ CVAR_DEFINE_AUTO( sv_allow_upload, "1", FCVAR_SERVER, "allow uploading custom re
CVAR_DEFINE( sv_allow_download, "sv_allowdownload", "1", FCVAR_SERVER, "allow downloading custom resources to the client" );
static CVAR_DEFINE_AUTO( sv_allow_dlfile, "1", 0, "compatibility cvar, does nothing" );
CVAR_DEFINE_AUTO( sv_uploadmax, "0.5", FCVAR_SERVER, "max size to upload custom resources (500 kB as default)" );
CVAR_DEFINE_AUTO( sv_downloadurl, "", FCVAR_PROTECTED, "location from which clients can download missing files" );
CVAR_DEFINE_AUTO( sv_downloadurl, "", FCVAR_PROTECTED, "IPv4 location from which clients can download missing files (applying for IPv4 connections" );
CVAR_DEFINE_AUTO( sv_downloadurl_ipv6, "", FCVAR_PROTECTED, "IPv6 location from which clients can download missing files (applying for IPv6 connections)" );
CVAR_DEFINE( sv_consistency, "mp_consistency", "1", FCVAR_SERVER, "enbale consistency check in multiplayer" );
CVAR_DEFINE_AUTO( mp_logecho, "1", 0, "log multiplayer frags to server logfile" );
CVAR_DEFINE_AUTO( mp_logfile, "1", 0, "log multiplayer frags to console" );
@ -934,6 +935,7 @@ void SV_Init( void ) @@ -934,6 +935,7 @@ void SV_Init( void )
Cvar_RegisterVariable( &sv_instancedbaseline );
Cvar_RegisterVariable( &sv_consistency );
Cvar_RegisterVariable( &sv_downloadurl );
Cvar_RegisterVariable( &sv_downloadurl_ipv6 );
Cvar_RegisterVariable( &sv_novis );
Cvar_RegisterVariable( &sv_hostmap );
Cvar_DirectSet( &sv_hostmap, GI->startmap );

Loading…
Cancel
Save