13.07.2012, 01:04
(
Последний раз редактировалось Swyft™; 14.07.2012 в 01:31.
)
It's all good. thanks for helping
#define DIALOG_LOGIN 1
#define DIALOG_REGISTER 2
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case DIALOG_LOGIN :
{
if(!response) return Kick(playerid);
if(isnull(inputtext)) return ShowPlayerDialog(playerid,DIALOG_LOGIN,3,"Login","You entered invalid password\nEnter your password","OK","CANCEL");
new Query[256], pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
mysql_real_escape_string(pName, pName);
format(Query, sizeof Query, "SELECT * FROM `accounts` WHERE `Name` = '%s' LIMIT 1", pName);
mysql_query(Query);
mysql_store_result();
if(!mysql_num_rows())
{
SendClientMessage(playerid, COLOR_RED, "[ERROR]{FFFFFF} You're not registered! Use \"/register\" to register an account!");
mysql_free_result();
return 1;
}
mysql_free_result();
WP_Hash(Query, 129, inputtext);
format(Query, sizeof Query, "SELECT * FROM `accounts` WHERE `Name` = '%s' AND `Password` = '%s' LIMIT 1", pName, Query);
mysql_query(Query);
mysql_store_result();
if(!mysql_num_rows())
{
SetPVarInt(playerid, "LoginWarns", GetPVarInt(playerid, "LoginWarns") + 1);
if(GetPVarInt(playerid, "LoginWarns") == 3)
{
format(Query, sizeof Query, "[PLAYER] %s has been kicked for 3 wrong login attempts!", pName);
SendClientMessageToAll(COLOR_RED, Query);
Kick(playerid);
}
else
{
format(Query, sizeof Query, "[ERROR]{FFFFFF} Wrong password! Attempt %i out of 3.", GetPVarInt(playerid, "LoginWarns"));
SendClientMessage(playerid, COLOR_RED, Query);
}
return 1;
}
mysql_fetch_row(Query);
new values[5];
sscanf(Query, "p<|>{s[24]s[129]s[16]}a<i>[5]", values); //Enjoy editing.
SetPVarInt(playerid, "Admin", values[0]);
GivePlayerMoney(playerid, values[1]);
SetPlayerScore(playerid, values[2]);
SetPVarInt(playerid, "Kills", values[3]);
SetPVarInt(playerid, "Deaths", values[4]);
mysql_free_result();
SetPVarInt(playerid, "Logged", 1);
SendClientMessage(playerid, COLOR_BLUE, "[ACCOUNT]{FFFFFF} Succesfully logged in!");
//Ip setting
GetPlayerIp(playerid, Query, 16);
format(Query, sizeof Query, "UPDATE `accounts` SET `IP` = '%s' WHERE `Name` = '%s' LIMIT 1", Query, pName);
mysql_query(Query);
return 1;
}
case DIALOG_REGISTER:
{
if(!response) return Kick(playerid);
if(GetPVarInt(playerid, "Logged")) return SendClientMessage(playerid, COLOR_RED,"[ERROR]{FFFFFF} You are already logged in!");
if(isnull(inputtext)) ShowPlayerDialog(playerid,DIALOG_REGISTER,3,"Login","You entered invalid password\nEnter your password","OK","CANCEL");
new Query[320], pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
mysql_real_escape_string(pName, pName);
format(Query, sizeof Query, "SELECT * FROM `accounts` WHERE `Name` = '%s' LIMIT 1", pName);
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows())
{
SendClientMessage(playerid, COLOR_RED, "[ERROR]{FFFFFF} An account already exists under that name! Use \"/login\" to log in!");
mysql_free_result();
return 1;
}
mysql_free_result();
WP_Hash(Query, 129, inputtext);
new IP[16];
GetPlayerIp(playerid, IP, 16);
format(Query, sizeof Query, "INSERT INTO `accounts` (Name, Password, IP, Admin, Money, Score, Kills, Deaths) VALUES ('%s', '%s', '%s', %i, %i, %i, %i, %i)",
pName,
Query,
IP,
GetPVarInt(playerid, "Admin"),
GetPlayerMoney(playerid),
GetPlayerScore(playerid),
GetPVarInt(playerid, "Kills"),
GetPVarInt(playerid, "Deaths"));
mysql_query(Query);
SetPVarInt(playerid, "Logged", 1);
SendClientMessage(playerid, COLOR_BLUE, "[ACCOUNT]{FFFFFF} Succesfully registered and automatically logged in!");
return 1;
}
}
return 1;
}
public OnPlayerConnect(playerid)
{
new Query[256], pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof pName);
mysql_real_escape_string(pName, pName);
format(Query, sizeof Query, "SELECT * FROM `accounts` WHERE `Name` = '%s' LIMIT 1", pName);
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() != 0)
{
new IP[16];
GetPlayerIp(playerid, IP, sizeof IP);
format(Query, sizeof Query, "SELECT * FROM `accounts` WHERE `Name` = '%s' and IP = '%s' LIMIT 1", pName, IP);
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() != 0)
{
mysql_fetch_row(Query);
new values[5];
sscanf(Query, "p<|>{s[24]s[129]s[16]}a<i>[5]", values);
SetPVarInt(playerid, "Admin", values[0]);
GivePlayerMoney(playerid, values[1]);
SetPlayerScore(playerid, values[2]);
SetPVarInt(playerid, "Kills", values[3]);
SetPVarInt(playerid, "Deaths", values[4]);
SetPVarInt(playerid, "Logged", 1);
SendClientMessage(playerid, COLOR_BLUE, "[ACCOUNT]{FFFFFF} Welcome back! You've been automatically logged in.");
}
else ShowPlayerDialog(playerid,DIALOG_LOGIN,3,"Login","Enter your password","OK","CANCEL");
}
else howPlayerDialog(playerid,DIALOG_REGISTER,3,"Register","You are new here\nEnter a password to register","OK","CANCEL");
return 1;
}