[openjk] 06/15: MP: Do not call NET_AdrToString* for every incoming packet

Simon McVittie smcv at debian.org
Thu Jun 15 10:28:40 UTC 2017


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

smcv pushed a commit to branch debian/master
in repository openjk.

commit 948b55b59b6c8110969d7b22a504397a313a70ba
Author: Ensiform <ensiform at gmail.com>
Date:   Sun May 14 11:11:41 2017 -0500

    MP: Do not call NET_AdrToString* for every incoming packet
    
    Even in non-developer mode, this function was previously called despite only being printed in developer = 1 cases.
    
    Fix from ec-/Quake3e at 1db5d128df035b8d12440c010efcc97b723839cd
---
 codemp/client/cl_main.cpp      | 18 ++++++++++++------
 codemp/server/sv_challenge.cpp |  8 ++++++--
 codemp/server/sv_client.cpp    |  6 ++++--
 codemp/server/sv_main.cpp      | 28 +++++++++++++++++++---------
 4 files changed, 41 insertions(+), 19 deletions(-)

diff --git a/codemp/client/cl_main.cpp b/codemp/client/cl_main.cpp
index 3de7f1a..bf5d85b 100644
--- a/codemp/client/cl_main.cpp
+++ b/codemp/client/cl_main.cpp
@@ -1864,9 +1864,11 @@ void CL_ConnectionlessPacket( netadr_t from, msg_t *msg ) {
 
 	Cmd_TokenizeString( s );
 
-	c = Cmd_Argv(0);
+	c = Cmd_Argv( 0 );
 
-	Com_DPrintf ("CL packet %s: %s\n", NET_AdrToString(from), c);
+	if ( com_developer->integer ) {
+		Com_Printf( "CL packet %s: %s\n", NET_AdrToString( from ), c );
+	}
 
 	// challenge from the server we are connecting to
 	if ( !Q_stricmp(c, "challengeResponse") )
@@ -2020,8 +2022,10 @@ void CL_PacketEvent( netadr_t from, msg_t *msg ) {
 	// packet from server
 	//
 	if ( !NET_CompareAdr( from, clc.netchan.remoteAddress ) ) {
-		Com_DPrintf ("%s:sequenced packet without connection\n"
-			,NET_AdrToString( from ) );
+		if ( com_developer->integer ) {
+			Com_Printf( "%s:sequenced packet without connection\n",
+				NET_AdrToString( from ) );
+		}
 		// FIXME: send a client disconnect?
 		return;
 	}
@@ -2990,7 +2994,9 @@ void CL_ServerInfoPacket( netadr_t from, msg_t *msg ) {
 		{
 			// calc ping time
 			cl_pinglist[i].time = Sys_Milliseconds() - cl_pinglist[i].start;
-			Com_DPrintf( "ping time %dms from %s\n", cl_pinglist[i].time, NET_AdrToString( from ) );
+			if ( com_developer->integer ) {
+				Com_Printf( "ping time %dms from %s\n", cl_pinglist[i].time, NET_AdrToString( from ) );
+			}
 
 			// save of info
 			Q_strncpyz( cl_pinglist[i].info, infoString, sizeof( cl_pinglist[i].info ) );
@@ -3044,7 +3050,7 @@ void CL_ServerInfoPacket( netadr_t from, msg_t *msg ) {
 	Q_strncpyz( info, MSG_ReadString( msg ), MAX_INFO_STRING );
 	if (strlen(info)) {
 		if (info[strlen(info)-1] != '\n') {
-			strncat(info, "\n", sizeof(info) -1);
+			Q_strcat(info, sizeof(info), "\n");
 		}
 		Com_Printf( "%s: %s", NET_AdrToString( from ), info );
 	}
diff --git a/codemp/server/sv_challenge.cpp b/codemp/server/sv_challenge.cpp
index 1331af8..147c48d 100644
--- a/codemp/server/sv_challenge.cpp
+++ b/codemp/server/sv_challenge.cpp
@@ -126,7 +126,9 @@ static int SV_CreateChallenge(int timestamp, netadr_t from)
 	challenge |= (unsigned int)(timestamp & 0x1) << 31;
 
 #ifdef DEBUG_SV_CHALLENGE
-	Com_DPrintf("Generated challenge %d (timestamp = %d) for %s\n", challenge, timestamp, NET_AdrToString(from));
+	if ( com_developer->integer ) {
+		Com_Printf( "Generated challenge %d (timestamp = %d) for %s\n", challenge, timestamp, NET_AdrToString( from ) );
+	}
 #endif
 
 	return challenge;
@@ -174,7 +176,9 @@ qboolean SV_VerifyChallenge(int receivedChallenge, netadr_t from)
 	int challengeTimestamp = currentTimestamp - (currentPeriod ^ challengePeriod);
 
 #ifdef DEBUG_SV_CHALLENGE
-	Com_DPrintf("Verifying challenge %d (timestamp = %d) for %s\n", receivedChallenge, challengeTimestamp, NET_AdrToString(from));
+	if ( com_developer->integer ) {
+		Com_Printf( "Verifying challenge %d (timestamp = %d) for %s\n", receivedChallenge, challengeTimestamp, NET_AdrToString( from ) );
+	}
 #endif
 
 	int expectedChallenge = SV_CreateChallenge(challengeTimestamp, from);
diff --git a/codemp/server/sv_client.cpp b/codemp/server/sv_client.cpp
index 105e82a..ef1c010 100644
--- a/codemp/server/sv_client.cpp
+++ b/codemp/server/sv_client.cpp
@@ -76,8 +76,10 @@ void SV_GetChallenge( netadr_t from ) {
 
 	// Prevent using getchallenge as an amplifier
 	if ( SVC_RateLimitAddress( from, 10, 1000 ) ) {
-		Com_DPrintf( "SV_GetChallenge: rate limit from %s exceeded, dropping request\n",
-			NET_AdrToString( from ) );
+		if ( com_developer->integer ) {
+			Com_Printf( "SV_GetChallenge: rate limit from %s exceeded, dropping request\n",
+				NET_AdrToString( from ) );
+		}
 		return;
 	}
 
diff --git a/codemp/server/sv_main.cpp b/codemp/server/sv_main.cpp
index 6d3c1d4..bc67f22 100644
--- a/codemp/server/sv_main.cpp
+++ b/codemp/server/sv_main.cpp
@@ -484,8 +484,10 @@ void SVC_Status( netadr_t from ) {
 
 	// Prevent using getstatus as an amplifier
 	if ( SVC_RateLimitAddress( from, 10, 1000 ) ) {
-		Com_DPrintf( "SVC_Status: rate limit from %s exceeded, dropping request\n",
-			NET_AdrToString( from ) );
+		if ( com_developer->integer ) {
+			Com_Printf( "SVC_Status: rate limit from %s exceeded, dropping request\n",
+				NET_AdrToString( from ) );
+		}
 		return;
 	}
 
@@ -554,8 +556,10 @@ void SVC_Info( netadr_t from ) {
 
 	// Prevent using getinfo as an amplifier
 	if ( SVC_RateLimitAddress( from, 10, 1000 ) ) {
-		Com_DPrintf( "SVC_Info: rate limit from %s exceeded, dropping request\n",
-			NET_AdrToString( from ) );
+		if ( com_developer->integer ) {
+			Com_Printf( "SVC_Info: rate limit from %s exceeded, dropping request\n",
+				NET_AdrToString( from ) );
+		}
 		return;
 	}
 
@@ -659,8 +663,10 @@ void SVC_RemoteCommand( netadr_t from, msg_t *msg ) {
 
 	// Prevent using rcon as an amplifier and make dictionary attacks impractical
 	if ( SVC_RateLimitAddress( from, 10, 1000 ) ) {
-		Com_DPrintf( "SVC_RemoteCommand: rate limit from %s exceeded, dropping request\n",
-			NET_AdrToString( from ) );
+		if ( com_developer->integer ) {
+			Com_Printf( "SVC_RemoteCommand: rate limit from %s exceeded, dropping request\n",
+				NET_AdrToString( from ) );
+		}
 		return;
 	}
 
@@ -738,7 +744,9 @@ void SV_ConnectionlessPacket( netadr_t from, msg_t *msg ) {
 	Cmd_TokenizeString( s );
 
 	c = Cmd_Argv(0);
-	Com_DPrintf ("SV packet %s : %s\n", NET_AdrToString(from), c);
+	if ( com_developer->integer ) {
+		Com_Printf( "SV packet %s : %s\n", NET_AdrToString( from ), c );
+	}
 
 	if (!Q_stricmp(c, "getstatus")) {
 		SVC_Status( from  );
@@ -757,8 +765,10 @@ void SV_ConnectionlessPacket( netadr_t from, msg_t *msg ) {
 		// server disconnect messages when their new server sees our final
 		// sequenced messages to the old client
 	} else {
-		Com_DPrintf ("bad connectionless packet from %s:\n%s\n",
-			NET_AdrToString (from), s);
+		if ( com_developer->integer ) {
+			Com_Printf( "bad connectionless packet from %s:\n%s\n",
+				NET_AdrToString( from ), s );
+		}
 	}
 }
 

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



More information about the Pkg-games-commits mailing list