Код:
#include <a_samp>
#include <y_ini>
#define Dir "/Data/%s.ini"
#define DIALOG_REGISTER 100
#define DIALOG_LOGIN 101
native WP_Hash(buffer[], len, const str[]);
enum PlayerInfo
{
Password,
Registered,
Loggedin,
Kills,
Deaths,
Level,
VIPLevel
};
new pInfo[MAX_PLAYERS][PlayerInfo];
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
INI_Int("Registered",pInfo[playerid][Registered]);
INI_Int("Kills",pInfo[playerid][Kills]);
INI_Int("Deaths",pInfo[playerid][Deaths]);
INI_Int("Level",pInfo[playerid][Level]);
INI_Int("VIPLevel",pInfo[playerid][VIPLevel]);
return 1;
}
public OnPlayerConnect(playerid)
{
if(fexist(UserData(playerid)))
{
new string[20];
INI_ParseFile(UserData(playerid), "LoadUser_data", .bExtra = true, .extra = playerid);
format(string,sizeof(string)," Welcome back");
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,string," Your account is already registered\nKindly type your password below to login.","Login","Quit");
}
else
{
new string[20];
format(string,sizeof(string),"Welcome to server");
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,string,"Welcome to Server please type your password below to register.","Register","Quit");
}
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
pInfo[playerid][Deaths]++;
pInfo[killerid][Kills]++;
return 1;
}
public OnPlayerDisconnect(playerid)
{
new INI:File = INI_Open(UserData(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Registered",pInfo[playerid][Registered]);
INI_WriteInt(File,"Kills",pInfo[playerid][Kills]);
INI_WriteInt(File,"Deaths",pInfo[playerid][Deaths]);
INI_WriteInt(File,"Level",pInfo[playerid][Level]);
INI_WriteInt(File,"VIPLevel",pInfo[playerid][VIPLevel]);
INI_Close(File);
return 1;
}
stock UserData(playerid)
{
new str[128],Pname[MAX_PLAYER_NAME];
GetPlayerName(playerid,Pname,sizeof(Pname));
format(str,sizeof(str),Dir,Pname);
return str;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case DIALOG_REGISTER:
{
if(!response)
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,"Welcome!"," Welcome to Server please type your password below to register.","Register","Quit");
}
if(response)
{
new str[256],IP[16],buf[129];
GetPlayerIp(playerid, IP, sizeof(IP));
if(!strlen(inputtext))
{
format(str,sizeof(str),"Welcome to Server");
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,"Welcome!"," Welcome to Server please type your password below to register.","Register","Quit");
}
new INI:File = INI_Open(UserData(playerid));
WP_Hash(buf, sizeof(buf), inputtext);
INI_SetTag(File,"data");
INI_WriteString(File, "Password", buf);
INI_WriteInt(File,"Kills",0);
INI_WriteInt(File,"Deaths",0);
INI_WriteInt(File,"Level",0);
INI_WriteInt(File,"VIPLevel",0);
INI_Close(File);
pInfo[playerid][Loggedin] = 1;
}
}
case DIALOG_LOGIN:
{
if(!response)
{
ShowPlayerDialog(playerid, DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Wrong Password!","Wrong Password!\nKindly type your password below to login!","Login","Quit");
}
if(response)
{
new buf[129];
WP_Hash(buf, sizeof(buf), inputtext);
if(!strcmp(buf,pInfo[playerid][Password]))
{
INI_ParseFile(UserData(playerid), "LoadUser_data", .bExtra = true, .extra = playerid);
pInfo[playerid][Loggedin] = 1;
SendClientMessage(playerid,-1,"Your Account Has Been Successfully Logged in!");
}
else
{
new string[256];
format(string,sizeof(string),"Welcome back");
ShowPlayerDialog(playerid, DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,string,"Wrong Password!\nKindly type your password below to login!","Login","Quit");
}
}
}
}
return 1;
}