Browse Source

engine: client: streamline constructing master server scan request through common function

pull/2/head
Alibek Omarov 2 years ago
parent
commit
9cbf5ab6a6
  1. 9
      engine/client/cl_game.c
  2. 42
      engine/client/cl_main.c
  3. 1
      engine/client/client.h
  4. 3
      engine/common/protocol.h

9
engine/client/cl_game.c

@ -3401,9 +3401,12 @@ void GAME_EXPORT NetAPI_SendRequest( int context, int request, int flags, double @@ -3401,9 +3401,12 @@ void GAME_EXPORT NetAPI_SendRequest( int context, int request, int flags, double
if( request == NETAPI_REQUEST_SERVERLIST )
{
char fullquery[512] = "1\xFF" "0.0.0.0:0\0" "\\gamedir\\";
char fullquery[512];
size_t len;
// make sure what port is specified
len = CL_BuildMasterServerScanRequest( fullquery, sizeof( fullquery ), false );
// make sure that port is specified
if( !nr->resp.remote_address.port )
nr->resp.remote_address.port = MSG_BigShort( PORT_MASTER );
@ -3431,7 +3434,7 @@ void GAME_EXPORT NetAPI_CancelRequest( int context ) @@ -3431,7 +3434,7 @@ void GAME_EXPORT NetAPI_CancelRequest( int context )
{
net_request_t *nr;
int i;
;
// find a specified request
for( i = 0; i < MAX_REQUESTS; i++ )
{

42
engine/client/cl_main.c

@ -1584,7 +1584,32 @@ void CL_LocalServers_f( void ) @@ -1584,7 +1584,32 @@ void CL_LocalServers_f( void )
Netchan_OutOfBandPrint( NS_CLIENT, adr, "info %i", PROTOCOL_VERSION );
}
#define MS_SCAN_REQUEST "1\xFF" "0.0.0.0:0\0"
/*
=================
CL_BuildMasterServerScanRequest
=================
*/
size_t CL_BuildMasterServerScanRequest( char *buf, size_t size, qboolean nat )
{
size_t remaining;
char *info;
if( unlikely( size < sizeof( MS_SCAN_REQUEST )))
return 0;
Q_strncpy( buf, MS_SCAN_REQUEST, size );
info = buf + sizeof( MS_SCAN_REQUEST ) - 1;
remaining = size - sizeof( MS_SCAN_REQUEST );
info[0] = 0;
Info_SetValueForKey( info, "gamedir", GI->gamefolder, remaining );
Info_SetValueForKey( info, "clver", XASH_VERSION, remaining ); // let master know about client version
Info_SetValueForKey( info, "nat", nat ? "1" : "0", remaining );
return sizeof( MS_SCAN_REQUEST ) + Q_strlen( info );
}
/*
=================
@ -1593,18 +1618,17 @@ CL_InternetServers_f @@ -1593,18 +1618,17 @@ CL_InternetServers_f
*/
void CL_InternetServers_f( void )
{
char fullquery[512] = MS_SCAN_REQUEST;
char *info = fullquery + sizeof( MS_SCAN_REQUEST ) - 1;
const size_t remaining = sizeof( fullquery ) - sizeof( MS_SCAN_REQUEST );
char fullquery[512];
size_t len;
qboolean nat = cl_nat->value != 0.0f;
NET_Config( true, true ); // allow remote
len = CL_BuildMasterServerScanRequest( fullquery, sizeof( fullquery ), nat );
Con_Printf( "Scanning for servers on the internet area...\n" );
Info_SetValueForKey( info, "gamedir", GI->gamefolder, remaining );
Info_SetValueForKey( info, "clver", XASH_VERSION, remaining ); // let master know about client version
Info_SetValueForKey( info, "nat", cl_nat->string, remaining );
cls.internetservers_wait = NET_SendToMasters( NS_CLIENT, sizeof( MS_SCAN_REQUEST ) + Q_strlen( info ), fullquery );
NET_Config( true, true ); // allow remote
cls.internetservers_wait = NET_SendToMasters( NS_CLIENT, len, fullquery );
cls.internetservers_pending = true;
if( !cls.internetservers_wait )

1
engine/client/client.h

@ -754,6 +754,7 @@ int CL_IsDevOverviewMode( void ); @@ -754,6 +754,7 @@ int CL_IsDevOverviewMode( void );
void CL_PingServers_f( void );
void CL_SignonReply( void );
void CL_ClearState( void );
size_t CL_BuildMasterServerScanRequest( char *buf, size_t size, qboolean nat );
//
// cl_demo.c

3
engine/common/protocol.h

@ -302,4 +302,7 @@ extern const char *clc_strings[clc_lastmsg+1]; @@ -302,4 +302,7 @@ extern const char *clc_strings[clc_lastmsg+1];
#define MAX_LEGACY_TOTAL_CMDS 16 // 28 - 16 = 12 real legacy max backup
#define MAX_LEGACY_BACKUP_CMDS 12
// Master Server protocol
#define MS_SCAN_REQUEST "1\xFF" "0.0.0.0:0\0" // TODO: implement IP filter
#endif//NET_PROTOCOL_H

Loading…
Cancel
Save