SA-MP Forums Archive
Detecting illegal name characters in a string? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Detecting illegal name characters in a string? (/showthread.php?tid=607244)



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 
istrlen(p_name); != ji++)
    {
        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 
istrlen(p_name); != ji++)
    {
        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.