[Tutorial] MySQL [R41-2] Registration System
#14

I don't see why you save a cache for later use.

When a player connects, just load his ID in the database that matches his name and load the hashed password and salt, store all 3 (password, salt and ID) in the array pInfo and ShowPlayerDialog to input a password.
Then in that callback (OnDialogResponse), check if the hashed input is the same as the stored hashed password.
If so, send a new query to load the remaining data and store that as well in your pInfo array.

No need to save cache and having to remember to delete it later on.



Also, saving everything inside OnPlayerDisconnect is also questionable.
With so little data, it won't matter that much.
But once you have a huge gamemode, you'll want to split up datasaving.



In my gamemode, I have so much data that my query would be at least 5000 characters long when I would save everything at once in one huge query upon logging out.

Just save whatever changes using a small query and save it immediately.

A player gets money? Save it.
A player receives a scorepoint? Save it.

A player buys a vehicle or a house? Save the money with one query, and update the housedata with a second query.

I'm having a full-blown auction system in my gamemode to auction houses and vehicles to other players, all controlled via one single menu built with textdraws (my vehicle-menu).

Players can place bids on houses and the system also has an automatic system linked to it.
Once a house is put up for auction, the house will automatically transferred to the highest bidder who has the money for it after 7 days, even when both parties (seller and buyer) are offline.
If no bids were there, or nobody has the money for it, the house goes to the bank.
Also vehicles can be browsed that are put up for auction.

House-owners also need to pay a weekly maintenance fee to keep their houses and vehicles.
If they can't afford it, the house is automatically put up for auction along with the vehicles linked to that house.

Doing such a system with queries only inside OnPlayerDisconnect is mindblowing and practically impossible to do.

If I would only save whenever the server shuts down, the server would need several thousand huge queries to update every house on the server,
every house-vehicle (which could be several tens of thousands), just in case something was edited.

Just save whatever needs to be saved at the moment it changes, and use small queries to do it.

Nothing as easy as a function like this:
PHP Code:
// This function is used to give (or take) money to/from the player
Player_GiveMoney(playeridamount)
{
    
// Setup local variables
    
new query[128];
    
// Add the given Money to the player's account
    
APlayerData[playerid][Money] = APlayerData[playerid][Money] + amount;
    
// Also update the client immediately instead of waiting for the GlobalTimer1000 to update it
    
ResetPlayerMoney(playerid);
    
GivePlayerMoney(playeridAPlayerData[playerid][Money]);
    
// Update money for this player in the player's account in MySQL
    
mysql_format(SQL_dbquerysizeof(query), "UPDATE playerdata SET Money = '%i' WHERE UserID = '%i'"APlayerData[playerid][Money], APlayerData[playerid][UserID]);
    
mysql_tquery(SQL_dbquery"""");
    return 
1;

Whenever a player gets money or pays money, his account in the database has also been updated at once.

That way, you can also lose the Corrupt_Check thing, whatever it does.
The data was already saved while playing, logging in fast after a player disconnects won't corrupt data as there is nothing saved in there.



What if your server suddenly crashes? Then nothing would be saved for hours.
You'll lose hours of progress of your players, who in turn will not be happy because they need to spend hours again to get back what was lost.


The only thing I'm saving in my OnPlayerDisconnect callback, is the fuel for all my house-vehicles, as fuel changes every second while driving, this would mean one query per second per vehicle and is too much at once.
And for the rest of the code in there, is to delete the house-vehicles from the server's memory when a player logs out and clearing variables.



When creating an account, add some default values for values to shorten the INSERT query as well upon registering.
Since score, kills, deaths and cash are 0 to begin with, you can simply have MySQL fill in those for you automatically when your table has default values of 0 assigned to those columns.



Also, clearing an array with an enum is much easier than clearing every variable one by one.
You can clear them all at once for a single player.

Instead of doing:
PHP Code:
//Resetting player information.
pInfo[playerid][Kills] = 0;
pInfo[playerid][Deaths] = 0;
pInfo[playerid][PasswordFails] = 0
You can do:
PHP Code:
new clean[ENUM_PLAYER_DATA];
pInfo[playerid] = clean
Not much of a space-saver here, but you never have to edit that code again when you add a variable to the enum.
So less likely to forget to clear one.
Reply


Messages In This Thread
MySQL [R41-2] Registration System - by Variable™ - 29.01.2017, 01:16
Re: MySQL [R41-2] Registration System - by Gammix - 29.01.2017, 03:51
Re: MySQL [R41-2] Registration System - by Variable™ - 29.01.2017, 10:31
Re: MySQL [R41-2] Registration System - by GoldenLion - 29.01.2017, 10:33
Re: MySQL [R41-2] Registration System - by Variable™ - 29.01.2017, 10:51
Re: MySQL [R41-2] Registration System - by GhostHacker9 - 29.01.2017, 11:42
Re: MySQL [R41-2] Registration System - by Variable™ - 29.01.2017, 12:26
Re: MySQL [R41-2] Registration System - by oMa37 - 29.01.2017, 12:30
Re: MySQL [R41-2] Registration System - by princejeet1510 - 29.01.2017, 12:40
Re: MySQL [R41-2] Registration System - by Variable™ - 29.01.2017, 12:45
Re: MySQL [R41-2] Registration System - by DerickClark - 29.01.2017, 14:39
Re: MySQL [R41-2] Registration System - by X337 - 29.01.2017, 14:49
Re: MySQL [R41-2] Registration System - by Gammix - 29.01.2017, 15:07
Re: MySQL [R41-2] Registration System - by PowerPC603 - 29.01.2017, 20:20
Re: MySQL [R41-2] Registration System - by princejeet1510 - 09.02.2017, 14:09
Re: MySQL [R41-2] Registration System - by Variable™ - 09.02.2017, 17:12
Re: MySQL [R41-2] Registration System - by TheLeech - 25.02.2017, 18:26
Re: MySQL [R41-2] Registration System - by Sabur - 27.02.2017, 05:48
Re: MySQL [R41-2] Registration System - by Variable™ - 27.02.2017, 23:02
Re: MySQL [R41-2] Registration System - by Eoussama - 10.03.2017, 11:46
Re: MySQL [R41-2] Registration System - by Variable™ - 10.03.2017, 16:57
Re: MySQL [R41-2] Registration System - by SteSte - 13.07.2017, 01:26
Re: MySQL [R41-2] Registration System - by valerastar - 26.07.2017, 18:18
Re: MySQL [R41-2] Registration System - by Uberanwar - 02.12.2017, 15:48
Re: MySQL [R41-2] Registration System - by AjaxM - 02.12.2017, 15:53
Re: MySQL [R41-2] Registration System - by Uberanwar - 02.12.2017, 16:06
Re: MySQL [R41-2] Registration System - by AjaxM - 02.12.2017, 17:00
Re: MySQL [R41-2] Registration System - by maddinat0r - 02.12.2017, 19:41
Re: MySQL [R41-2] Registration System - by SintaksTR - 02.01.2018, 14:23
Re: MySQL [R41-2] Registration System - by MrCesar - 09.01.2018, 19:58
Re: MySQL [R41-2] Registration System - by Flamehaze7 - 29.01.2018, 20:42
Re: MySQL [R41-2] Registration System - by OptimusBloodHunter - 29.01.2018, 20:59
Re: MySQL [R41-2] Registration System - by RxErT - 13.02.2018, 18:43
Re: MySQL [R41-2] Registration System - by JnniorDoug - 18.02.2018, 21:16
Re: MySQL [R41-2] Registration System - by insus100 - 21.02.2018, 19:14

Forum Jump:


Users browsing this thread: 2 Guest(s)