Need an advice about registration/saving stats system
#1

Hello dear forum users...
Here I am again, and guess what... I need your help again...

Currently I am using this system to save accounts and stats

Code:
stock OnPlayerLogin( playerid, password[] )
{
  new string2[ 64 ], playername2[ MAX_PLAYER_NAME ];

  GetPlayerName(playerid, playername2, sizeof(playername2));
	format(string2, sizeof(string2), "/Accounts/%s.ini", playername2);

	new File: UserFile = fopen(string2, io_read);
	if ( UserFile )
	{
	  new PassData[256];
	  new keytmp[256], valtmp[256];
	  fread( UserFile , PassData , sizeof( PassData ) );
	  keytmp = ini_GetKey( PassData );
	  if( strcmp( keytmp , "Password" , true ) == 0 )
		{
			valtmp = ini_GetValue( PassData );
			strmid(PlayerInfo[playerid][ pPassword ], valtmp, 0, strlen(valtmp)-1, 255);
		}
		if(strcmp(PlayerInfo[playerid][ pPassword ],password, true ) == 0 )
		{
			  new key[ 256 ] , val[ 256 ];
			  new Data[ 256 ];
			  while ( fread( UserFile , Data , sizeof( Data ) ) )
				{
					key = ini_GetKey( Data );
			  	if( strcmp( key , "Adminlevel" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][ pAdmin ] = strval( val ); }
			    if( strcmp( key , "Money" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][ pCash ] = strval( val ); }
			    if( strcmp( key , "Score" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][ pScore ] = strval( val ); }
			    if( strcmp( key , "Kills" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][ pKills ] = strval( val ); }
			    if( strcmp( key , "Deaths" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][ pDeaths ] = strval( val ); }

	}
	return 1;
}
Code:
stock OnPlayerRegister( playerid, password[] )
{
	if (IsPlayerConnected(playerid)) {
		new string3[32], playername3[MAX_PLAYER_NAME];
		GetPlayerName(playerid, playername3, sizeof(playername3));
		format(string3, sizeof(string3), "/Accounts/%s.ini", playername3);
		new ip[ 20 ];
		GetPlayerIp(playerid,ip,sizeof(ip));
		new File: hFile = fopen(string3, io_write);
		if (hFile) {
		  strmid(PlayerInfo[playerid][ pPassword ], password, 0, strlen(password), 255);
		  new var[128];
		  format(var, 128, "Password=%s\n", PlayerInfo[playerid][ pPassword ]);fwrite(hFile, var);
	    format(var, 128, "Adminlevel=%d\n",PlayerInfo[playerid][ pAdmin ]);fwrite(hFile, var);
		  format(var, 128, "Money=%d\n",PlayerInfo[playerid][ pCash ]);fwrite(hFile, var);
			format(var, 128, "Score=%d\n",PlayerInfo[playerid][ pScore ]);fwrite(hFile, var);
			format(var, 128, "Kills=%d\n",PlayerInfo[playerid][ pKills ]);fwrite(hFile, var);
			format(var, 128, "Deaths=%d\n",PlayerInfo[playerid][ pDeaths ]);fwrite(hFile, var);
			fclose(hFile);
			SendClientMessage(playerid, COLOR_FINALSCORE, "Nickname registered.");
			SendClientMessage(playerid, COLOR_FINALSCORE, "Type /login (password) now.");
			ResetPlayerMoney(playerid);
		}
	}
	return 1;
}
Code:
stock OnPlayerUpdate( playerid )
{
	if (IsPlayerConnected(playerid))
	{
		if (PlayerInfo[playerid][ pLogged ] ==1)
		{
      new string3[32];
			new playername3[MAX_PLAYER_NAME];
			GetPlayerName(playerid, playername3, sizeof(playername3));
			format(string3, sizeof(string3), "/Accounts/%s.ini", playername3);
			new ip[ 20 ];
		  GetPlayerIp(playerid,ip,sizeof(ip));
			new File: hFile = fopen(string3, io_write);
			if (hFile)
			{
				new var[128];
				format(var, 128, "Password=%s\n", PlayerInfo[playerid][pPassword]);fwrite(hFile, var);
				format(var, 128, "AdminLevel=%d\n",PlayerInfo[playerid][pAdmin]);fwrite(hFile, var);
				PlayerInfo[playerid][pCash] = AC_GetPlayerMoney(playerid);
				format(var, 128, "Money=%d\n",PlayerInfo[playerid][pCash]);fwrite(hFile, var);
				PlayerInfo[playerid][pScore] = GetPlayerScore(playerid);
				format(var, 128, "Score=%d\n",PlayerInfo[playerid][pScore]);fwrite(hFile, var);
				PlayerInfo[playerid][pKills] = GetPlayerScore(playerid);
				format(var, 128, "Kills=%d\n",PlayerInfo[playerid][pKills]);fwrite(hFile, var);
				format(var, 128, "Deaths=%d\n",PlayerInfo[playerid][pDeaths]);fwrite(hFile, var);
				fclose(hFile);
			}
		}
		new CurVirtualWorld[MAX_PLAYERS];
    CurVirtualWorld[playerid] = GetPlayerVirtualWorld(playerid);
    if(CurVirtualWorld[playerid] != CurrentVirtualWorld[playerid])
    {
    OnPlayerVirtualWorldChange(playerid, CurVirtualWorld[playerid], CurrentVirtualWorld[playerid]);
    CurrentVirtualWorld[playerid] = CurVirtualWorld[playerid];
    }
	}
	return 1;
}
OnPlayerRegister is called when I'm using /register command
OnPlayerLogin is called when I'm using /login command
OnPlayerUpdate is called OnGameModeExit and OnPlayerDisconnect....
_________________________________________________

So I heard there are some other ways of doing same thing, just faster!
I need an advice which registration system to use, djson, dini or any other... And please keep it mind that it needs to support INI files reading, as I'm not going to rewrite all files currently registered on my server...

Please help!
Reply
#2

Anyone?
I just need an advice which registration system to use... to improve my code, make it faster...
Reply
#3

OnPlayerUpdate is already a callback for SA-MP, it's called about 30 times a second, I suggest you change the name of that callback to something else.
Reply
#4

Hmm I use it as stock function, not public.. so it doesn't make it default... Does it!?

And it isn't called 30 times a second, only OnPlayerDisconnect and OnGameModeExit

So which registration system should I use, I still didn't get my asnwer..
Reply
#5

OnPlayerUpdate is called PLAYERS_ONLINE * 20+random(10) per second, not at OnPlayerDisconnect and OnGameModeExit!

So dont use second, or it will lag so only use it with a timer and use first if you want
Reply
#6

I used it as custom stock OnPlayerUpdate function and called it in two places only...

But still I need answer on my question, what is the best and fastest way of creating/saving accounts and stats...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)