I believe I do, actually...
pawn Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case 1:
{
if(!response) // If the player hit "exit" we're going to kick them
{
SendClientMessage(playerid, COLOR_RED, "You selected exit, therefore you were kicked.");
Kick(playerid);
}
else if(strlen(inputtext) == 0)
{
SendClientMessage(playerid, COLOR_SYSTEM, "You must input the password to your account! If this is not your account, come back with a new name!");
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Login / Authentication Process", "Hello there!\n\nPlease enter your password to authenticate.", "Login", "Cancel");
}
else
{
new buf[129];
GetFromAccount(PlayerStatistics[playerid][pDatabaseID], "Password", PlayerStatistics[playerid][pPassword]);
WP_Hash(buf, sizeof (buf), inputtext);
if(!strcmp(buf, PlayerStatistics[playerid][pPassword], true))
{
PlayerStatistics[playerid][pAuth] = 1;
LoadAccountVariables(playerid);
format(string, sizeof(string), "You have successfully logged in, %s!", GetName(playerid));
SendClientMessage(playerid, COLOR_ORANGE, string);
SetPlayerMoney(playerid, PlayerStatistics[playerid][pMoney]);
SetPlayerScore(playerid, PlayerStatistics[playerid][pScore]);
format(string, sizeof(string), "%s (%d)\n Score: %i", GetName(playerid), playerid, GetPlayerScore(playerid));
pNameTag[playerid] = Create3DTextLabel(string, COLOR_YELLOW, 30.0, 40.0, 50.0, 15.0, -1, 1);
Attach3DTextLabelToPlayer(pNameTag[playerid], playerid, 0.0, 0.0, 0.2);
}
else
{
SendClientMessage(playerid, COLOR_WHITE, "Incorrect password. Please try again!");
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Login / Authentication Process", "Hello there!\n\nPlease enter your password to authenticate.", "Login", "Cancel");
}
}
}
case 2:
{
if(!response) // If the player hit "exit" we're going to kick them
{
SendClientMessage(playerid, COLOR_SYSTEM, "You selected exit, therfore you have been kicked!");
Kick(playerid);
}
else if(strlen(inputtext) < 4 || strlen(inputtext) > 30)
{
SendClientMessage(playerid, COLOR_SYSTEM, "Your password must be at least 4, but less than 30 alhpanumeric characters.");
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Registration Process", "Hello there!\n\nPlease enter a password to register.", "Authenticate", "Cancel");
}
else
{
new buf[130], EscapedName[MAX_PLAYER_NAME];
mysql_real_escape_string(GetName(playerid), EscapedName);
WP_Hash(buf, sizeof (buf), inputtext);
format(Query, sizeof(Query), "INSERT INTO `Accounts` (Username, Password) VALUES('%s', '%s')", EscapedName, buf);
mysql_query(Query);
JustRegistered = 1;
PlayerStatistics[playerid][pAuth] = 1;
format(string, sizeof(string), "You have automatically logged in, %s!", GetName(playerid));
SendClientMessage(playerid, COLOR_ORANGE, string);
SpawnPlayer(playerid);
}
}
}
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}
// -------------------- [MySQL Stocks and Publics] ------------------------ //
stock ResetPlayerVariables(playerid)
{
PlayerStatistics[playerid][pDatabaseID] = 0;
PlayerStatistics[playerid][pAdminLevel] = 0;
PlayerStatistics[playerid][pMoney] = 0;
PlayerStatistics[playerid][pAuth] = 0;
PlayerStatistics[playerid][pPositionX] = 0.00;
PlayerStatistics[playerid][pPositionY] = 0.00;
PlayerStatistics[playerid][pPositionZ] = 0.00;
return 1;
}
stock InitPlayerConnection(playerid)
{
ResetPlayerVariables(playerid);
new EscapedName[MAX_PLAYER_NAME];
mysql_real_escape_string(GetName(playerid), EscapedName);
format(Query, sizeof(Query), "SELECT `UserID` FROM `Accounts` WHERE `Username` = '%s'", EscapedName);
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() >= 1)
{
if(mysql_num_rows() >= 2)
{
mysql_free_result();
SendClientMessage(playerid, COLOR_WHITE, "There seems to be duplicates of your account, please contact a high-level admin.");
Kick(playerid);
}
else
{
PlayerStatistics[playerid][pDatabaseID] = mysql_fetch_int();
mysql_free_result();
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Login / Authentication Process", "Hello there!\n\nPlease enter your password to authenticate.", "Login", "Cancel");
SendClientMessage(playerid, COLOR_WHITE, "Your account exists. Please enter your password to proceed.");
}
}
else
{
mysql_free_result();
SendClientMessage(playerid, COLOR_WHITE, "Your account does not yet exist. Enter a password to register one!");
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Registration Process", "Hello there!\n\nPlease enter a password to register.", "Register", "Cancel");
}
}
stock SavePlayerAccount(playerid)
{
if(PlayerStatistics[playerid][pAuth] == 1)
{
PlayerStatistics[playerid][pScore] = GetPlayerScore(playerid);
PlayerStatistics[playerid][pMoney] = GetPlayerMoney(playerid);
PlayerStatistics[playerid][pSkin] = GetPlayerSkin(playerid);
format(Query, sizeof(Query), "UPDATE `Accounts` SET `Password` = '%s', `AdminLevel` = '%d', `AdminDuty` = '%d', `Money` = '%d', `Score` = '%d', `Skin` = '%d' WHERE `UserID` = '%d'", PlayerStatistics[playerid][pPassword], PlayerStatistics[playerid][pAdminLevel], PlayerStatistics[playerid][pAdminDuty], PlayerStatistics[playerid][pMoney], PlayerStatistics[playerid][pScore], PlayerStatistics[playerid][pSkin], PlayerStatistics[playerid][pDatabaseID]);
mysql_query(Query);
GetPlayerPos(playerid, PlayerStatistics[playerid][pPositionX], PlayerStatistics[playerid][pPositionY], PlayerStatistics[playerid][pPositionZ]);
format(Query, sizeof(Query), "UPDATE `Accounts` SET `PositionX` = '%f', `PositionY` = '%f', `PositionZ` = '%f' WHERE `UserID` = '%d'", PlayerStatistics[playerid][pPositionX], PlayerStatistics[playerid][pPositionY], PlayerStatistics[playerid][pPositionZ], PlayerStatistics[playerid][pDatabaseID]);
mysql_query(Query);
}
return 1;
}
stock LoadAccountVariables(playerid)
{
if(IsPlayerConnected(playerid))
{
format(Query, sizeof(Query), "SELECT * FROM `Accounts` WHERE `UserID` = %d", PlayerStatistics[playerid][pDatabaseID]);
mysql_query(Query);
mysql_store_result();
mysql_fetch_row(Query, "|");
sscanf(Query, "e<p<|>ds[23]s[129]dddddfff>", PlayerStatistics[playerid]);
SpawnPlayer(playerid);
}
else
{
printf("[MySQL ERROR] LoadAccountVariables() was called, but to a non-connected ID.", playerid);
}
mysql_free_result();
}
stock GetFromAccount(dbid, obtaining[], holdingvar[])
{
format(Query, sizeof(Query), "SELECT `%s` FROM `Accounts` WHERE `UserID` = '%d'", obtaining, dbid);
mysql_query(Query);
mysql_store_result();
if(mysql_fetch_row(holdingvar) == 1)
{
mysql_free_result();
}
return 1;
}