Page 1 of 1

How to detect bad characters in player names?

Posted: Fri Jun 16, 2023 12:29 am
by Barbie
Sometimes players with strange characters in name join the server. To avoid using characters that are not proper displayed in UT, I created a function to adjust such names:

Code: Select all

function bool AdjustPlayerName(string CurrentName, out string NewName) {
/*******************************************************************************
Returns all "bad" characters in *CurrentName* replaced with "_" in *NewName*.
If at least one bad character was found, TRUE is returned.
*******************************************************************************/
local int i, CharCode;

	logger(LOG_Debug, "AdjustPlayerName", "CurrentName='" $ CurrentName $ "', Len(CurrentName)=" $ len(CurrentName));
	NewName = "";
	for (i = 0; i < len(CurrentName); i++)
	{
		CharCode = asc(mid(CurrentName, i, 1));
		logger(LOG_Debug, "AdjustPlayerName", mid(CurrentName, i, 1) $ "=" $ CharCode);
		if (class'SharedCode'.static.CharIsWhite(CharCode) || CharCode > 255)
			NewName = NewName $ "_";
		else
			NewName = NewName $ Chr(CharCode);
	}
	if (CurrentName == NewName)
	{
		logger(LOG_All, "AdjustPlayerName", "'" $ CurrentName $ "' has no bad chars, keeping this name");
		return false;
	}
	else
	{
		logger(LOG_Debug, "AdjustPlayerName", "changed" @ CurrentName @ "to '" $ NewName $ "'");
		return true;
	}
}
static function bool CharIsWhite

Code: Select all

static function bool CharIsWhite(int charcode) {
/******************************************************************************
Returns TRUE if the char with *charcode* is a white char (= no ink is used if
printed).
******************************************************************************/

	switch (charcode) {
		case 9: // tab
			return true;
		case 10: // LF
			return true;
		case 11: // vTab
			return true;
		case 12: // FF
			return true;
		case 13: // CR
			return true;
		case 32: // Space
			return true;
		case 0xAD: // soft hyphen
			return true;
	}
	if (charcode <= 255)
		return false;

	// what about unicode?
	return false;
}
But it does not catch the <Device Control String> (DCS)?I tried it and the result is:
The log file wrote:Level server received: JOIN
Join request: MH-GreatescapeV0?Name=??Class=BotPack.TFemale1?Team=255?skin=FCommandoSkins_Negaverse_Titus.ttus?Face=FCommandoSkins_Negaverse_Titus.titus?Voice=BotPack.VoiceFemaleTwo?Override
Team 255
Login: ?
2023-06-16 01:18:19 MH-GreatescapeV0.MonsterHuntSB0.AdjustPlayerName LOG_Debug: CurrentName='?', Len(CurrentName)=1
2023-06-16 01:18:19 MH-GreatescapeV0.MonsterHuntSB0.AdjustPlayerName LOG_Debug: ?=144

Re: How to detect bad characters in player names?

Posted: Fri Jun 16, 2023 3:44 pm
by sektor2111
Barbie wrote: Fri Jun 16, 2023 12:29 am To avoid using characters that are not proper displayed in UT
Interesting...
Subject it's more extended, they are not only not displayed in UT (Nexgen does lousy records loading database with crap), but when you check stats at Game-Tracker there will be also some funky ID which has nothing to do with the clown from game. I would try to figure implementing such corrections in PreLogin using XC_Engine but... last time it did not work, or... I failed to figure something at this point...

Edit: "AlternatePath"
Perhaps I'll edit server's run-line with something more cute related to NexgenPlayerLookUp.ini file. I'll save it after each auto-stop and adding a fresh EMPTY file before start - as an "auto-update" stuff (automatic update is already set). Old file will be LZMA compressed and things are getting clean excepting server from processing a long array with trash (that version has a 25,000 elements array - a SLOW-DOWN).

Re: How to detect bad characters in player names?

Posted: Sat Jun 17, 2023 2:50 am
by The_Cowboy
Barbie wrote: Fri Jun 16, 2023 12:29 am But it does not catch the <Device Control String> (DCS)?
Hmm, there may be native way to detect them (https://www.geeksforgeeks.org/iscntrl-c ... haracters/). Let me know if that is the thing (or give me the relevant c++ code). I can try to hook a native function for you (windows and linux only).

Re: How to detect bad characters in player names?

Posted: Sat Jun 17, 2023 8:42 pm
by Barbie
Thanks for answers.
I think the problem lies in handling of different characters in different pages and unicode, but with the same char code: Len(<Device Control String>) returns "1" correctly, and Asc(<Device Control String>) returns 0x90 (144 decimal) what is <DCS> in UTF-16 and UTF-32, unused in code page Windows-1252, Latin capital letter E with acute ("É") in code page 437, etc.

I think I'll stick to UTF-16 and extend the function CharIsWhite with the unused characters of code page Windows-1252.