Strcmp Problems
#1

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 istext 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!
Reply
#2

add debug:
pawn Код:
printf("(%s)",text);
use instead:
pawn Код:
strcmp(text,"Password")
PStrcmp will return 0 if compare with null string.
Reply
#3

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"))
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)