Strcmp Problems - 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: Strcmp Problems (
/showthread.php?tid=82412)
Strcmp Problems -
Jonte92 - 18.06.2009
Hey scripters!
I've had some problems with the strcmp syntax.
I'm using it to my login and the problem is that whatever I type it will still login, even when I type the correct password.
The code I'm testing now is
text is the strtok from the command)
Код:
if(strcmp(text, "Password", false, strlen(text)) != 0)
{
SCM(playerid, COLOR_RED, "MAIN ERROR(Wrong Password!)");
fclose(UserFile);
return 1;
}
And then I simply got the login code under that(But that shouldn't matter to the strcmp syntax)
So when I type the password "Password" I should get spawned and I do , but I can type anything and I will still spawn , I NEVER get the message "Wrong Password".
Can someone please help me out with this?
I'm all out of ideas.
Cheers / Jax!
Re: Strcmp Problems -
yezizhu - 18.06.2009
add debug:
use instead:
PS
trcmp will return 0 if compare with null string.
Re: Strcmp Problems -
Jonte92 - 18.06.2009
I wrote this as the debug:
Код:
printf("(%s)",text);
printf("(%d)",strcmp(text, "Password"));
new TextO[255];
format(TextO, sizeof(TextO), "%d", strcmp(text, "Password"));
SCM(playerid, COLOR_WHITE, TextO);
if(strcmp(text, "Password", false, strlen(text)) != 0)
{
SCM(playerid, COLOR_RED, "MAIN ERROR(Wrong Password!)");
fclose(UserFile);
return 1;
}
But it doesn't matter what I type, the strcmp always returns 0.
Why does this happen?
And the command code looks like this:
Код:
if(strcmp(cmd, "/login", true) == 0 || strcmp(cmd, "/L", true) == 0)
{
if(IsPlayerConnected(playerid))
{
new tmppass[64];
if(Inloggad[playerid] == 1)
{
SCM(playerid, COLOR_RED, "** MAIN ERROR(You are already logged in!) **");
return 1;
}
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SCM(playerid, COLOR_WHITE, "** USAGE: (/L)ogin <Password> **");
return 1;
}
SCM(playerid, COLOR_WHITE, "** Logging in... **");
strmid(tmppass, tmp, 0, strlen(cmdtext), 255);
SetTimerEx("OnLogin", 2000, 0, "is", playerid, tmppass);
}
//Else: Is not connected
return 1;
}
But if I change the timer to just
Код:
OnLogin(playerid, tmppass);
It works!
Howdo i do so it works with the timer?
And why can I login with Passw?(FIXED, changed the strlen(text) to strlen("Password"))