PHP код:
enum pInfo
{
PlayerPass,
PlayerMoney,
PlayerLevel,
PlayerScore,
PlayerKills,
PlayerDeaths,
PlayerBanned,
PlayerIP[16]
}
new PlayerInfo[PLAYERS][pInfo];
forward LoadPlayer_data(playerid,name[],value[]);
public LoadPlayer_data(playerid,name[],value[])
{
INI_Int("password",PlayerInfo[playerid][PlayerPass]);
INI_Int("money",PlayerInfo[playerid][PlayerMoney]);
INI_Int("adminlevel",PlayerInfo[playerid][PlayerLevel]);
INI_Int("scores",PlayerInfo[playerid][PlayerScore]);
INI_Int("kills",PlayerInfo[playerid][PlayerKills]);
INI_Int("deaths",PlayerInfo[playerid][PlayerDeaths]);
INI_Int("playerbanned",PlayerInfo[playerid][PlayerBanned]);
INI_String("playerip",PlayerInfo[playerid][PlayerIP], 16);
return 1;
}
stock AccountsPath(playerid)
{
new string[128],playername[MAX_PLAYER_NAME];
GetPlayerName(playerid,playername,sizeof(playername));
format(string,sizeof(string),UserFiles,playername);
return string;
}
stock udb_hash(buf[]) {
new length=strlen(buf);
new s1 = 1;
new s2 = 0;
new n;
for (n=0; n<length; n++)
{
s1 = (s1 + buf[n]) % 65521;
s2 = (s2 + s1) % 65521;
}
return (s2 << 16) + s1;
}
//OnplayerConnect
new str[270];
if (isconnected[playerid] == 0)
{
isconnected[playerid] = 1;
SetPlayerColor(playerid, COLOR_PLAYER);
SetPlayerVirtualWorld(playerid, 1);
new playername[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername, MAX_PLAYER_NAME);
if(fexist(AccountsPath(playerid)))
{
INI_ParseFile(AccountsPath(playerid), "LoadPlayer_%s", .bExtra = true, .extra = playerid);
format(str, sizeof(str), "Welcome to {00FFF3}%s.\n\n{FFFF00}Account:{FFFFFF} %s\n\nPlease enter your password below:", SV_NAME, RPN(playerid));
ShowPlayerDialog2(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""COL_RED"Login", str, "Login", "Cancel");
SendPlayerFormattedText(playerid, COLOR_LBLUE, "Welcome back %s to {FF33CC}"SV_NAME"{FFFFFF}.", playername, "");
playerlogged[playerid] = 1;
}
else
{
format(str, sizeof(str), "Welcome to {FFB900}%s.\n\n{FFFF00}Account:{FFFFFF} %s\n\nRegister an account to play.\n\nPlease put the password below:", SV_NAME, RPN(playerid));
ShowPlayerDialog2(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_GREEN"Register", str, "Continue", "Cancel");
SendPlayerFormattedText(playerid, COLOR_WHITE, "Welcome %s to {FF33CC}"SV_NAME"{FFFFFF}.", playername, "");
playerlogged[playerid] = 1;
}
return 0;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
new string[270], strings[270], playername[25];
GetPlayerName(playerid, playername, MAX_PLAYER_NAME);
if(dialogid == DIALOG_REGISTER)
{
if (!response) return SendClientMessage(playerid, COLOR_GREY,"[Server]: You must register/login to spawn.");
if(response)
{
if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_GREEN"Register",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Cancel");
new pIP[16];
GetPlayerIp(playerid, pIP, sizeof(pIP));
new INI:File = INI_Open(AccountsPath(playerid));
INI_SetTag(File,"Player Data");
INI_WriteInt(File,"password",udb_hash(inputtext));
INI_WriteInt(File,"money", REGISTER_MONEY);
INI_WriteInt(File,"adminlevel",0);
INI_WriteInt(File,"scores", REGISTER_SCORE);
INI_WriteInt(File,"kills",0);
INI_WriteInt(File,"deaths",0);
INI_WriteInt(File,"playerbanned",0);
INI_WriteString(File, "playerip", pIP);
INI_Close(File);
GivePlayerMoney(playerid, REGISTER_MONEY);
GivePlayerScore(playerid, REGISTER_SCORE);
playerlogged[playerid] = 1;
format(string, sizeof string,"%s has registered a new account", playername);
SendClientMessageToAll(COLOR_YELLOW, string);
format(strings, sizeof strings,"%s Welcome in "SV_NAME", /rules and /help", playername);
SendClientMessageToAll(COLOR_YELLOW, strings);
}
}
if(dialogid == DIALOG_LOGIN)
{
if(!response) return SendClientMessage(playerid, COLOR_GREY,"[Server]: You must register/login to spawn.");
if(response)
{
if(num_hash(inputtext) == PlayerInfo[playerid][PlayerPass])
{
//INI_ParseFile(AccountsPath(playerid), "LoadPlayer_%s", .bExtra = true, .extra = playerid);
SetPlayerScore(playerid, PlayerInfo[playerid][PlayerScore]);
GivePlayerMoney(playerid, PlayerInfo[playerid][PlayerMoney]);
playerlogged[playerid] = 1;
SendClientMessage(playerid, COLOR_GREEN,"You have successfully logged in");
}
else
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_RED"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Cancel");
}
return 1;
}
}
return 1;
}