Browse Source

engine: common: simplify strings operations.

pull/2/head
Andrey Akhmichin 2 years ago committed by Alibek Omarov
parent
commit
177ed2c603
  1. 2
      engine/common/con_utils.c
  2. 4
      engine/common/crashhandler.c
  3. 2
      engine/common/host.c
  4. 30
      engine/common/net_ws.c

2
engine/common/con_utils.c

@ -368,7 +368,7 @@ qboolean Cmd_GetSavesList( const char *s, char *completedname, int length )
string matchbuf; string matchbuf;
int i, numsaves; int i, numsaves;
t = FS_Search( va( "%s%s*.sav", DEFAULT_SAVE_DIRECTORY, s ), true, true ); // lookup only in gamedir t = FS_Search( va( DEFAULT_SAVE_DIRECTORY "%s*.sav", s ), true, true ); // lookup only in gamedir
if( !t ) return false; if( !t ) return false;
COM_FileBase( t->filenames[0], matchbuf ); COM_FileBase( t->filenames[0], matchbuf );

4
engine/common/crashhandler.c

@ -358,8 +358,8 @@ static void Sys_Crash( int signal, siginfo_t *si, void *context)
#endif #endif
// safe actions first, stack and memory may be corrupted // safe actions first, stack and memory may be corrupted
len = Q_snprintf( message, sizeof( message ), "Ver: %s %s (build %i-%s, %s-%s)\n", len = Q_snprintf( message, sizeof( message ), "Ver: " XASH_ENGINE_NAME " " XASH_VERSION " (build %i-%s, %s-%s)\n",
XASH_ENGINE_NAME, XASH_VERSION, Q_buildnum(), Q_buildcommit(), Q_buildos(), Q_buildarch() ); Q_buildnum(), Q_buildcommit(), Q_buildos(), Q_buildarch() );
#if !XASH_BSD #if !XASH_BSD
len += Q_snprintf( message + len, sizeof( message ) - len, "Crash: signal %d errno %d with code %d at %p %p\n", signal, si->si_errno, si->si_code, si->si_addr, si->si_ptr ); len += Q_snprintf( message + len, sizeof( message ) - len, "Crash: signal %d errno %d with code %d at %p %p\n", signal, si->si_errno, si->si_code, si->si_addr, si->si_ptr );

2
engine/common/host.c

@ -1137,7 +1137,7 @@ int EXPORT Host_Main( int argc, char **argv, const char *progname, int bChangeGa
build = Cvar_Get( "buildnum", va( "%i", Q_buildnum_compat()), FCVAR_READ_ONLY, "returns a current build number" ); build = Cvar_Get( "buildnum", va( "%i", Q_buildnum_compat()), FCVAR_READ_ONLY, "returns a current build number" );
ver = Cvar_Get( "ver", va( "%i/%s (hw build %i)", PROTOCOL_VERSION, XASH_COMPAT_VERSION, Q_buildnum_compat()), FCVAR_READ_ONLY, "shows an engine version" ); ver = Cvar_Get( "ver", va( "%i/%s (hw build %i)", PROTOCOL_VERSION, XASH_COMPAT_VERSION, Q_buildnum_compat()), FCVAR_READ_ONLY, "shows an engine version" );
Cvar_Get( "host_ver", va( "%i %s %s %s %s", Q_buildnum(), XASH_VERSION, Q_buildos(), Q_buildarch(), Q_buildcommit() ), FCVAR_READ_ONLY, "detailed info about this build" ); Cvar_Get( "host_ver", va( "%i " XASH_VERSION " %s %s %s", Q_buildnum(), Q_buildos(), Q_buildarch(), Q_buildcommit() ), FCVAR_READ_ONLY, "detailed info about this build" );
Cvar_Get( "host_lowmemorymode", va( "%i", XASH_LOW_MEMORY ), FCVAR_READ_ONLY, "indicates if engine compiled for low RAM consumption (0 - normal, 1 - low engine limits, 2 - low protocol limits)" ); Cvar_Get( "host_lowmemorymode", va( "%i", XASH_LOW_MEMORY ), FCVAR_READ_ONLY, "indicates if engine compiled for low RAM consumption (0 - normal, 1 - low engine limits, 2 - low protocol limits)" );
Mod_Init(); Mod_Init();

30
engine/common/net_ws.c

@ -700,20 +700,23 @@ NET_AdrToString
*/ */
const char *NET_AdrToString( const netadr_t a ) const char *NET_AdrToString( const netadr_t a )
{ {
static char s[64];
if( a.type == NA_LOOPBACK ) if( a.type == NA_LOOPBACK )
return "loopback"; return "loopback";
if( a.type6 == NA_IP6 ) if( a.type6 == NA_IP6 )
{ {
char s[64];
uint8_t ip6[16]; uint8_t ip6[16];
NET_NetadrToIP6Bytes( ip6, &a ); NET_NetadrToIP6Bytes( ip6, &a );
IPv6AddrToString( s, ip6, ntohs( a.port ), 0 ); IPv6AddrToString( s, ip6, ntohs( a.port ), 0 );
return va( "%s", s ); return s;
} }
return va( "%i.%i.%i.%i:%i", a.ip[0], a.ip[1], a.ip[2], a.ip[3], ntohs( a.port )); Q_sprintf( s, "%i.%i.%i.%i:%i", a.ip[0], a.ip[1], a.ip[2], a.ip[3], ntohs( a.port ));
return s;
} }
/* /*
@ -723,19 +726,23 @@ NET_BaseAdrToString
*/ */
const char *NET_BaseAdrToString( const netadr_t a ) const char *NET_BaseAdrToString( const netadr_t a )
{ {
static char s[64];
if( a.type == NA_LOOPBACK ) if( a.type == NA_LOOPBACK )
return "loopback"; return "loopback";
if( a.type6 == NA_IP6 ) if( a.type6 == NA_IP6 )
{ {
char s[64];
uint8_t ip6[16]; uint8_t ip6[16];
NET_NetadrToIP6Bytes( ip6, &a ); NET_NetadrToIP6Bytes( ip6, &a );
IPv6IPToString( s, ip6 ); IPv6IPToString( s, ip6 );
return va( "%s", s ); return s;
} }
return va( "%i.%i.%i.%i", a.ip[0], a.ip[1], a.ip[2], a.ip[3] );
Q_sprintf( s, "%i.%i.%i.%i", a.ip[0], a.ip[1], a.ip[2], a.ip[3] );
return s;
} }
/* /*
@ -1868,6 +1875,7 @@ void NET_GetLocalAddress( void )
char buff[512]; char buff[512];
struct sockaddr_storage address; struct sockaddr_storage address;
WSAsize_t namelen; WSAsize_t namelen;
const char *net_addr_string;
memset( &net_local, 0, sizeof( netadr_t )); memset( &net_local, 0, sizeof( netadr_t ));
memset( &net6_local, 0, sizeof( netadr_t )); memset( &net6_local, 0, sizeof( netadr_t ));
@ -1895,8 +1903,9 @@ void NET_GetLocalAddress( void )
if( !NET_IsSocketError( getsockname( net.ip_sockets[NS_SERVER], (struct sockaddr *)&address, &namelen ))) if( !NET_IsSocketError( getsockname( net.ip_sockets[NS_SERVER], (struct sockaddr *)&address, &namelen )))
{ {
net_local.port = ((struct sockaddr_in *)&address)->sin_port; net_local.port = ((struct sockaddr_in *)&address)->sin_port;
Con_Printf( "Server IPv4 address %s\n", NET_AdrToString( net_local )); net_addr_string = NET_AdrToString( net_local );
Cvar_FullSet( "net_address", va( "%s", NET_AdrToString( net_local )), net_address->flags ); Con_Printf( "Server IPv4 address %s\n", net_addr_string );
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( ));
} }
@ -1917,8 +1926,9 @@ void NET_GetLocalAddress( void )
if( !NET_IsSocketError( getsockname( net.ip6_sockets[NS_SERVER], (struct sockaddr *)&address, &namelen ))) if( !NET_IsSocketError( getsockname( net.ip6_sockets[NS_SERVER], (struct sockaddr *)&address, &namelen )))
{ {
net6_local.port = ((struct sockaddr_in6 *)&address)->sin6_port; net6_local.port = ((struct sockaddr_in6 *)&address)->sin6_port;
Con_Printf( "Server IPv6 address %s\n", NET_AdrToString( net6_local )); net_addr_string = NET_AdrToString( net6_local );
Cvar_FullSet( "net6_address", va( "%s", NET_AdrToString( net6_local )), net6_address->flags ); Con_Printf( "Server IPv6 address %s\n", net_addr_string );
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( ));
} }

Loading…
Cancel
Save