- fix typo in previous commit to net_ip.c

- Make servers send heartbeats to master servers in ipv4 as well as ipv6 if master server has both protocols
This commit is contained in:
Thilo Schulz 2009-06-23 00:59:47 +00:00
parent 78254a626f
commit 948f7a6015
2 changed files with 58 additions and 23 deletions

View file

@ -285,7 +285,7 @@ static qboolean Sys_StringToSockaddr(const char *s, struct sockaddr *sadr, int s
if(family == AF_UNSPEC) if(family == AF_UNSPEC)
{ {
// Decide here and now which protocol family to use // Decide here and now which protocol family to use
if((net_enabled->integer & NET_PRIOV6) if(net_enabled->integer & NET_PRIOV6)
{ {
if(net_enabled->integer & NET_ENABLEV6) if(net_enabled->integer & NET_ENABLEV6)
search = SearchAddrInfo(res, AF_INET6); search = SearchAddrInfo(res, AF_INET6);

View file

@ -234,56 +234,91 @@ but not on every player enter or exit.
#define HEARTBEAT_MSEC 300*1000 #define HEARTBEAT_MSEC 300*1000
#define HEARTBEAT_GAME "QuakeArena-1" #define HEARTBEAT_GAME "QuakeArena-1"
void SV_MasterHeartbeat( void ) { void SV_MasterHeartbeat( void ) {
static netadr_t adr[MAX_MASTER_SERVERS]; static netadr_t adr[MAX_MASTER_SERVERS][2]; // [2] for v4 and v6 address for the same address string.
int i; int i;
int res; int res;
int netenabled;
netenabled = Cvar_VariableIntegerValue("net_enabled");
// "dedicated 1" is for lan play, "dedicated 2" is for inet public play // "dedicated 1" is for lan play, "dedicated 2" is for inet public play
if ( !com_dedicated || com_dedicated->integer != 2 ) { if (!com_dedicated || com_dedicated->integer != 2 || !(netenabled & (NET_ENABLEV4 | NET_ENABLEV6)))
return; // only dedicated servers send heartbeats return; // only dedicated servers send heartbeats
}
// if not time yet, don't send anything // if not time yet, don't send anything
if ( svs.time < svs.nextHeartbeatTime ) { if ( svs.time < svs.nextHeartbeatTime )
return; return;
}
svs.nextHeartbeatTime = svs.time + HEARTBEAT_MSEC; svs.nextHeartbeatTime = svs.time + HEARTBEAT_MSEC;
// send to group masters // send to group masters
for ( i = 0 ; i < MAX_MASTER_SERVERS ; i++ ) { for (i = 0; i < MAX_MASTER_SERVERS; i++)
if ( !sv_master[i]->string[0] ) { {
if(!sv_master[i]->string[0])
continue; continue;
}
// see if we haven't already resolved the name // see if we haven't already resolved the name
// resolving usually causes hitches on win95, so only // resolving usually causes hitches on win95, so only
// do it when needed // do it when needed
if ( sv_master[i]->modified ) { if(sv_master[i]->modified || (adr[i][0].type == NA_BAD && adr[i][1].type == NA_BAD))
{
sv_master[i]->modified = qfalse; sv_master[i]->modified = qfalse;
Com_Printf( "Resolving %s\n", sv_master[i]->string ); if(netenabled & NET_ENABLEV4)
res = NET_StringToAdr( sv_master[i]->string, &adr[i], NA_UNSPEC ); {
if ( !res ) { Com_Printf("Resolving %s (IPv4)\n", sv_master[i]->string);
res = NET_StringToAdr(sv_master[i]->string, &adr[i][0], NA_IP);
if(res == 2)
{
// if no port was specified, use the default master port
adr[i][0].port = BigShort(PORT_MASTER);
}
if(res)
Com_Printf( "%s resolved to %s\n", sv_master[i]->string, NET_AdrToStringwPort(adr[i][0]));
else
Com_Printf( "%s has no IPv4 address.\n", sv_master[i]->string);
}
if(netenabled & NET_ENABLEV6)
{
Com_Printf("Resolving %s (IPv6)\n", sv_master[i]->string);
res = NET_StringToAdr(sv_master[i]->string, &adr[i][1], NA_IP6);
if(res == 2)
{
// if no port was specified, use the default master port
adr[i][1].port = BigShort(PORT_MASTER);
}
if(res)
Com_Printf( "%s resolved to %s\n", sv_master[i]->string, NET_AdrToStringwPort(adr[i][1]));
else
Com_Printf( "%s has no IPv6 address.\n", sv_master[i]->string);
}
if(adr[i][0].type == NA_BAD && adr[i][1].type == NA_BAD)
{
// if the address failed to resolve, clear it // if the address failed to resolve, clear it
// so we don't take repeated dns hits // so we don't take repeated dns hits
Com_Printf( "Couldn't resolve address: %s\n", sv_master[i]->string ); Com_Printf("Couldn't resolve address: %s\n", sv_master[i]->string);
Cvar_Set( sv_master[i]->name, "" ); Cvar_Set(sv_master[i]->name, "");
sv_master[i]->modified = qfalse; sv_master[i]->modified = qfalse;
continue; continue;
} }
if ( res == 2 ) {
// if no port was specified, use the default master port
adr[i].port = BigShort( PORT_MASTER );
}
Com_Printf( "%s resolved to %s\n", sv_master[i]->string, NET_AdrToStringwPort(adr[i]));
} }
Com_Printf ("Sending heartbeat to %s\n", sv_master[i]->string ); Com_Printf ("Sending heartbeat to %s\n", sv_master[i]->string );
// this command should be changed if the server info / status format // this command should be changed if the server info / status format
// ever incompatably changes // ever incompatably changes
NET_OutOfBandPrint( NS_SERVER, adr[i], "heartbeat %s\n", HEARTBEAT_GAME );
if(adr[i][0].type != NA_BAD)
NET_OutOfBandPrint( NS_SERVER, adr[i][0], "heartbeat %s\n", HEARTBEAT_GAME );
if(adr[i][1].type != NA_BAD)
NET_OutOfBandPrint( NS_SERVER, adr[i][1], "heartbeat %s\n", HEARTBEAT_GAME );
} }
} }