strlen(str[]) doesn't work :/
#1

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

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
Reply
#3

Doesn't work that. More suggests? :/
Reply
#4

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]\"");
}
Reply
#5

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) ?
Reply
#6

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

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) ?

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)