Problem with a login system
#1

Ok, it`s the first time I use a dialog box to make a login/register system. The code is this:

Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	if(dialogid == 0)
	{
	  if(response == 1)
	  {
  		new pname[MAX_PLAYER_NAME], file[128], string[128];
			GetPlayerName(playerid, pname, sizeof(pname));
			format(file, sizeof(file), "\\Users\\%s.ini", pname);
			dini_Create(file);
			dini_Set(file, "password", inputtext);
 			dini_IntSet(file, "level", 0);
 			format(string, sizeof(string), ".:Welcome to the server %s:.", pname);
 			SendClientMessage(playerid, COLOUR_GREEN, string);
 			logged[playerid] = 1;
 			return 1;
		}
		else 
		{
      SendClientMessage(playerid, COLOUR_RED, "You must login to play on this server!");
			Kick( playerid );
			return 1;
		}
		return 1;
	}
	else if(dialogid == 1)
	{
  		new pname[MAX_PLAYER_NAME], file[128], string[128];
			GetPlayerName(playerid, pname, sizeof(pname));
			format(file, sizeof(file), "\\Users\\%s.ini", pname);
			if(dini_Get(file, "password") == inputtext) //Here is the error
			{
				logged[playerid] = 1;
	  		level[playerid] = dini_Int(file, "level");
	  		SetPlayerMoney(playerid, dini_Int(file, "money"));
	  		SendClientMessage(playerid, COLOUR_GREEN, "You have succesfully logged in!");
	  		return 1;
			}
			else SendClientMessage(playerid, COLOUR_RED, "Wrong password for this account. Try again!");
			return 1;
	}
	return 1;
}
When i try to compile it, I get this error "error 033: array must be indexed (variable "dini_Get")"

Could you help please ?
Reply
#2

Код:
if(dini_Get(file, "password") == inputtext) //Here is the error
change this too

Код:
  new tmp[256]; tmp = dini_Get(file, "password");
  if(!strcmp(tmp, inputtext, true)) 
  {
    //stuff to do if the password is right
  }
Reply
#3

Thanks alot. Works now, but I don`t understand why you used !strcmp instead of strcmp. I have a little guess tho`. strcmp returns 0 if they are the same, so you used ! to return 1 and continue, right?
Reply
#4

you could use if(strcmp(tmp, inputtext, true) == 0), and it would be the same as !strcmp, and, we want strcmp to return 0, if it returned 1, then the strings aren't the same..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)