strfind, strcmp
#1

Which function should i use for checking names for forbidden words?

strfind(), strcmp()
I know how they both work, im just not sure if it matters if i use strfind or strcmp.
Maybe one of them is faster then the other?

~Wesley
Reply
#2

Well they are both completely different. strcmp is string compare, it is used for comparing two strings and seeing if they match. strfind is string find, it is used for finding a string within a string.

So which one do you think you need to use?
Reply
#3

Hm, duh.. Should be strfind then.. Haha
Thanks
Reply
#4

Quote:
Originally Posted by Wesley221
Посмотреть сообщение
Which function should i use for checking names for forbidden words?

strfind(), strcmp()
I know how they both work, im just not sure if it matters if i use strfind or strcmp.
Maybe one of them is faster then the other?

~Wesley
strcmp will check the whole name. But strfind will check part of name.
pawn Код:
if(!strcmp(name,"forbidden_name"))

if(strfind(name,"forbidden") != -1)
if(strfind(name,"name") != -1)
Reply
#5

Im getting kicked by using the name "Lemmy_Lusion[NL]" when im using this piece of code:
pawn Код:
for( new i = 0; i < MAX_FORBIDDEN_NAMES; i ++ )
    {
        if( strfind(ForbiddenNames[i], GetName(playerid), true ) )
        {
            SendClientMessage(playerid, COLOR_ORANGE, " ** We found a forbidden word in your name! Please remove it and re-connect. ");
            Kick(playerid);
            return 1;
        }
    }
I never used the strfind function before, is this the right way?
Note: There are no parts of my name in the forbiddennames variable
Reply
#6

pawn Код:
for( new i = 0; i < MAX_FORBIDDEN_NAMES; i ++ )
    {
        if( strfind(ForbiddenNames[i], GetName(playerid), true ) != -1)
        {
            SendClientMessage(playerid, COLOR_ORANGE, " ** We found a forbidden word in your name! Please remove it and re-connect. ");
            Kick(playerid);
            return 1;
        }
    }
Reply
#7

Im not getting kicked now, but now my register/login dialog wont show neither. Ive already tried to remove the 'return 1;', but still didnt show the dialog.
pawn Код:
public OnPlayerConnect(playerid)
{
    for( new i = 0; i < MAX_FORBIDDEN_NAMES; i ++ )
    {
        if( strfind( ForbiddenNames[i], GetName(playerid), true ) != -1 )
        {
            SendClientMessage(playerid, COLOR_ORANGE, " ** We found a forbidden word in your name! Please remove it and re-connect. ");
            Kick(playerid);
        }
    }
    if(!fexist(UserPath(playerid)))
    {
        Register
        return 1;
    }
    else if (fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        if( PlayerInfo[playerid][pBanned] == 1 ) return Kick(playerid), SendClientMessage(playerid, COLOR_RED, " ** You are banned and cannot log in! ");
        printf("|| TotalKills: %i || TotalDeaths: %i || TotalKD: %0.2f || Useown: %i ||", PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths], Float:floatdiv(PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths]), WeaponInfo[playerid][pUseOwn]);
        Login
        return 1;
    }
Reply
#8

Quote:
Originally Posted by Wesley221
Посмотреть сообщение
Im not getting kicked now, but now my register/login dialog wont show neither. Ive already tried to remove the 'return 1;', but still didnt show the dialog.
pawn Код:
public OnPlayerConnect(playerid)
{
    for( new i = 0; i < MAX_FORBIDDEN_NAMES; i ++ )
    {
        if( strfind( ForbiddenNames[i], GetName(playerid), true ) != -1 )
        {
            SendClientMessage(playerid, COLOR_ORANGE, " ** We found a forbidden word in your name! Please remove it and re-connect. ");
            Kick(playerid);
        }
    }
    if(!fexist(UserPath(playerid)))
    {
        Register
        return 1;
    }
    else if (fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        if( PlayerInfo[playerid][pBanned] == 1 ) return Kick(playerid), SendClientMessage(playerid, COLOR_RED, " ** You are banned and cannot log in! ");
        printf("|| TotalKills: %i || TotalDeaths: %i || TotalKD: %0.2f || Useown: %i ||", PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths], Float:floatdiv(PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths]), WeaponInfo[playerid][pUseOwn]);
        Login
        return 1;
    }
A don't see anywhere in your code that show dialog.
Reply
#9

Its the "Register Login". I defined the ShowPlayerDialog in them, so i dont have to have long lines everywhere.
Also i just debugged the script like this:
pawn Код:
for( new i = 0; i < MAX_FORBIDDEN_NAMES; i ++ )
    {
        printf("%s start loop", GetName(playerid));
        if( strfind( ForbiddenNames[i], GetName(playerid), true ) != -1 )
        {
            printf("%s forbidden name found", GetName(playerid));
            SendClientMessage(playerid, COLOR_ORANGE, " ** We found a forbidden word in your name! Please remove it and re-connect. ");
            printf("%s kicked", GetName(playerid));
            Kick(playerid);
        }
        printf("%s end loop", GetName(playerid));
    }
This is what it shows:
Код:
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop
[18:03:45] Lemmy_Lusion[NL] end loop
[18:03:45] Lemmy_Lusion[NL] start loop // 31 time, but doesnt end
Just the last one doesnt stop.
Reply
#10

Show us your ForbiddenNames variable.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)