SA-MP Forums Archive
Player name with "_" - 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: Player name with "_" (/showthread.php?tid=587123)



Player name with "_" - Sn4ke2 - 28.08.2015

Hellow, how to change this ? I want to cant create a normal name without "_" Like : Sn4Ke, or NiTr3X, here is the code

PHP код:
Dialog:CreateChar(playerid, response, listitem, inputtext[])
{
    if (!
response)
        return 
PlayerData[playerid][pCharacter] = 0;
    else if (
isnull(inputtext) || strlen(inputtext) > 20)
        return 
Dialog_Show(playerid, CreateChar, DIALOG_STYLE_INPUT, "Create Character", "Please enter the name of your new character below:\n\nWarning: Your name must be in the Firstname_Lastname format and not exceed 20 characters.", "Create", "Cancel");
    else if (!
IsValidRoleplayName(inputtext))
        return 
Dialog_Show(playerid, CreateChar, DIALOG_STYLE_INPUT, "Create Character", "Error: You have entered an invalid roleplay name.\n\nPlease enter the name of your new character below:\n\nWarning: Your name must be in the Firstname_Lastname format and not exceed 20 characters.", "Create", "Cancel");
    else
    {
        static
            
query[128];
        
format(query, sizeof(query), "SELECT `ID` FROM `characters` WHERE `Character` = '%s'", inputtext);
        
mysql_tquery(g_iHandle, query, "OnCharacterCheck", "ds", playerid, inputtext);
    }
    return 
1;
} 
And Public
PHP код:
IsValidRoleplayName(const name[]) {
    if (!
name[0] || strfind(name, "_") == -1)
        return 
0;
    else for (new 
i = 0, len = strlen(name); i != len; i ++) {
        if ((
i == 0) && (name[i] < 'A' || name[i] > 'Z'))
            return 
0;
        else if ((
i != 0 && i < len  && name[i] == '_') && (name[i + 1] < 'A' || name[i + 1] > 'Z'))
            return 
0;
        else if ((
name[i] < 'A' || name[i] > 'Z') && (name[i] < 'a' || name[i] > 'z') && name[i] != '_' && name[i] != '.')
            return 
0;
    }
    return 
1;
} 



Re: Player name with "_" - PT - 28.08.2015

PHP код:
Dialog:CreateChar(playerid, response, listitem, inputtext[]) 
{ 
    if (!
response) 
        return 
PlayerData[playerid][pCharacter] = 0; 
    else if (
isnull(inputtext) || strlen(inputtext) > 20) 
        return 
Dialog_Show(playerid, CreateChar, DIALOG_STYLE_INPUT, "Create Character", "Please enter the name of your new character below:\n\nWarning: Your name must be in the Firstname_Lastname format and not exceed 20 characters.", "Create", "Cancel"); 
    else 
    {
        new 
query[128]; 
        
format(query, sizeof(query), "SELECT `ID` FROM `characters` WHERE `Character` = '%s'", inputtext); 
        
mysql_tquery(g_iHandle, query, "OnCharacterCheck", "ds", playerid, inputtext); 
    } 
    return 
1; 
} 



Re: Player name with "_" - Sn4ke2 - 28.08.2015

Thank you


Re: Player name with "_" - Banana_Ghost - 29.08.2015

To add on, I'd seriously be escaping that input.

PHP код:
Dialog:CreateChar(playerid, response, listitem, inputtext[])
{
    if (!
response)
        return 
PlayerData[playerid][pCharacter] = 0;
    else if (
isnull(inputtext) || strlen(inputtext) > 20)
        return 
Dialog_Show(playerid, CreateChar, DIALOG_STYLE_INPUT, "Create Character", "Please enter the name of your new character below:\n\nWarning: Your name must be in the Firstname_Lastname format and not exceed 20 characters.", "Create", "Cancel");
    else
    {
        new 
query[128];
        
mysql_format(g_iHandle, query, sizeof(query), "SELECT `ID` FROM `characters` WHERE `Character` = '%e'", inputtext);
        
mysql_tquery(g_iHandle, query, "OnCharacterCheck", "ds", playerid, inputtext);
    }
    return 
1;
} 
Use mysql_format and pass any strings with the %e specifier or at least use mysql_escape_string so it can be escaped for SQL vulnerabilities.