EnsurePlayerNameIsGood: Remove trailing whitespace, instead of just failing on it

Interesting error with its recursive duplication resolving exposed by the previous commit!
This commit is contained in:
toaster 2024-03-18 19:24:42 +00:00
parent a4cec98c26
commit a161df579f

View file

@ -606,13 +606,22 @@ boolean EnsurePlayerNameIsGood(char *name, INT32 playernum)
if (len == 0 || len > MAXPLAYERNAME) if (len == 0 || len > MAXPLAYERNAME)
return false; // Empty or too long. return false; // Empty or too long.
if (name[0] == ' ' || name[len-1] == ' ') if (name[0] == ' ')
return false; // Starts or ends with a space. return false; // Starts with a space.
if (isdigit(name[0])) if (isdigit(name[0]))
return false; // Starts with a digit. return false; // Starts with a digit.
if (name[0] == '@' || name[0] == '~') if (name[0] == '@' || name[0] == '~')
return false; // Starts with an admin symbol. 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. // Check if it contains a non-printing character.
// Note: ANSI C isprint() considers space a printing character. // Note: ANSI C isprint() considers space a printing character.
// Also don't allow semicolons, since they are used as // Also don't allow semicolons, since they are used as