Код:
#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
#define DIALOG_SUCCESS_1 3
#define DIALOG_SUCCESS_2 4
#define PATH "/Accounts/%s.ini"
enum pStats
{
pPass,
pCash,
pAdmin,
pTutorial,
pKills,
pLevel,
Float:Health,
Float:Armour,
Float:pPos_x,
Float:pPos_y,
Float:pPos_z,
pSex,
pSkin,
pAge,
pDeaths
}
new pInfo[MAX_PLAYERS][pStats];
stock SaveAccountStats(playerid)
{
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"Player Data:");
pInfo[playerid][pSkin] = GetPlayerSkin(playerid);
pInfo[playerid][pCash] = GetPlayerMoney(playerid);
pInfo[playerid][pLevel] = GetPlayerScore(playerid);
new
Float:x,
Float:y,
Float:z
;
GetPlayerPos(playerid, x, y, z);
pInfo[playerid][pPos_x] = x;
pInfo[playerid][pPos_y] = y;
pInfo[playerid][pPos_z] = z;
INI_WriteInt(File, "Tutorial", pInfo[playerid][pTutorial]);
INI_WriteInt(File, "Cash", pInfo[playerid][pCash]);
INI_WriteInt(File, "Admin", pInfo[playerid][pAdmin]);
INI_WriteInt(File, "Kills", pInfo[playerid][pKills]);
INI_WriteInt(File, "Level", pInfo[playerid][pLevel]);
INI_WriteFloat(File, "Health", pInfo[playerid][Health]);
INI_WriteFloat(File, "Armour", pInfo[playerid][Armour]);
INI_WriteFloat(File, "Pos_x", pInfo[playerid][pPos_x]);
INI_WriteFloat(File, "Pos_y", pInfo[playerid][pPos_y]);
INI_WriteFloat(File, "Pos_z", pInfo[playerid][pPos_z]);
INI_WriteInt(File, "Sex", pInfo[playerid][pSex]);
INI_WriteInt(File, "Skin", pInfo[playerid][pSkin]);
INI_WriteInt(File, "Age", pInfo[playerid][pAge]);
INI_WriteInt(File, "Deaths", pInfo[playerid][pDeaths]);
INI_Close(File);
}
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
INI_Int("Password",pInfo[playerid][pPass]);
INI_Int("Cash",pInfo[playerid][pCash]);
INI_Int("Admin",pInfo[playerid][pAdmin]);
INI_Int("Kills",pInfo[playerid][pKills]);
INI_Int("Level", pInfo[playerid][pLevel]);
INI_Float("Health", pInfo[playerid][Health]);
INI_Float("Armour", pInfo[playerid][Armour]);
INI_Float("Pos_x", pInfo[playerid][pPos_x]);
INI_Float("Pos_y", pInfo[playerid][pPos_y]);
INI_Float("Pos_z", pInfo[playerid][pPos_z]);
INI_Int("Sex", pInfo[playerid][pSex]);
INI_Int("Skin", pInfo[playerid][pSkin]);
INI_Int("Age", pInfo[playerid][pAge]);
INI_Int("Deaths", pInfo[playerid][pDeaths]);
INI_Int("Tutorial", pInfo[playerid][pTutorial]);
return 1;
}
stock UserPath(playerid)
{
new string[128],playername[MAX_PLAYER_NAME];
GetPlayerName(playerid,playername,sizeof(playername));
format(string,sizeof(string),PATH,playername);
return string;
}
/*Credits to Dracoblue*/
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;
}
public OnPlayerDisconnect(playerid, reason)
{
SaveAccountStats(playerid);
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch( dialogid )
{
case DIALOG_REGISTER:
{
if (!response) return Kick(playerid);
if(response)
{
if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Password",udb_hash(inputtext));
INI_WriteInt(File,"Cash",0);
INI_WriteInt(File,"Admin",0);
INI_WriteInt(File,"Kills",0);
INI_WriteInt(File,"Deaths",0);
INI_WriteInt(File,"Level",0);
INI_WriteInt(File,"Tutorial", 0);
INI_WriteFloat(File,"Pos_x", 0);
INI_WriteFloat(File,"Pos_y", 0);
INI_WriteFloat(File,"Pos_z", 0);
INI_WriteFloat(File,"Health", 100);
INI_WriteFloat(File,"Armour", 0);
INI_WriteInt(File,"Sex", 0);
INI_WriteInt(File,"Skin", 299);
INI_WriteInt(File,"Age", 0);
INI_Close(File);
CancelSelectTextDraw(playerid);
SetSpawnInfo(playerid, 0, 0, 1715.5223,-1904.3020,13.5664, 269.15, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
TextDrawHideForPlayer(playerid, Textdraw0);
TextDrawHideForPlayer(playerid, Textdraw1);
TextDrawHideForPlayer(playerid, Textdraw2);
TextDrawHideForPlayer(playerid, Textdraw3);
TextDrawHideForPlayer(playerid, Textdraw4);
TextDrawHideForPlayer(playerid, Textdraw5);
TextDrawHideForPlayer(playerid, login);
TextDrawHideForPlayer(playerid, Textdraw7);
TextDrawHideForPlayer(playerid, register);
TextDrawHideForPlayer(playerid, Textdraw9);
TextDrawHideForPlayer(playerid, Textdraw10);
TextDrawHideForPlayer(playerid, Textdraw11);
TextDrawHideForPlayer(playerid, Textdraw12);
TextDrawHideForPlayer(playerid, Textdraw13);
TextDrawHideForPlayer(playerid, Textdraw14);
ShowPlayerDialog(playerid, DIALOG_SEX, DIALOG_STYLE_MSGBOX, "Gender Selection", "What is your Sex/Gender?", "Male", "Female");
}
}
case DIALOG_LOGIN:
{
if ( !response ) return Kick ( playerid );
if( response )
{
if(udb_hash(inputtext) == pInfo[playerid][pPass])
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
GivePlayerMoney(playerid, pInfo[playerid][pCash]);
ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Login Authentication: CVRP",""COL_GREEN"You have successfully logged in!","Ok","");
}
else
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login Authentication: CVRP",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Quit");
}
CancelSelectTextDraw(playerid);
return 1;
}
}
//Don't worry about closing OnDialogResponse, it is already closed.
public OnPlayerClickTextDraw(playerid, Text:clickedid)
{
if(clickedid == register)
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""COL_WHITE"Registeration Console",""COL_WHITE"Welcome to Crystal Valley Roleplay \n Please fill your password below to continue:","Register","Quit");
}
else if(clickedid == login)
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,""COL_WHITE"Authentication Console",""COL_WHITE"Welcome back to Crystal Valley Roleplay! \n Please fill out your password to continue:","Login","Quit");
}
return 1;
}