mirror of
https://github.com/YGGverse/xash3d-fwgs.git
synced 2025-01-18 02:50:33 +00:00
engine: client: streamline constructing master server scan request through common function
This commit is contained in:
parent
c9e4e62474
commit
9cbf5ab6a6
@ -3401,9 +3401,12 @@ void GAME_EXPORT NetAPI_SendRequest( int context, int request, int flags, double
|
|||||||
|
|
||||||
if( request == NETAPI_REQUEST_SERVERLIST )
|
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 )
|
if( !nr->resp.remote_address.port )
|
||||||
nr->resp.remote_address.port = MSG_BigShort( PORT_MASTER );
|
nr->resp.remote_address.port = MSG_BigShort( PORT_MASTER );
|
||||||
|
|
||||||
@ -3431,7 +3434,7 @@ void GAME_EXPORT NetAPI_CancelRequest( int context )
|
|||||||
{
|
{
|
||||||
net_request_t *nr;
|
net_request_t *nr;
|
||||||
int i;
|
int i;
|
||||||
|
;
|
||||||
// find a specified request
|
// find a specified request
|
||||||
for( i = 0; i < MAX_REQUESTS; i++ )
|
for( i = 0; i < MAX_REQUESTS; i++ )
|
||||||
{
|
{
|
||||||
|
@ -1584,7 +1584,32 @@ void CL_LocalServers_f( void )
|
|||||||
Netchan_OutOfBandPrint( NS_CLIENT, adr, "info %i", PROTOCOL_VERSION );
|
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
|
|||||||
*/
|
*/
|
||||||
void CL_InternetServers_f( void )
|
void CL_InternetServers_f( void )
|
||||||
{
|
{
|
||||||
char fullquery[512] = MS_SCAN_REQUEST;
|
char fullquery[512];
|
||||||
char *info = fullquery + sizeof( MS_SCAN_REQUEST ) - 1;
|
size_t len;
|
||||||
const size_t remaining = sizeof( fullquery ) - sizeof( MS_SCAN_REQUEST );
|
qboolean nat = cl_nat->value != 0.0f;
|
||||||
|
|
||||||
|
len = CL_BuildMasterServerScanRequest( fullquery, sizeof( fullquery ), nat );
|
||||||
|
|
||||||
|
Con_Printf( "Scanning for servers on the internet area...\n" );
|
||||||
|
|
||||||
NET_Config( true, true ); // allow remote
|
NET_Config( true, true ); // allow remote
|
||||||
|
|
||||||
Con_Printf( "Scanning for servers on the internet area...\n" );
|
cls.internetservers_wait = NET_SendToMasters( NS_CLIENT, len, fullquery );
|
||||||
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 );
|
|
||||||
cls.internetservers_pending = true;
|
cls.internetservers_pending = true;
|
||||||
|
|
||||||
if( !cls.internetservers_wait )
|
if( !cls.internetservers_wait )
|
||||||
|
@ -754,6 +754,7 @@ int CL_IsDevOverviewMode( void );
|
|||||||
void CL_PingServers_f( void );
|
void CL_PingServers_f( void );
|
||||||
void CL_SignonReply( void );
|
void CL_SignonReply( void );
|
||||||
void CL_ClearState( void );
|
void CL_ClearState( void );
|
||||||
|
size_t CL_BuildMasterServerScanRequest( char *buf, size_t size, qboolean nat );
|
||||||
|
|
||||||
//
|
//
|
||||||
// cl_demo.c
|
// cl_demo.c
|
||||||
|
@ -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_TOTAL_CMDS 16 // 28 - 16 = 12 real legacy max backup
|
||||||
#define MAX_LEGACY_BACKUP_CMDS 12
|
#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
|
#endif//NET_PROTOCOL_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user