Need help with accessing string arrays
#1

Hello there!
I tried to make a simple /register and /login script with dini.

Here's the script:

Код:
	

public OnPlayerCommandText(playerid, cmdtext[])
{
	dcmd(register, 8, cmdtext);
	dcmd(login, 5, cmdtext);
	return 1;
}


dcmd_register(playerid, params[])
{
	if (dini_Exists(gPlayerfile[playerid]))
	{	
		SendClientMessage(playerid, 0xFF0000FF, "You have already registered.");
		return 0;
	}
	else 
	{
		if (!params[0]) 
		{
			SendClientMessage(playerid, 0xFF0000FF, "Usage: /register <password>");
			return 0;
		}
		else 
		{
			dini_Create(gPlayerfile[playerid]);
			dini_Set(gPlayerfile[playerid], "Password", params);
			SendClientMessage(playerid, 0x00FF00FF, "You have successfully registered. Proceed to login thanks.");
			return 1;
		}
	}
}

dcmd_login(playerid, params[])
{
	if (!dini_Exists(gPlayerfile[playerid]))
	{
		SendClientMessage(playerid, 0xFF0000FF, "You have not registered.");
		return 0;
	}
	else if (gPlayerlogged[playerid])
	{
		SendClientMessage(playerid, 0x00FF00FF, "You have already logged in.");
		return 0;
	}
	else
	{
		new pw[1000];
		pw = dini_Get(gPlayerfile[playerid], "Password");
		if (params == pw) // THIS LINE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
		{
			gPlayerlogged[playerid] = 1;
			SendClientMessage(playerid, 0x00FF00FF, "Login successful.");
			return 1;
		}
		else
		{
			SendClientMessage(playerid, 0xFF0000FF, "Wrong password.");
			return 0;
		}
	}
}
The error says that params and pw should be indexed. Since the password is a string, I can't index it to a specific character. This may be too obvious, but I'm a newb. So please help
Thanks!

EDIT: Btw the register part works just fine. When I read the file, the password is set correctly.
Reply
#2

Strings are compared with the function 'strcmp'

You save/load passwords unencryted?
Reply
#3

Quote:
Originally Posted by 0rb
Strings are compared with the function 'strcmp'

You save/load passwords unencryted?
Yes :/ Is that unsafe?
Btw I'll look into some easy strcmp tutorials :S
Thanks.
Reply
#4

I'd advise you to use sscanf, however this is commonly used for 2 params or more.
Reply
#5

Well, shouldn't this work?

Код:
		new pw[1000];
		pw = dini_Get(gPlayerfile[playerid], "Password");
        gPlayerlogged[playerid] = 1;
		for (new x = 0; x<=(sizeof(pw)); x++)
		{
			if (params[x] != pw[x]) gPlayerlogged[playerid] = 0;
		}
I know it could be done alot easier, but I can't use strcmp :S
Reply
#6

Quote:
Originally Posted by iMr
I know it could be done alot easier, but I can't use strcmp :S
pawn Код:
{
    new pw[128];
    pw = dini_Get(gPlayerfile[playerid], "Password");
    if ( !strcmp(params, pw, true) ) // THIS LINE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    {
        gPlayerlogged[playerid] = 1;
        SendClientMessage(playerid, 0x00FF00FF, "Login successful.");
        return 1;
    }
    else
    {
        SendClientMessage(playerid, 0xFF0000FF, "Wrong password.");
        return 0;
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)