Skip to content

Commit

Permalink
Merge pull request #10 from YGGverse/sv-downloadurl-ipv6
Browse files Browse the repository at this point in the history
Sv downloadurl ipv6
  • Loading branch information
d47081 authored Jan 17, 2024
2 parents 34005a1 + bc846bb commit 3fc219e
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 17 deletions.
67 changes: 52 additions & 15 deletions engine/common/net_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 )
{
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions engine/server/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion engine/server/sv_custom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
4 changes: 3 additions & 1 deletion engine/server/sv_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 3fc219e

Please sign in to comment.