Detecting illegal name characters in a string?
#1

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?
Reply
#2

Okay, This is just a tip:
Don't make blacklists, Make whitelists.
So much better and shorter.
Reply
#3

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;

Reply
#4

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?
Reply
#5

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)