Created
April 7, 2020 16:08
-
-
Save PatrickGTR/f0ab8a063208e42a84e5e37585704a89 to your computer and use it in GitHub Desktop.
Make your query and code neat.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <YSI_Visual\y_dialog> | |
#include <YSI_Coding\y_hooks> | |
#include <formatex> | |
#include <logger> | |
#include <mysql_prepared> | |
static | |
Statement:stmt_loadPlayerData, | |
gPlayerPasswordHash[MAX_PLAYERS][250]; | |
// Initialise | |
hook OnMySQLConnected(playerid) { | |
stmt_loadPlayerData = MySQL_PrepareStatement(MySQL_GetHandle(), "SELECT kills, deaths FROM players WHERE u_id = ?"); | |
} | |
hook OnPlayerConnect(playerid) { | |
gPlayerPasswordHash[playerid][0] = EOS; | |
} | |
// Global | |
Account_PromptLogin(playerid, const password[], len = sizeof(password)) { | |
if(isnull(gPlayerPasswordHash[playerid])) { | |
strcat(gPlayerPasswordHash[playerid], password, len); | |
} | |
inline PromptLoginResponse(pid, dialogid, response, listitem, string:inputtext[]) { | |
#pragma unused pid, dialogid, listitem | |
// User clicked the 'leave' buton or pressed 'ESC' . | |
if(!response) { | |
Kick(playerid); | |
return; | |
} | |
bcrypt_verify(playerid, "OnPasswordVerify", inputtext, gPlayerPasswordHash[playerid]); | |
} | |
new string[MAX_PLAYER_NAME + 35]; | |
format(string, sizeof(string), "Hello %p! Welcome back to %s", playerid, SERVER_NAME); | |
Dialog_ShowCallback(playerid, | |
using inline PromptLoginResponse, // Handler | |
DIALOG_STYLE_PASSWORD, // Style | |
"Please Login...", // Title | |
string, // Content | |
"Login", // Button Left | |
"Leave"); // Button Right | |
} | |
// Local | |
static Account_LoadData(playerid) { | |
inline OnDataLoad() { | |
new | |
kills, deaths; | |
MySQL_BindResultInt(stmt_loadPlayerData, 0, kills); | |
MySQL_BindResultInt(stmt_loadPlayerData, 1, deaths); | |
if(MySQL_Statement_FetchRow(stmt_loadPlayerData)) { | |
SetPlayerKills(playerid, kills); | |
SetPlayerDeaths(playerid, deaths); | |
static const | |
msg_title[] = "~g~Welcome back!", | |
msg_content[] = "Hello ~p~%p, ~w~Welcome back to ~p~%s. ~n~~n~~y~Enjoy your stay!"; | |
MessageBox_ShowF(playerid, TYPE_MSGBOX, msg_title, msg_content, 8000, playerid, SERVER_NAME); | |
CallLocalFunction("OnPlayerLogin", "i", playerid); // Used in other modules to load other data. | |
dbg("player", "player successfully logged in", | |
_p("username", playerid), | |
_i("uid", GetPlayerAccountID(playerid))); | |
} | |
} | |
MySQL_BindInt(stmt_loadPlayerData, 0, GetPlayerAccountID(playerid)); | |
MySQL_ExecuteParallel_Inline(stmt_loadPlayerData, using inline OnDataLoad); | |
} | |
// BCRypt Callbacks | |
static | |
Player_Attempts[MAX_PLAYERS]; | |
forward OnPasswordVerify(playerid, bool:success); | |
public OnPasswordVerify(playerid, bool:success) { | |
if(!success) { | |
SendErrorMsg(playerid, "Wrong password, try again!"); | |
Account_PromptLogin(playerid, gPlayerPasswordHash[playerid]); | |
dbg("player", "player failed to login", | |
_i("attemps", Player_Attempts[playerid]), | |
_p("username", playerid), | |
_i("uid", GetPlayerAccountID(playerid)) | |
); | |
Player_Attempts[playerid] ++; | |
return; | |
} | |
Account_LoadData(playerid); | |
Player_Attempts[playerid] = 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment