Detect invisible characters in player name
-
- Godlike
- Posts: 2557
- Joined: Fri Sep 25, 2015 9:01 pm
- Location: moved without proper hashing
Detect invisible characters in player name
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
-
- Godlike
- Posts: 2018
- Joined: Sat Mar 21, 2020 5:32 am
Re: Detect invisible characters in player name
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.
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.
-
- Godlike
- Posts: 6202
- Joined: Sun May 09, 2010 6:15 pm
- Location: On the roof.
Re: Detect invisible characters in player name
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.
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.
-
- Average
- Posts: 72
- Joined: Tue Jan 12, 2021 9:18 pm
Re: Detect invisible characters in player name
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/
-
- Godlike
- Posts: 2557
- Joined: Fri Sep 25, 2015 9:01 pm
- Location: moved without proper hashing
Re: Detect invisible characters in player name
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
Are you sure that this loop is doing what you want?Dennis wrote: ↑Fri Jun 10, 2022 6:17 pmCode: Select all
NameLength = Len(Name); for ( i=0; i<NameLength+1; i++ )

Spoiler
Because strings are zero based, access to MyString[Len(MyString)] is not valid.
Correct loop should be
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