16.02.2020, 20:32
Good evening everyone, I need your help. Is there a guide I have to follow to create a MySQL database optimized to the maximum, avoiding unnecessary lines etc? Please help me. Thanks in advance.
Depends on which is your use. Registration? If so, just save username, password and salt (if you have it).
|
enum E_PLAYERS
{
ID,
Name[MAX_PLAYER_NAME],
Password[65],
Salt[17],
Kills
}
new Player[MAX_PLAYERS][E_PLAYERS];
for(new i = 0; i < 16; i++) Player[playerid][Salt][i] = random(94) + 33;
SHA256_PassHash(inputtext, Player[playerid][Salt], Player[playerid][Password], 65);
new regQuery[200];
mysql_format(g_SQL, regQuery, sizeof regQuery, "INSERT INTO `your_accounts_table` (`Username`, `Password`, `Salt`) VALUES ('%e', '%s', '%e')", ReturnPlayerName(playerid), Player[playerid][Password], Player[playerid][Salt]);
mysql_tquery(g_SQL, regQuery, "OnPlayerRegister", "d", playerid);
forward OnPlayerRegister(playerid)
public OnPlayerRegister(playerid)
{
Player[playerid][ID] = cache_insert_id();
return 1;
}
new hashed_pass[65];
SHA256_PassHash(inputtext, Player[playerid][Salt], hashed_pass, 65);
if(strcmp(hashed_pass, Player[playerid][Password]) == 0)
{
//Password is correct, load your player's stats here
LoadPlayerStats(playerid);
}
LoadPlayerStats(playerid)
{
cache_get_value_int(0, "ID", Player[playerid][ID]);
cache_get_value_int(0, "Kills", Player[playerid][Kills]);
//give money, set skin etc.
}
if(killerid != INVALID_PLAYER_ID)
{
Player[killerid][Kills] ++;
new upKillsQuery[70];
mysql_format(g_SQL, upKillsQuery, sizeof(upKillsQuery), "UPDATE `players` SET `Kills` = %d WHERE `ID` = %d", Player[playerid][Kills], Player[playerid][ID]);
mysql_query(g_SQL, upKillsQuery);
}
stock SaveAccountStats(playerid)
{
//Insert your UPDATE query here for everything
return 1;
}