SA-MP Forums Archive
strlen(str[]) doesn't work :/ - 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: strlen(str[]) doesn't work :/ (/showthread.php?tid=84006)



strlen(str[]) doesn't work :/ - Dreftas - 28.06.2009

pawn Код:
new BanInfoIp[16];
if (sscanf(params, "s",BanInfoIp)) return SendClientMessage(playerid, red, "[SERVER]: Naudojimas: \"/baninfo [ip]\"");
       
        if(strlen(BanInfoIp) >= 16)
            return SendClientMessage(playerid,red,"[SERVER]: Command too long...");
Why this doesnt work? If i write ~18-19 symbols, thats ok, script shows "command too long", if i write more ~23-25 script just shows SERVER: Unknown command :/ how to fix?


Re: strlen(str[]) doesn't work :/ - illay - 28.06.2009

pawn Код:
new
    BanInfoIp[16];
if (sscanf(params, "s",BanInfoIp)) {
    return SendClientMessage(playerid, red, "[SERVER]: Naudojimas: \"/baninfo [ip]\"");
}
else if(strlen(BanInfoIp) >= 16) {
    return SendClientMessage(playerid,red,"[SERVER]: Command too long...");
}
David


Re: strlen(str[]) doesn't work :/ - Dreftas - 28.06.2009

Doesn't work that. More suggests? :/


Re: strlen(str[]) doesn't work :/ - Goldkiller - 28.06.2009

Do you think the len of BanInfoIP can be longer than it's maximum len / size?
BanInfoIP hat 16 cells,hence the string can't be longer than 16.
That 'Server Unkown Command' show's up because there must be some kind of crash.
pawn Код:
new
    BanInfoIp[16];
if(strlen( params ) >= 16) {
    return SendClientMessage(playerid,red,"[SERVER]: Command too long...");
}else if (sscanf(params, "s",BanInfoIp)) {
    return SendClientMessage(playerid, red, "[SERVER]: Naudojimas: \"/baninfo [ip]\"");
}



Re: strlen(str[]) doesn't work :/ - Dreftas - 28.06.2009

Quote:
Originally Posted by Goldkiller
Do you think the len of BanInfoIP can be longer than it's maximum len / size?
BanInfoIP hat 16 cells,hence the string can't be longer than 16.
That 'Server Unkown Command' show's up because there must be some kind of crash.
pawn Код:
new
    BanInfoIp[16];
if(strlen( params ) >= 16) {
    return SendClientMessage(playerid,red,"[SERVER]: Command too long...");
}else if (sscanf(params, "s",BanInfoIp)) {
    return SendClientMessage(playerid, red, "[SERVER]: Naudojimas: \"/baninfo [ip]\"");
}
No, i dont think that string can be longer than 16, but if i write more SERVER: Unknown command shows up, as you said it shows up for some kind of crash, oh that crash, totally crashing my server.

This works for command where i need to write something in one string.
But what abbout commands like:
/kick [id] [reason] ?
How to check that [rason] wouldn't be longer than i writed in new Reason[56] ?
Do everything like in /baninfo ? with strlen(params) (knowing that first going ID, not string) ?


Re: strlen(str[]) doesn't work :/ - woot - 28.06.2009

If you defined BanInfoIp as max 16 cells, then it will return Unknown Command if the input is over 16 cells.


Re: strlen(str[]) doesn't work :/ - Dreftas - 28.06.2009

And then, because it using sql with that string server crash if string is writed more cells than i writed in BanInfoIp[16]...

Oh, nvm.. Waiting answer to this:
Quote:

But what abbout commands like:
/kick [id] [reason] ?
How to check that [rason] wouldn't be longer than i writed in new Reason[56] ?
Do everything like in /baninfo ? with strlen(params) (knowing that first going ID, not string) ?