[iortcw] 67/152: All: Always resolve IP of master when sending heartbeats

Simon McVittie smcv at debian.org
Fri Sep 8 10:40:03 UTC 2017


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to annotated tag 1.5a
in repository iortcw.

commit db9b62bc8b4abd8f72eeb3ed85ea17e07574f957
Author: MAN-AT-ARMS <M4N4T4RMS at gmail.com>
Date:   Sun Jun 5 15:29:38 2016 -0400

    All: Always resolve IP of master when sending heartbeats
---
 MP/code/server/sv_main.c | 220 +++++++++++++++++++++++------------------------
 SP/code/server/sv_main.c | 103 +++++++++++-----------
 2 files changed, 159 insertions(+), 164 deletions(-)

diff --git a/MP/code/server/sv_main.c b/MP/code/server/sv_main.c
index 4538ac5..189d738 100644
--- a/MP/code/server/sv_main.c
+++ b/MP/code/server/sv_main.c
@@ -241,14 +241,14 @@ but not on every player enter or exit.
 ================
 */
 #define HEARTBEAT_MSEC  300 * 1000
-
 void SV_MasterHeartbeat(const char *message)
 {
-	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;
+	netadr_t	adr[2]; // [2] for v4 and v6 address for the same address string.
+	int		i;
+	int		res;
+	int		netenabled;
 
+	Com_Memset(adr, 0, sizeof(netadr_t) * 2);
 	netenabled = Cvar_VariableIntegerValue("net_enabled");
 
 	// DHM - Nerve :: Update Server doesn't send heartbeat
@@ -258,10 +258,10 @@ void SV_MasterHeartbeat(const char *message)
 
 	// "dedicated 1" is for lan play, "dedicated 2" is for inet public play
 	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 ( svs.time < svs.nextHeartbeatTime ) 
+	if ( svs.time < svs.nextHeartbeatTime )
 		return;
 
 	if ( !Q_stricmp( com_gamename->string, LEGACY_MASTER_GAMENAME ) )
@@ -270,72 +270,68 @@ void SV_MasterHeartbeat(const char *message)
 	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 || (adr[i][0].type == NA_BAD && adr[i][1].type == NA_BAD))
+		// Enforce IP check everytime in case master moves to a new IP
+		sv_master[i]->modified = qfalse;
+
+		if(netenabled & NET_ENABLEV4)
 		{
-			sv_master[i]->modified = qfalse;
+			Com_Printf("Resolving %s (IPv4)\n", sv_master[i]->string);
+			res = NET_StringToAdr(sv_master[i]->string, &adr[0], NA_IP);
 
-			if(netenabled & NET_ENABLEV4)
+			if(res == 2)
 			{
-				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 no port was specified, use the default master port
+				adr[0].port = BigShort(PORT_MASTER);
 			}
-			
-			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(res)
+				Com_Printf( "%s resolved to %s\n", sv_master[i]->string, NET_AdrToStringwPort(adr[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[1], NA_IP6);
 
-			if(adr[i][0].type == NA_BAD && adr[i][1].type == NA_BAD)
+			if(res == 2)
 			{
-				// 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 no port was specified, use the default master port
+				adr[1].port = BigShort(PORT_MASTER);
 			}
+
+			if(res)
+				Com_Printf( "%s resolved to %s\n", sv_master[i]->string, NET_AdrToStringwPort(adr[1]));
+			else
+				Com_Printf( "%s has no IPv6 address.\n", sv_master[i]->string);
+		}
+
+		if(adr[0].type == NA_BAD && adr[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, "");
+			sv_master[i]->modified = qfalse;
+			continue;
 		}
 
 
-		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
 		// ever incompatably changes
 
-		if(adr[i][0].type != NA_BAD)
-			NET_OutOfBandPrint( NS_SERVER, adr[i][0], "heartbeat %s\n", message);
-		if(adr[i][1].type != NA_BAD)
-			NET_OutOfBandPrint( NS_SERVER, adr[i][1], "heartbeat %s\n", message);
+		if(adr[0].type != NA_BAD)
+			NET_OutOfBandPrint( NS_SERVER, adr[0], "heartbeat %s\n", message);
+		if(adr[1].type != NA_BAD)
+			NET_OutOfBandPrint( NS_SERVER, adr[1], "heartbeat %s\n", message);
 	}
 }
 
@@ -347,83 +343,85 @@ NERVE - SMF - Sends gameCompleteStatus messages to all master servers
 =================
 */
 void SV_MasterGameCompleteStatus() {
-	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;
+	netadr_t	adr[2]; // [2] for v4 and v6 address for the same address string.
+	int		i;
+	int		res;
+	int		netenabled;
 
+	Com_Memset(adr, 0, sizeof(netadr_t) * 2);
 	netenabled = Cvar_VariableIntegerValue("net_enabled");
 
+	// DHM - Nerve :: Update Server doesn't send gameCompleteStatus 
+#ifdef UPDATE_SERVER
+	return;
+#endif
+
 	// "dedicated 1" is for lan play, "dedicated 2" is for inet public play
 	if (!com_dedicated || com_dedicated->integer != 2 || !(netenabled & (NET_ENABLEV4 | NET_ENABLEV6)))
-		return;     // only dedicated servers send master game status
+		return;		// only dedicated servers send heartbeats
 
 	// 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 || (adr[i][0].type == NA_BAD && adr[i][1].type == NA_BAD))
+		// Enforce IP check everytime in case master moves to a new IP
+		sv_master[i]->modified = qfalse;
+
+		if(netenabled & NET_ENABLEV4)
 		{
-			sv_master[i]->modified = qfalse;
+			Com_Printf("Resolving %s (IPv4)\n", sv_master[i]->string);
+			res = NET_StringToAdr(sv_master[i]->string, &adr[0], NA_IP);
 
-			if(netenabled & NET_ENABLEV4)
+			if(res == 2)
 			{
-				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 no port was specified, use the default master port
+				adr[0].port = BigShort(PORT_MASTER);
 			}
-			
-			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(res)
+				Com_Printf( "%s resolved to %s\n", sv_master[i]->string, NET_AdrToStringwPort(adr[0]));
+			else
+				Com_Printf( "%s has no IPv4 address.\n", sv_master[i]->string);
+		}
 
-			if(adr[i][0].type == NA_BAD && adr[i][1].type == NA_BAD)
+		if(netenabled & NET_ENABLEV6)
+		{
+			Com_Printf("Resolving %s (IPv6)\n", sv_master[i]->string);
+			res = NET_StringToAdr(sv_master[i]->string, &adr[1], NA_IP6);
+
+			if(res == 2)
 			{
-				// 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 no port was specified, use the default master port
+				adr[1].port = BigShort(PORT_MASTER);
 			}
+
+			if(res)
+				Com_Printf( "%s resolved to %s\n", sv_master[i]->string, NET_AdrToStringwPort(adr[1]));
+			else
+				Com_Printf( "%s has no IPv6 address.\n", sv_master[i]->string);
 		}
 
+		if(adr[0].type == NA_BAD && adr[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, "");
+			sv_master[i]->modified = qfalse;
+			continue;
+		}
+
+
 		Com_Printf( "Sending gameCompleteStatus to %s\n", sv_master[i]->string );
 		// this command should be changed if the server info / status format
 		// ever incompatably changes
 
-		if(adr[i][0].type != NA_BAD)
-			SVC_GameCompleteStatus( adr[i][0] );
-		if(adr[i][1].type != NA_BAD)
-			SVC_GameCompleteStatus( adr[i][1] );
+		if(adr[0].type != NA_BAD)
+			SVC_GameCompleteStatus( adr[0] );
+		if(adr[1].type != NA_BAD)
+			SVC_GameCompleteStatus( adr[1] );
 	}
 }
 
diff --git a/SP/code/server/sv_main.c b/SP/code/server/sv_main.c
index 9ff522d..c478a54 100644
--- a/SP/code/server/sv_main.c
+++ b/SP/code/server/sv_main.c
@@ -253,16 +253,17 @@ but not on every player enter or exit.
 #define HEARTBEAT_MSEC  300 * 1000
 void SV_MasterHeartbeat(const char *message)
 {
-	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;
+	netadr_t	adr[2]; // [2] for v4 and v6 address for the same address string.
+	int		i;
+	int		res;
+	int		netenabled;
 
+	Com_Memset(adr, 0, sizeof(netadr_t) * 2);
 	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 || !(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 ( svs.time < svs.nextHeartbeatTime )
@@ -279,67 +280,63 @@ void SV_MasterHeartbeat(const char *message)
 		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 || (adr[i][0].type == NA_BAD && adr[i][1].type == NA_BAD))
+		// Enforce IP check everytime in case master moves to a new IP
+		sv_master[i]->modified = qfalse;
+
+		if(netenabled & NET_ENABLEV4)
 		{
-			sv_master[i]->modified = qfalse;
+			Com_Printf("Resolving %s (IPv4)\n", sv_master[i]->string);
+			res = NET_StringToAdr(sv_master[i]->string, &adr[0], NA_IP);
 
-			if(netenabled & NET_ENABLEV4)
+			if(res == 2)
 			{
-				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 no port was specified, use the default master port
+				adr[0].port = BigShort(PORT_MASTER);
 			}
-			
-			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(res)
+				Com_Printf( "%s resolved to %s\n", sv_master[i]->string, NET_AdrToStringwPort(adr[0]));
+			else
+				Com_Printf( "%s has no IPv4 address.\n", sv_master[i]->string);
+		}
 
-			if(adr[i][0].type == NA_BAD && adr[i][1].type == NA_BAD)
-			{
+		if(netenabled & NET_ENABLEV6)
+		{
+			Com_Printf("Resolving %s (IPv6)\n", sv_master[i]->string);
+			res = NET_StringToAdr(sv_master[i]->string, &adr[1], NA_IP6);
 
-				// 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(res == 2)
+			{
+				// if no port was specified, use the default master port
+				adr[1].port = BigShort(PORT_MASTER);
 			}
+
+			if(res)
+				Com_Printf( "%s resolved to %s\n", sv_master[i]->string, NET_AdrToStringwPort(adr[1]));
+			else
+				Com_Printf( "%s has no IPv6 address.\n", sv_master[i]->string);
 		}
 
+		if(adr[0].type == NA_BAD && adr[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, "");
+			sv_master[i]->modified = qfalse;
+			continue;
+		}
+
+
+		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
 		// ever incompatably changes
-		if(adr[i][0].type != NA_BAD)
-			NET_OutOfBandPrint( NS_SERVER, adr[i][0], "heartbeat %s\n", message);
-		if(adr[i][1].type != NA_BAD)
-			NET_OutOfBandPrint( NS_SERVER, adr[i][1], "heartbeat %s\n", message);
+
+		if(adr[0].type != NA_BAD)
+			NET_OutOfBandPrint( NS_SERVER, adr[0], "heartbeat %s\n", message);
+		if(adr[1].type != NA_BAD)
+			NET_OutOfBandPrint( NS_SERVER, adr[1], "heartbeat %s\n", message);
 	}
 }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/iortcw.git



More information about the Pkg-games-commits mailing list