|
|
@ -18,8 +18,6 @@ GNU General Public License for more details. |
|
|
|
#include "net_encode.h" |
|
|
|
#include "net_encode.h" |
|
|
|
#include "platform/platform.h" |
|
|
|
#include "platform/platform.h" |
|
|
|
|
|
|
|
|
|
|
|
#define HEARTBEAT_SECONDS ((sv_nat.value > 0.0f) ? 60.0f : 300.0f) // 1 or 5 minutes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// server cvars
|
|
|
|
// server cvars
|
|
|
|
CVAR_DEFINE_AUTO( sv_lan, "0", 0, "server is a lan server ( no heartbeat, no authentication, no non-class C addresses, 9999.0 rate, etc." ); |
|
|
|
CVAR_DEFINE_AUTO( sv_lan, "0", 0, "server is a lan server ( no heartbeat, no authentication, no non-class C addresses, 9999.0 rate, etc." ); |
|
|
|
CVAR_DEFINE_AUTO( sv_lan_rate, "20000.0", 0, "rate for lan server" ); |
|
|
|
CVAR_DEFINE_AUTO( sv_lan_rate, "20000.0", 0, "rate for lan server" ); |
|
|
@ -142,8 +140,6 @@ convar_t *sv_allow_mouse; |
|
|
|
convar_t *sv_allow_joystick; |
|
|
|
convar_t *sv_allow_joystick; |
|
|
|
convar_t *sv_allow_vr; |
|
|
|
convar_t *sv_allow_vr; |
|
|
|
|
|
|
|
|
|
|
|
static void Master_Heartbeat( void ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//============================================================================
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
================ |
|
|
|
================ |
|
|
@ -668,7 +664,7 @@ void Host_ServerFrame( void ) |
|
|
|
Platform_UpdateStatusLine (); |
|
|
|
Platform_UpdateStatusLine (); |
|
|
|
|
|
|
|
|
|
|
|
// send a heartbeat to the master if needed
|
|
|
|
// send a heartbeat to the master if needed
|
|
|
|
Master_Heartbeat (); |
|
|
|
NET_MasterHeartbeat (); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
@ -683,68 +679,6 @@ void Host_SetServerState( int state ) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
================= |
|
|
|
|
|
|
|
Master_Add |
|
|
|
|
|
|
|
================= |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
static void Master_Add( void ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
sizebuf_t msg; |
|
|
|
|
|
|
|
char buf[16]; |
|
|
|
|
|
|
|
uint challenge; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NET_Config( true, false ); // allow remote
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
svs.heartbeat_challenge = challenge = COM_RandomLong( 0, INT_MAX ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MSG_Init( &msg, "Master Join", buf, sizeof( buf )); |
|
|
|
|
|
|
|
MSG_WriteBytes( &msg, "q\xFF", 2 ); |
|
|
|
|
|
|
|
MSG_WriteDword( &msg, challenge ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( NET_SendToMasters( NS_SERVER, MSG_GetNumBytesWritten( &msg ), MSG_GetBuf( &msg ))) |
|
|
|
|
|
|
|
svs.last_heartbeat = MAX_HEARTBEAT; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
================ |
|
|
|
|
|
|
|
Master_Heartbeat |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Send a message to the master every few minutes to |
|
|
|
|
|
|
|
let it know we are alive, and log information |
|
|
|
|
|
|
|
================ |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
static void Master_Heartbeat( void ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if(( !public_server.value && !sv_nat.value ) || svs.maxclients == 1 ) |
|
|
|
|
|
|
|
return; // only public servers send heartbeats
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// check for time wraparound
|
|
|
|
|
|
|
|
if( svs.last_heartbeat > host.realtime ) |
|
|
|
|
|
|
|
svs.last_heartbeat = host.realtime; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(( host.realtime - svs.last_heartbeat ) < HEARTBEAT_SECONDS ) |
|
|
|
|
|
|
|
return; // not time to send yet
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
svs.last_heartbeat = host.realtime; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Master_Add(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
================= |
|
|
|
|
|
|
|
Master_Shutdown |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Informs all masters that this server is going down |
|
|
|
|
|
|
|
================= |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
static void Master_Shutdown( void ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
NET_Config( true, false ); // allow remote
|
|
|
|
|
|
|
|
while( NET_SendToMasters( NS_SERVER, 2, "\x62\x0A" )); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
================= |
|
|
|
================= |
|
|
|
SV_AddToMaster |
|
|
|
SV_AddToMaster |
|
|
@ -755,18 +689,19 @@ Master will validate challenge and this server to public list |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void SV_AddToMaster( netadr_t from, sizebuf_t *msg ) |
|
|
|
void SV_AddToMaster( netadr_t from, sizebuf_t *msg ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
uint challenge, challenge2; |
|
|
|
uint challenge, challenge2, heartbeat_challenge; |
|
|
|
char s[MAX_INFO_STRING] = "0\n"; // skip 2 bytes of header
|
|
|
|
char s[MAX_INFO_STRING] = "0\n"; // skip 2 bytes of header
|
|
|
|
int clients, bots; |
|
|
|
int clients, bots; |
|
|
|
|
|
|
|
double last_heartbeat; |
|
|
|
const int len = sizeof( s ); |
|
|
|
const int len = sizeof( s ); |
|
|
|
|
|
|
|
|
|
|
|
if( !NET_IsMasterAdr( from )) |
|
|
|
if( !NET_GetMaster( from, &heartbeat_challenge, &last_heartbeat )) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Con_Printf( S_WARN "unexpected master server info query packet from %s\n", NET_AdrToString( from )); |
|
|
|
Con_Printf( S_WARN "unexpected master server info query packet from %s\n", NET_AdrToString( from )); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if( svs.last_heartbeat + sv_master_response_timeout.value < host.realtime ) |
|
|
|
if( last_heartbeat + sv_master_response_timeout.value < host.realtime ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Con_Printf( S_WARN "unexpected master server info query packet (too late? try increasing sv_master_response_timeout value)\n"); |
|
|
|
Con_Printf( S_WARN "unexpected master server info query packet (too late? try increasing sv_master_response_timeout value)\n"); |
|
|
|
return; |
|
|
|
return; |
|
|
@ -775,7 +710,7 @@ void SV_AddToMaster( netadr_t from, sizebuf_t *msg ) |
|
|
|
challenge = MSG_ReadDword( msg ); |
|
|
|
challenge = MSG_ReadDword( msg ); |
|
|
|
challenge2 = MSG_ReadDword( msg ); |
|
|
|
challenge2 = MSG_ReadDword( msg ); |
|
|
|
|
|
|
|
|
|
|
|
if( challenge2 != svs.heartbeat_challenge ) |
|
|
|
if( challenge2 != heartbeat_challenge ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Con_Printf( S_WARN "unexpected master server info query packet (wrong challenge!)\n" ); |
|
|
|
Con_Printf( S_WARN "unexpected master server info query packet (wrong challenge!)\n" ); |
|
|
|
return; |
|
|
|
return; |
|
|
@ -1114,7 +1049,7 @@ void SV_Shutdown( const char *finalmsg ) |
|
|
|
SV_FinalMessage( finalmsg, false ); |
|
|
|
SV_FinalMessage( finalmsg, false ); |
|
|
|
|
|
|
|
|
|
|
|
if( public_server.value && svs.maxclients != 1 ) |
|
|
|
if( public_server.value && svs.maxclients != 1 ) |
|
|
|
Master_Shutdown(); |
|
|
|
NET_MasterShutdown(); |
|
|
|
|
|
|
|
|
|
|
|
NET_Config( false, false ); |
|
|
|
NET_Config( false, false ); |
|
|
|
SV_UnloadProgs (); |
|
|
|
SV_UnloadProgs (); |
|
|
|