Skip to content

Commit

Permalink
- fix typo in previous commit to net_ip.c
Browse files Browse the repository at this point in the history
- Make servers send heartbeats to master servers in ipv4 as well as ipv6 if master server has both protocols
  • Loading branch information
Thilo Schulz committed Jun 23, 2009
1 parent 78254a6 commit 948f7a6
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 23 deletions.
2 changes: 1 addition & 1 deletion code/qcommon/net_ip.c
Expand Up @@ -285,7 +285,7 @@ static qboolean Sys_StringToSockaddr(const char *s, struct sockaddr *sadr, int s
if(family == AF_UNSPEC)
{
// 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)
search = SearchAddrInfo(res, AF_INET6);
Expand Down
79 changes: 57 additions & 22 deletions code/server/sv_main.c
Expand Up @@ -234,56 +234,91 @@ but not on every player enter or exit.
#define HEARTBEAT_MSEC 300*1000
#define HEARTBEAT_GAME "QuakeArena-1"
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 res;
int netenabled;

netenabled = Cvar_VariableIntegerValue("net_enabled");

// "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
}

// if not time yet, don't send anything
if ( svs.time < svs.nextHeartbeatTime ) {
if ( svs.time < svs.nextHeartbeatTime )
return;
}
svs.nextHeartbeatTime = svs.time + HEARTBEAT_MSEC;

svs.nextHeartbeatTime = svs.time + HEARTBEAT_MSEC;

// send to group masters
for ( i = 0 ; i < MAX_MASTER_SERVERS ; i++ ) {
if ( !sv_master[i]->string[0] ) {
for (i = 0; i < MAX_MASTER_SERVERS; i++)
{
if(!sv_master[i]->string[0])
continue;
}

// see if we haven't already resolved the name
// resolving usually causes hitches on win95, so only
// 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;

Com_Printf( "Resolving %s\n", sv_master[i]->string );
res = NET_StringToAdr( sv_master[i]->string, &adr[i], NA_UNSPEC );
if ( !res ) {

if(netenabled & NET_ENABLEV4)
{
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
// so we don't take repeated dns hits
Com_Printf( "Couldn't resolve address: %s\n", sv_master[i]->string );
Cvar_Set( sv_master[i]->name, "" );
Com_Printf("Couldn't resolve address: %s\n", sv_master[i]->string);
Cvar_Set(sv_master[i]->name, "");
sv_master[i]->modified = qfalse;
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 );

// this command should be changed if the server info / status format
// 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 );
}
}

Expand Down

0 comments on commit 948f7a6

Please sign in to comment.