Skip to content

Commit

Permalink
Added support for GameSpy heartbeat
Browse files Browse the repository at this point in the history
  • Loading branch information
L committed Feb 5, 2023
1 parent 64520b9 commit 7f7faea
Showing 1 changed file with 7 additions and 48 deletions.
55 changes: 7 additions & 48 deletions code/server/sv_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ cvar_t *g_gametypestring;
cvar_t *sv_chatter;
cvar_t *sv_gamename;
cvar_t *sv_location;
cvar_t *sv_debug_gamespy;
cvar_t *sv_gamespy;

// FIXME: use another global network ?
//cvar_t *sv_debug_gamepsy;
Expand Down Expand Up @@ -232,58 +234,15 @@ changes from empty to non-empty, and full to non-full,
but not on every player enter or exit.
================
*/
#define HEARTBEAT_MSEC 300*1000
#define HEARTBEAT_GAME "mohaa-1"
void SV_MasterHeartbeat( void ) {
static netadr_t adr[MAX_MASTER_SERVERS];
int i;

// "dedicated 1" is for lan play, "dedicated 2" is for inet public play
if ( !com_dedicated || com_dedicated->integer != 2 ) {
return; // only dedicated servers send heartbeats
}

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


// send to group masters
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 ) {
sv_master[i]->modified = qfalse;

Com_Printf( "Resolving %s\n", sv_master[i]->string );
if ( !NET_StringToAdr( sv_master[i]->string, &adr[i] ) ) {
// 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, "" );
sv_master[i]->modified = qfalse;
continue;
}
if ( !strchr( sv_master[i]->string, ':' ) ) {
adr[i].port = BigShort( PORT_MASTER );
}
Com_Printf( "%s resolved to %i.%i.%i.%i:%i\n", sv_master[i]->string,
adr[i].ip[0], adr[i].ip[1], adr[i].ip[2], adr[i].ip[3],
BigShort( adr[i].port ) );
}


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 (svs.time >= svs.nextHeartbeatTime)
{
svs.nextHeartbeatTime = svs.time + 300000;
SV_GamespyHeartbeat();
}
}

Expand Down

0 comments on commit 7f7faea

Please sign in to comment.