[quake3-commits] r1638 - in trunk/code: game qcommon

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Sat Oct 3 17:15:23 EDT 2009


Author: thilo
Date: 2009-10-03 17:15:23 -0400 (Sat, 03 Oct 2009)
New Revision: 1638

Modified:
   trunk/code/game/g_client.c
   trunk/code/qcommon/q_shared.h
Log:
- Modify color generating codes to only accept numbers and not alphabetical chars anymore
- Fix client clean name so that it cannot be tricked anymore, see https://bugzilla.icculus.org/show_bug.cgi?id=3313


Modified: trunk/code/game/g_client.c
===================================================================
--- trunk/code/game/g_client.c	2009-09-28 12:44:43 UTC (rev 1637)
+++ trunk/code/game/g_client.c	2009-10-03 21:15:23 UTC (rev 1638)
@@ -607,85 +607,59 @@
 ClientCheckName
 ============
 */
-static void ClientCleanName( const char *in, char *out, int outSize ) {
-	int		len, colorlessLen;
-	char	ch;
-	char	*p;
-	int		spaces;
+static void ClientCleanName(const char *in, char *out, int outSize)
+{
+	int outpos = 0, colorlessLen = 0, spaces = 0;
 
-	//save room for trailing null byte
-	outSize--;
+	// discard leading spaces
+	for(; *in == ' '; in++);
+	
+	for(; *in && outpos < outSize - 1; in++)
+	{
+		out[outpos] = *in;
 
-	len = 0;
-	colorlessLen = 0;
-	p = out;
-	*p = 0;
-	spaces = 0;
-
-	while( 1 ) {
-		ch = *in++;
-		if( !ch ) {
-			break;
+		if(*in == ' ')
+		{
+			// don't allow too many consecutive spaces
+			if(spaces > 2)
+				continue;
+			
+			spaces++;
 		}
-
-		// don't allow leading spaces
-		if( colorlessLen == 0 && ch == ' ' ) {
-			continue;
-		}
-
-		// check colors
-		if( ch == Q_COLOR_ESCAPE ) {
-			// solo trailing carat is not a color prefix
-			if( !*in ) {
-				break;
+		if(outpos > 0 && out[outpos - 1] == Q_COLOR_ESCAPE)
+		{
+			if(Q_IsColorString(&out[outpos - 1]))
+			{
+				colorlessLen--;
+				
+				if(*in == COLOR_BLACK)
+				{
+					// Disallow color black in names to prevent players
+					// from getting advantage playing in front of black backgrounds
+					outpos--;
+					continue;
+				}
 			}
-
-			// don't allow black in a name, period
-			if( ColorIndex(*in) == 0 ) {
-				in++;
-				continue;
+			else
+			{
+				spaces = 0;
+				colorlessLen++;
 			}
-
-			// make sure room in dest for both chars
-			if( len > outSize - 2 ) {
-				break;
-			}
-
-			*out++ = ch;
-			*out++ = *in++;
-			len += 2;
-			continue;
 		}
-
-		// don't allow too many consecutive spaces
-		// don't count spaces in colorlessLen
-		if( ch == ' ' ) {
-			spaces++;
-			if( spaces > 3 ) {
-				continue;
-			}
-			*out++ = ch;
-			len++;
-			continue;
-		}
-		else {
+		else
+		{
 			spaces = 0;
+			colorlessLen++;
 		}
-
-		if( len > outSize - 1 ) {
-			break;
-		}
-
-		*out++ = ch;
-		colorlessLen++;
-		len++;
+		
+		outpos++;
 	}
-	*out = 0;
 
+	out[outpos] = '\0';
+
 	// don't allow empty names
-	if( *p == 0 || colorlessLen == 0 ) {
-		Q_strncpyz( p, "UnnamedPlayer", outSize );
-	}
+	if( *out == '\0' || colorlessLen == 0)
+		Q_strncpyz(out, "UnnamedPlayer", outSize );
 }
 
 

Modified: trunk/code/qcommon/q_shared.h
===================================================================
--- trunk/code/qcommon/q_shared.h	2009-09-28 12:44:43 UTC (rev 1637)
+++ trunk/code/qcommon/q_shared.h	2009-10-03 21:15:23 UTC (rev 1638)
@@ -365,20 +365,20 @@
 extern	vec4_t		colorDkGrey;
 
 #define Q_COLOR_ESCAPE	'^'
-#define Q_IsColorString(p)	( p && *(p) == Q_COLOR_ESCAPE && *((p)+1) && isalnum(*((p)+1)) ) // ^[0-9a-zA-Z]
+#define Q_IsColorString(p)	((p) && *(p) == Q_COLOR_ESCAPE && *((p)+1) && *((p)+1) >= '0' && *((p)+1) <= '7') // ^[0-9a-zA-Z]
 
-#define COLOR_BLACK		'0'
-#define COLOR_RED		'1'
-#define COLOR_GREEN		'2'
+#define COLOR_BLACK	'0'
+#define COLOR_RED	'1'
+#define COLOR_GREEN	'2'
 #define COLOR_YELLOW	'3'
-#define COLOR_BLUE		'4'
-#define COLOR_CYAN		'5'
+#define COLOR_BLUE	'4'
+#define COLOR_CYAN	'5'
 #define COLOR_MAGENTA	'6'
-#define COLOR_WHITE		'7'
-#define ColorIndex(c)	( ( (c) - '0' ) & 7 )
+#define COLOR_WHITE	'7'
+#define ColorIndex(c)	((c) - '0')
 
 #define S_COLOR_BLACK	"^0"
-#define S_COLOR_RED		"^1"
+#define S_COLOR_RED	"^1"
 #define S_COLOR_GREEN	"^2"
 #define S_COLOR_YELLOW	"^3"
 #define S_COLOR_BLUE	"^4"



More information about the quake3-commits mailing list