From ae5257c65400ee493c3a98bf1022785c07769ac2 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Fri, 1 Jun 2018 20:44:16 +0300 Subject: [PATCH] Add masterlist from engine. Use non-blocking network name resolution --- contib/a1batross/xash3d.files | 1 + engine/client/cl_main.c | 51 +++++-- engine/client/cl_mobile.c | 2 +- engine/client/client.h | 2 + engine/client/in_evdev.c | 2 +- engine/client/in_touch.c | 16 +-- engine/client/vid_common.c | 2 +- engine/common/common.h | 7 + engine/common/con_utils.c | 2 + engine/common/host.c | 1 + engine/common/masterlist.c | 256 ++++++++++++++++++++++++++++++++++ engine/common/net_ws.h | 3 +- engine/common/netchan.h | 1 + 13 files changed, 321 insertions(+), 25 deletions(-) create mode 100644 engine/common/masterlist.c diff --git a/contib/a1batross/xash3d.files b/contib/a1batross/xash3d.files index 3a145cd8..17423cc6 100644 --- a/contib/a1batross/xash3d.files +++ b/contib/a1batross/xash3d.files @@ -146,6 +146,7 @@ engine/common/library.h engine/common/mathlib.c engine/common/mathlib.h engine/common/matrixlib.c +engine/common/masterlist.c engine/common/mod_bmodel.c engine/common/mod_local.h engine/common/mod_studio.c diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index 93bd18b1..c3a60036 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -1020,6 +1020,10 @@ Resend a connect message if the last one has timed out void CL_CheckForResend( void ) { netadr_t adr; + int res; + + if( cls.internetservers_wait ) + CL_InternetServers_f(); // if the local server is running and we aren't then connect if( cls.state == ca_disconnected && SV_Active( )) @@ -1044,13 +1048,21 @@ void CL_CheckForResend( void ) if(( host.realtime - cls.connect_time ) < cl_resend.value ) return; - if( !NET_StringToAdr( cls.servername, &adr )) + res = NET_StringToAdrNB( cls.servername, &adr ); + + if( !res ) { MsgDev( D_ERROR, "CL_CheckForResend: bad server address\n" ); CL_Disconnect(); return; } + if( res == 2 ) + { + cls.connect_time = MAX_HEARTBEAT; + return; + } + // only retry so many times before failure. if( cls.connect_retry >= CL_CONNECTION_RETRIES ) { @@ -1424,6 +1436,8 @@ 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_InternetServers_f @@ -1431,23 +1445,28 @@ CL_InternetServers_f */ void CL_InternetServers_f( void ) { - netadr_t adr; - char fullquery[512] = "1\xFF" "0.0.0.0:0\0" "\\gamedir\\"; + char fullquery[512] = MS_SCAN_REQUEST; + char *info = fullquery + sizeof( MS_SCAN_REQUEST ) - 1; + const size_t remaining = sizeof( fullquery ) - sizeof( MS_SCAN_REQUEST ); - Con_Printf( "Scanning for servers on the internet area...\n" ); - NET_Config( true ); // allow remote + // Info_SetValueForKey( info, "nat", cl_nat->string, remaining ); + Info_SetValueForKey( info, "gamedir", GI->gamefolder, remaining ); - if( !NET_StringToAdr( MASTERSERVER_ADR, &adr ) ) - MsgDev( D_ERROR, "Can't resolve adr: %s\n", MASTERSERVER_ADR ); + // let master know about client version + Info_SetValueForKey( info, "clver", XASH_VERSION, remaining ); - Q_strcpy( &fullquery[22], GI->gamefolder ); + NET_Config( true ); // allow remote - NET_SendPacket( NS_CLIENT, Q_strlen( GI->gamefolder ) + 23, fullquery, adr ); + cls.internetservers_wait = NET_SendToMasters( NS_CLIENT, sizeof( MS_SCAN_REQUEST ) + Q_strlen( info ), fullquery ); + cls.internetservers_pending = true; - // now we clearing the vgui request - if( clgame.master_request != NULL ) - memset( clgame.master_request, 0, sizeof( net_request_t )); - clgame.request_type = NET_REQUEST_GAMEUI; + if( !cls.internetservers_wait ) + { + // now we clearing the vgui request + if( clgame.master_request != NULL ) + memset( clgame.master_request, 0, sizeof( net_request_t )); + clgame.request_type = NET_REQUEST_GAMEUI; + } } /* @@ -1907,6 +1926,12 @@ void CL_ConnectionlessPacket( netadr_t from, sizebuf_t *msg ) Netchan_OutOfBandPrint( NS_CLIENT, servadr, "info %i", PROTOCOL_VERSION ); } } + + if( cls.internetservers_pending ) + { + Cbuf_AddText( "menu_resetping\n" ); // TODO: New Menu API + cls.internetservers_pending = false; + } } else if( clgame.dllFuncs.pfnConnectionlessPacket( &from, args, buf, &len )) { diff --git a/engine/client/cl_mobile.c b/engine/client/cl_mobile.c index d3dd0286..c58598a5 100644 --- a/engine/client/cl_mobile.c +++ b/engine/client/cl_mobile.c @@ -54,7 +54,7 @@ static void Vibrate_f() { if( Cmd_Argc() != 2 ) { - Msg( "Usage: vibrate