SA-MP Forums Archive
Could someone with fresh eye look on this script - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Could someone with fresh eye look on this script (/showthread.php?tid=223998)



Could someone with fresh eye look on this script - Voldemort - 10.02.2011

pawn Код:
IsValidRPName(rpname[])
{
    if(strfind(rpname,"_",true) == -1) { return 0; }
    if(strlen(rpname) < 6) { return 0; }
    if(strlen(rpname) > 19) { return 0; }
    new name1 = strfind(rpname, "The", true);
    new name2 = strfind(rpname, "kill", true);
    new name3 = strfind(rpname, "__", true);
    new name4 = strfind(rpname, "123", true);
    new name5 = strfind(rpname, "asd", true);
    new name6 = strfind(rpname, "xx", true);
    if(name1 != -1 || name2 != -1 || name3 != -1 || name4 != -1 || name5 != -1 || name6 != -1)
    {
        return 0;
    }
    new pos;
    while(pos <= strlen(rpname))
    {
        new str[5];
        for(new lenght = 0; lenght < 10; lenght++)
        {
            format(str,sizeof(str),"%d",lenght);
            if(strfind(rpname[pos],str,true) != -1)
            {
                return 0;
            }
        }
        pos++;
    }
    new part[10][12];
    new name,surname;
    split(rpname,part,'_');
    for(new g = 2; g < 10; g++)
    {
        if(strlen(part[g]) > 0)
        {
            return 0;
        }
    }
    new invalid;
    for(new i = 0; i < strlen(rpname); i++)
    {
        if(rpname[i] >= 'A' && rpname[i] <= 'Z')
        {
            invalid++;
            if(invalid > 2)
            {
                return 0;
            }
        }
    }
    if(part[0][0] >= 'A' && part[0][0] <= 'Z')
    {
        name = 1;
    }
    if(part[1][0] >= 'A' && part[1][0] <= 'Z')
    {
        surname = 1;
    }
    if(name == 1 && surname == 1)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
Some names, in some combinations cause server crash, could somone with fresh eye overview this script, maybe I have forgeted something


Re: Could someone with fresh eye look on this script - Krx17 - 10.02.2011

Here's one problem already.

pawn Код:
while(pos <= strlen(rpname))
If rpname was 7 characters long, the array would go from 0-6, yet at the end of that loop, pos would equal 7 and thus crash the server.

It should be:
pawn Код:
while(pos < strlen(rpname))
Edit: Your code is also VERY inefficient.