Detect invisible characters in player name

Discussions about Servers
Post Reply
User avatar
Barbie
Godlike
Posts: 2792
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Detect invisible characters in player name

Post by Barbie »

Maybe more a question for section Coding: How to detect invisible characters in player names? Because unicode is allowed for player names, invisible characters beside ASCII-spaces are no problem in them. I'd like to replace them for example by underscore as it is done already for white space in class'PlayerPawn'.SetName().
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
Buggie
Godlike
Posts: 2698
Joined: Sat Mar 21, 2020 5:32 am

Re: Detect invisible characters in player name

Post by Buggie »

You can go by whitelist or by blacklist.

Blacklist mean you replace only known chars to _.
Whitelist mean you replace all chars which is not in allowed range, to _.

Usually implementation end as walk by each char in nick via Mid, get code by Ord and compare with know range or know list of values. After that take or not, some actions.
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Detect invisible characters in player name

Post by sektor2111 »

In one of toys which I wrote (un-published) I used to check char codes comparing what "name" has inside vs a BlackList and a WhiteList. If a player was matching BlackList and not found in WhiteList it would be dropped out. Product was a bit similar to what was posted in forum but using a dynamic array and a few extra-rules (name too short, too many numbers, etc).

I did not check methods for testing range A-Z and a-z + numbers range since first tool was working and target was to get rid of those using offending names and all sort of trash words.
Dennis
Average
Posts: 72
Joined: Tue Jan 12, 2021 9:18 pm

Re: Detect invisible characters in player name

Post by Dennis »

Not sure if it can detect the chars you are searching for but I will post a snippet of the code I use to remove unwanted characters from players names. You will then be able to see how it is possible to detect player name and match the characters against a whitelist. You can then change it to detect unwanted characters instead of wanted characters and replace them using the SetName function mentioned earlier.

Code: Select all

local string LegitCharacters,Name;
local int NameLength, i;
local bool bLegitName;

	LegitCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789()[]-";
	Name = P.PlayerReplicationInfo.PlayerName;
	NameLength = Len(Name);
	bLegitName = True;
	
	for ( i=0; i<NameLength+1; i++ )
		{
		if (InStr(LegitCharacters, Left(Name,1)) != -1)
			{
			Name = Right(Name, NameLength - i);
			}
		else
			{
			bLegitName = False;
			i = 999;
			}
		}
Fraggers hangout place: http://fraggers.online/
User avatar
Barbie
Godlike
Posts: 2792
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Detect invisible characters in player name

Post by Barbie »

Thanks for answers. I've noticed that not all Unicode characters are displayed (for example '⨊') - in game they show up as blank. What range of Unicode characters are supported?

Automatically merged

Dennis wrote: Fri Jun 10, 2022 6:17 pm

Code: Select all

	NameLength = Len(Name);
	for ( i=0; i<NameLength+1; i++ )
Are you sure that this loop is doing what you want? 8)
Spoiler
Because strings are zero based, access to MyString[Len(MyString)] is not valid.
Correct loop should be

Code: Select all

	for ( i=0; i<NameLength; i++ )
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
Post Reply