//include
#include <a_samp>
#include <YSI\y_ini>
#include <sscanf2>
//PATH
#define PATH "/Users/%s.ini"
//colors
#define White "{FFFFFF}"
#define Red "{FF0000}"
//DIALOG
#define LOGIN 1
#define REGISTER 2
#define SUCCESS 3
//enum
enum Info
{
Password,
Admin,
Cash,
Kills,
Deaths,
Score,
Color,
}
new PlayerInfo[MAX_PLAYERS][Info];
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
INI_Int("Password",PlayerInfo[playerid][Password]);
INI_Int("Admin",PlayerInfo[playerid][Admin]);
INI_Int("Cash",PlayerInfo[playerid][Cash]);
INI_Int("Kills",PlayerInfo[playerid][Kills]);
INI_Int("Deaths",PlayerInfo[playerid][Deaths]);
INI_Int("Score",PlayerInfo[playerid][Score]);
INI_Int("Color",PlayerInfo[playerid][Color]);
return 1;
}
//stock
stock UserPath(playerid)
{
new string[128],Name[MAX_PLAYER_NAME];
GetPlayerName(playerid,Name,sizeof(Name));
format(string,sizeof(string),PATH,Name);
return string;
}
stock GetName(playerid)
{
new Name[MAX_PLAYER_NAME];
GetPlayerName(playerid,Name,MAX_PLAYER_NAME);
return Name;
}
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 OnPlayerConnect(playerid)
{
if(fexist(UserPath(playerid)))
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
ShowPlayerDialog(playerid, LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}LOGIN...", "{FFFFFF}Please Enter Your Password Below to Login.", "Login", "");
}
else
{
ShowPlayerDialog(playerid, REGISTER, DIALOG_STYLE_PASSWORD, "{FFFFFF}REGISTER...", "{FFFFFF}Please Enter Password To Register.", "Register", "");
}
return 1;
}
public OnPlayerDisconnect(playerid,reason)
{
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"Stats");
INI_WriteInt(File,"Admin",PlayerInfo[playerid][Admin]);
INI_WriteInt(File,"Cash",PlayerInfo[playerid][Cash]);
INI_WriteInt(File,"Kills",PlayerInfo[playerid][Kills]);
INI_WriteInt(File,"Deaths",PlayerInfo[playerid][Deaths]);
INI_WriteInt(File,"Score",PlayerInfo[playerid][Score]);
INI_WriteInt(File,"Color",PlayerInfo[playerid][Color]);
INI_Close(File);
INI_Close(File);
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch( dialogid )
{
case REGISTER:
{
if (!response) return Kick(playerid);
if(response)
{
if(!strlen(inputtext)) return ShowPlayerDialog(playerid, REGISTER, DIALOG_STYLE_PASSWORD, "{FFFFFF}REGISTER...", "{FFFFFF}Please Enter Password To Register.", "Register", "");
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"Stats");
INI_WriteInt(File,"Password",udb_hash(inputtext));
INI_WriteInt(File,"Admin",0);
INI_WriteInt(File,"Cash",0);
INI_WriteInt(File,"Kills",0);
INI_WriteInt(File,"Deaths",0);
INI_WriteInt(File,"Score",0);
INI_WriteInt(File,"Color",0);
INI_Close(File);
ShowPlayerDialog(playerid, SUCCESS, DIALOG_STYLE_MSGBOX, "{00FF00}Success!!!", "{FF61FF}You Have Successfully Registered!", "Okay", ""); INI_Close(File);
SpawnPlayer(playerid);
}
}
case LOGIN:
{
if (!response) return Kick ( playerid );
if(response)
{
if(udb_hash(inputtext) == PlayerInfo[playerid][Password])
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
GivePlayerMoney(playerid, PlayerInfo[playerid][Cash]);
SetPlayerVirtualWorld(playerid,0);
SetPlayerInterior(playerid,0);
SetPlayerScore(playerid,PlayerInfo[playerid][Score]);
ShowPlayerDialog(playerid, SUCCESS, DIALOG_STYLE_MSGBOX, "{00FF00}Success!!!", "{FF61FF}You Have Successfully Logged in!", "Okay", "");
}
else
{
ShowPlayerDialog(playerid, LOGIN, DIALOG_STYLE_PASSWORD, "Login!", "{FF0000}You Have Entered An Invalid Password\n{FF0000}Please Re-enter Your Password Below.", "Okay", "");
}
return 1;
}
}
}
return 1;
}
|