engine: make local ipv4 address private to net_ws, acquire local addresses with GetLocalAddress function

This commit is contained in:
Alibek Omarov
2025-03-20 05:39:02 +03:00
parent d93bee0cbc
commit 6b56e13b60
4 changed files with 32 additions and 5 deletions

View File

@@ -3410,7 +3410,7 @@ static void GAME_EXPORT NetAPI_Status( net_status_t *status )
status->latency = (connected) ? cl.frames[cl.parsecountmod].latency : 0.0;
status->remote_address = cls.netchan.remote_address;
status->packet_loss = packet_loss;
status->local_address = net_local;
NET_GetLocalAddress( &status->local_address, NULL ); // NetAPI doesn't know about IPv6
status->rate = rate.value;
}

View File

@@ -1791,12 +1791,12 @@ static void NET_OpenIP( qboolean change_port, int *sockets, const char *net_ifac
/*
================
NET_GetLocalAddress
NET_DetermineLocalAddress
Returns the servers' ip address as a string.
================
*/
static void NET_GetLocalAddress( void )
static void NET_DetermineLocalAddress( void )
{
char hostname[512];
char buff[512];
@@ -1910,7 +1910,7 @@ void NET_Config( qboolean multiplayer, qboolean changeport )
// get our local address, if possible
if( bFirst )
{
NET_GetLocalAddress();
NET_DetermineLocalAddress();
bFirst = false;
}
}
@@ -2006,6 +2006,32 @@ static void NET_ClearLagData( qboolean bClient, qboolean bServer )
if( bServer ) NET_ClearLaggedList( &net.lagdata[NS_SERVER] );
}
/*
====================
NET_GetLocalAddress
get local server addresses
====================
*/
void NET_GetLocalAddress( netadr_t *ip4, netadr_t *ip6 )
{
if( ip4 )
{
if( net.allow_ip )
*ip4 = net_local;
else
memset( ip4, 0, sizeof( *ip4 ));
}
if( ip6 )
{
if( net.allow_ip6 )
*ip6 = net6_local;
else
memset( ip6, 0, sizeof( *ip6 ));
}
}
/*
====================
NET_Init

View File

@@ -82,6 +82,8 @@ static inline qboolean NET_IsLocalAddress( netadr_t adr )
return NET_NetadrType( &adr ) == NA_LOOPBACK;
}
void NET_GetLocalAddress( netadr_t *ip4, netadr_t *ip6 );
#if !XASH_DEDICATED
int CL_GetSplitSize( void );
#endif

View File

@@ -290,7 +290,6 @@ typedef struct netchan_s
} netchan_t;
extern netadr_t net_from;
extern netadr_t net_local;
extern sizebuf_t net_message;
extern byte net_message_buffer[NET_MAX_MESSAGE];
extern convar_t sv_lan;