Problem with dini_Get("file", variable);
#1

Код:
 	    GetPlayerName(playerid, name, sizeof(name));
 		format(string, sizeof(string), "/users/%s.save", udb_encode(name));
 		new login;
		login=dini_Get(string,"login");
		if(login==1)
			{
			SendClientMessage(playerid, COLOR_LIGHTBLUE, "SERVER: You are already logged in.");
			return 1;
			}
And i get this error on
Код:
login=dini_Get(string,"login");
Код:
error 006: must be assigned to an array
Reply
#2

IIRC dini_Get is for strings. You can't store a string in a single cell. You should probably use dini_IntGet or smth liek that.
Reply
#3

There is dini_Set and dini_IntSet but there is only one dini_Get.
Reply
#4

Then it's dini_Int.

But i encourage you to not use dini, it's slow as hell.
Reply
#5

Thanks, i did not notice. There is a big mess in dini.
Reply
#6

Hey, i got a problem again.

Now i can't check if the password that the player is writing is the same that is in the file:

Код:
if(strcmp(cmd, "/login", true) == 0)
	{
	GetPlayerName(playerid, name, sizeof(name));
	format(file, sizeof(file), "/users/%s.save", udb_encode(name));
	if(!dini_Exists(file))
		{
		SendClientMessage(playerid, COLOR_LIGHTBLUE, "SERVER: Account does not exist, register with /register.");
		return 1;
		}
	else if(dini_Exists(file))
 		{
 		tmp=strtok(cmdtext, idx);
		if(dini_Int(file,"login")==1)
			{
			SendClientMessage(playerid, COLOR_LIGHTBLUE, "SERVER: You are already logged in.");
			return 1;
			}
		if(!strlen(tmp))
			{
			SendClientMessage(playerid, COLOR_LIGHTBLUE, "SERVER: You did not write a password.");
			return 1;
			}
		else if(strlen(tmp))
		  {
		  if(dini_Get(file,"password")!=tmp)
		  	{
		  	SendClientMessage(playerid, COLOR_LIGHTBLUE, "SERVER: Incorrect password.");
		  	}
          else if(dini_Get(file,"password")==tmp)
		  	{
            dini_Int(file,"login",1);
		  	SendClientMessage(playerid, COLOR_LIGHTBLUE, "SERVER: You are now logged in.");
		  	}
I get error on these:

Код:
if(dini_Get(file,"password")!=tmp)
Код:
if(dini_Get(file,"password")==tmp)
Код:
error 033: array must be indexed (variable "dini_Get")
Код:
error 033: array must be indexed (variable "dini_Get")
Reply
#7

pawn Код:
if(dini_Get(file,"password")!=tmp)
to
pawn Код:
if(!strcmp(dini_Get(file,"password"),tmp))
Reply
#8

Quote:
Originally Posted by paytas
Then it's dini_Int.

But i encourage you to not use dini, it's slow as hell.
Depends on the usage. You should of course not read/write data all the time, and not all in one big file. If you need a writer/reader for that case, try djson or use native db or file functions.

@ronyx69
Why do you store, if somebody is logged in, in a dini-file? You should better use an array for that, because what is if the user disconnects and somebody reconnects with your nickname?

Have fun coding.
Draco
Reply
#9

Thanks, yezizhu. It's working.

DracoBlue: The storing is because i will make an auto-login.
Reply
#10

Quote:
Originally Posted by ronyx69
Thanks, yezizhu. It's working.

DracoBlue: The storing is because i will make an auto-login.
This does not fix the issue I posted. Only an online player can be logged in. What if I connect with your nickname and the ini-file has login=1 for you: am I logged in then?

- Draco
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)