Код:
#include <a_samp>
#include <Dini>
#include <Dutils>
#include <DUDB>
enum PlayerInfo
{
Username, //0
AdminLevel, //1
Money, //2
VIP, //3
Score, //4
}
new pInfo[MAX_PLAYERS][PlayerInfo];
new IsLogged[MAX_PLAYERS]=0;
#define D_REGISTER 1000 //Register dialog
#define D_LOGIN 1001 //Login dialog
public OnPlayerConnect(playerid)
{
IsLogged[playerid]=0;
new
file[128],
format(file,sizeof(file),"\\Users\\%s.ini", GetName(playerid));
if (!dini_Exists(file))
{
ShowPlayerDialog(playerid, D_REGISTER, DIALOG_STYLE_INPUT, "[System]: Username not found in database.", "Welcome, please write a password in the box below to register your account.", "Register", "Leave");
}
if(fexist(file))
{
ShowPlayerDialog(playerid, D_LOGIN, DIALOG_STYLE_INPUT, "[Sysyem]: Username found in database.", "Please log in below.", "Login", "Leave");
}
}
public OnPlayerDisconnect(playerid, reason)
{
new
file[128];
format(file,sizeof(file),"\\Users\\%s.ini", GetName(playerid));
if(IsLogged[playerid] == 1)
{
SaveFile(playerid);
}
IsLogged[playerid]=0;
new
string[64];
switch(reason)
{
case 0: format(string,sizeof string,"%s left the server. (Timed out)",GetName(playerid));
case 1: format(string,sizeof string,"%s left the server. (Leaving)",GetName(playerid));
case 2: format(string,sizeof string,"%s left the server. (Kicked/Banned)",GetName(playerid));
}
SendClientMessageToAll(0xFFFFFFAA,string);
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
////////////////////////////////////////////////////////////////////////////////Register
if(dialogid == D_REGISTER)
{
if (!response)
{
SendClientMessage(playerid, COLOR_RED, "[System]: You have been automatically disconnected!");
Kick(playerid);
return 1;
}
if (isnull(inputtext) || strlen(inputtext) > 100) return ShowPlayerDialog(playerid, D_REGISTER, DIALOG_STYLE_INPUT, "[System]: Username not found in database.", "Welcome, please write a password in the box below to register your account.", "Register", "Leave");
CreateFile(playerid, inputtext);
SendClientMessage(playerid, COLOR_GREEN, "[System]: Account Created!");
new
string[128];
format(string,sizeof(string), "%s has registered a account!", GetName(playerid));
SendClientMessageToAll(COLOR_RED, string);
SendClientMessage(playerid, COLOR_GREEN, "[System]: You have been automatically logged in.");
LoadFile(playerid);
IsLogged[playerid]=1;
}
////////////////////////////////////////////////////////////////////////////////Login
if(dialogid == D_LOGIN)
{
new
file[128];
format(file,sizeof(file),"\\Users\\%s.ini", GetName(playerid));
if (!response)
{
SendClientMessage(playerid, COLOR_RED, "[System]: You have been automatically disconnected!");
Kick(playerid);
return 1;
}
if (isnull(inputtext)) return ShowPlayerDialog(playerid, D_LOGIN, DIALOG_STYLE_INPUT, "[Sysyem]: Username found in database.", "Please log in below.", "Login", "Leave");
new
tmp;
tmp = dini_Int(file, "Password");
if(udb_hash(inputtext) != tmp)
{
new string[128];
format(string, 256, "[System]: The password %s does not match %s's password.", inputtext, GetName(playerid));
SendClientMessage(playerid, COLOR_RED, string);
ShowPlayerDialog(playerid, D_LOGIN, DIALOG_STYLE_INPUT, "[Sysyem]: Username found in database.", "Please log in below.", "Login", "Leave");
}
else
{
IsLogged[playerid]=1;
LoadFile(playerid);
SendClientMessage(playerid, COLOR_GREEN, "[System]: You have succesfully logged in!");
}
}
return 1;
}
stock CreateFile(id, inputtext[])
{
new
file[128];
format(file,sizeof(file),"\\Users\\%s.ini", GetName(id));
dini_Create(file);
dini_Set(file,"Username",GetName(id));
dini_IntSet(file,"Password", udb_hash(inputtext));
dini_IntSet(file,"AdminLevel", 0);
dini_IntSet(file,"Money", 1000);
dini_IntSet(file,"VIP", fCiv);
dini_IntSet(file,"Score", 0);
return 1;
}
stock LoadFile(id)
{
new
file[128];
format(file,sizeof(file),"\\Users\\%s.ini", GetName(id));
pInfo[id][Username] = dini_Int(file, "Username");
pInfo[id][AdminLevel] = dini_Int(file, "AdminLevel");
pInfo[id][Money] = dini_Int(file, "Money");
pInfo[id][VIP] = dini_Int(file, "VIP");
new score1 = dini_Int(file, "Score");
SetPlayerScore(playerid, score1);
SetPlayerMoney(id, dini_Int(file, "Money"));
return 1;
}
stock SaveFile(id)
{
new
file[128];
format(file,sizeof(file),"\\Users\\%s.ini", GetName(id));
dini_IntSet(file, "AdminLevel", pInfo[id][AdminLevel]);
dini_IntSet(file, "Money", GetPlayerMoney(id));
dini_IntSet(file, "Score", GetPlayerScore(playerid));
dini_IntSet(file, "VIP", pInfo[id][VIP]);
dini_IntSet(file, "Tutored", pInfo[id][Tutored]);
return 1;
}
stock GetName(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
return name;
}