Detecting illegal name characters in a string? -
Sjn - 16.05.2016
I have an offline IRC command to change user's name, the command works fine but I need to detect if the admin enters an illegal character in the new name. For example if they type
!changename oldname {tag}newname it should give an error message saying the new name contains an illegal characters i.e
{ }
I know SetPlayerName function would check for illegal characters itself but the command is for offline name change only so the function cannot be called.
I tried making a function to detect them by creating an array of legal characters and checking if the string has those characters there, but I failed. The function returns error only if the first character from the string is illegal.
Anyone can help me out?
Re: Detecting illegal name characters in a string? -
Luicy. - 16.05.2016
Okay, This is just a tip:
Don't make blacklists, Make whitelists.
So much better and shorter.
Re: Detecting illegal name characters in a string? -
Konstantinos - 16.05.2016
In the IRC command, check if the new name is valid:
PHP код:
IsValidName(const p_name[])
{
for (new i, j = strlen(p_name); i != j; i++)
{
switch (p_name[i])
{
case '0' .. '9', 'A' .. 'Z', 'a' .. 'z', '[', ']', '(', ')', '$', '@', '.', '_', '=': continue;
default: return 0;
}
}
return 1;
}
Re: Detecting illegal name characters in a string? -
Sjn - 16.05.2016
Quote:
Originally Posted by Konstantinos
In the IRC command, check if the new name is valid:
PHP код:
IsValidName(const p_name[]) { for (new i, j = strlen(p_name); i != j; i++) { switch (p_name[i]) { case '0' .. '9', 'A' .. 'Z', 'a' .. 'z', '[', ']', '(', ')', '$', '@', '.', '_', '=': continue; default: return 0; } } return 1; }
|
Oh my, that just worked perfectly. I've been trying to find something like this from past few hours. Thanks a lot!
Quote:
Originally Posted by Meller
Okay, This is just a tip:
Don't make blacklists, Make whitelists.
So much better and shorter.
|
Ehm, what?
Re: Detecting illegal name characters in a string? -
BornHuman - 16.05.2016
Quote:
Originally Posted by Sjn
Oh my, that just worked perfectly. I've been trying to find something like this from past few hours. Thanks a lot!
Ehm, what?
|
He means instead of running a check for characters in a string that players cant use, make sure the string only contains characters they can use. A.K.A (A-Z, etc)
Like what Konstantinos showed.