From a161df579f0e3f52f6d10b3320ab8f3b64fd436d Mon Sep 17 00:00:00 2001 From: toaster Date: Mon, 18 Mar 2024 19:24:42 +0000 Subject: [PATCH] EnsurePlayerNameIsGood: Remove trailing whitespace, instead of just failing on it Interesting error with its recursive duplication resolving exposed by the previous commit! --- src/d_netcmd.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 472e0cdd6..8c2c571c9 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -606,13 +606,22 @@ boolean EnsurePlayerNameIsGood(char *name, INT32 playernum) if (len == 0 || len > MAXPLAYERNAME) return false; // Empty or too long. - if (name[0] == ' ' || name[len-1] == ' ') - return false; // Starts or ends with a space. + if (name[0] == ' ') + return false; // Starts with a space. if (isdigit(name[0])) return false; // Starts with a digit. if (name[0] == '@' || name[0] == '~') return false; // Starts with an admin symbol. + // Clean up trailing whitespace. + while (len && name[len-1] == ' ') + { + name[len-1] = '\0'; + len--; + } + if (len == 0) + return false; + // Check if it contains a non-printing character. // Note: ANSI C isprint() considers space a printing character. // Also don't allow semicolons, since they are used as