22.04.2016, 19:04
Hi all,
basically I'm making a gamemode from scratch, I've used dini in the past to save the account datas, but now I tried y_ini. The files don't save, can somebody help me please?
I've put the Dracoblue's password hash at the top of my script.
Then I made a stock that saves the account
Then there's a callback that loads the user's data
Then another two stocks
My OnPlayerConnect
OnPlayerDisconnect
And the OnDialogResponse for these two dialogs (login & register)
Any idea what do I have to do? There's no files creating in my scriptfiles creating aswell.
basically I'm making a gamemode from scratch, I've used dini in the past to save the account datas, but now I tried y_ini. The files don't save, can somebody help me please?
I've put the Dracoblue's password hash at the top of my script.
Код:
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;
}
Код:
stock SaveAccount(playerid)
{
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File, "Account data");
INI_WriteInt(File, "Banned", PlayerInfo[playerid][pBanned]);
INI_WriteInt(File, "PermBand", PlayerInfo[playerid][pPermBand]);
INI_WriteInt(File, "BanReason", PlayerInfo[playerid][pBanReason]);
INI_WriteInt(File, "PrisonReason", PlayerInfo[playerid][pPrisonReason]);
INI_WriteInt(File, "AdminJailed", PlayerInfo[playerid][pAdminJailed]);
INI_WriteInt(File, "PrisonedBy",PlayerInfo[playerid][pPrisonedBy]);
INI_WriteInt(File, "Donor",PlayerInfo[playerid][pDonor]);
INI_WriteInt(File, "XP", PlayerInfo[playerid][pExp]);
INI_WriteInt(File, "Cash", GetPlayerMoney(playerid));
INI_WriteInt(File, "Kills", PlayerInfo[playerid][pKills]);
INI_WriteInt(File, "Deaths", PlayerInfo[playerid][pDeaths]);
INI_WriteInt(File, "Tikis", PlayerInfo[playerid][pTikis]);
INI_Close(File);
return 1;
}
Код:
forward loadUserData(playerid,name[],value[]);
public loadUserData(playerid,name[],value[])
{
INI_Int("Key", PlayerInfo[playerid][pKey]);
INI_Int("Banned", PlayerInfo[playerid][pBanned]);
INI_Int("PermBand", PlayerInfo[playerid][pPermBand]);
INI_Int("BanReason", PlayerInfo[playerid][pBanReason]);
INI_Int("PrisonReason", PlayerInfo[playerid][pPrisonReason]);
INI_Int("AdminJailed", PlayerInfo[playerid][pAdminJailed]);
INI_Int("PrisonedBy", PlayerInfo[playerid][pPrisonedBy]);
INI_Int("Donor", PlayerInfo[playerid][pDonor]);
INI_Int("XP", PlayerInfo[playerid][pExp]);
INI_Int("Cash", PlayerInfo[playerid][pCash]);
INI_Int("Kills", PlayerInfo[playerid][pKills]);
INI_Int("Deaths", PlayerInfo[playerid][pDeaths]);
INI_Int("Tikis", PlayerInfo[playerid][pTikis]);
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;
}
stock CheckAccount(playerid)
{
if(fexist(UserPath(playerid)))
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,"{00FF00}Logging-in","{FFFFFF}Account status:{00FF00} REGISTERED\n{FFFFFF}Put your password to login.","Login","Quit");
}
else
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,"{00FF00}Registering","{FFFFFF}Account status:{FF0000}NOT-REGISTERED\n{FFFFFF}Put your desired password to register.","Register","Quit");
}
return 1;
}
Код:
public OnPlayerConnect(playerid)
{
new string[500];
removeBuildings(playerid);
PlayerInfo[playerid][pKey] = 0;
PlayerInfo[playerid][pAdmin] = 0;
PlayerInfo[playerid][pBanned] = 0;
PlayerInfo[playerid][pPermBand] = 0;
PlayerInfo[playerid][pBanReason] = 0;
PlayerInfo[playerid][pPrisonReason] = 0;
PlayerInfo[playerid][pAdminJailed] = 0;
PlayerInfo[playerid][pPrisonedBy] = 0;
PlayerInfo[playerid][pDonor] = 0;
PlayerInfo[playerid][pExp] = 0;
PlayerInfo[playerid][pCash] = 0;
PlayerInfo[playerid][pKills] = 0;
PlayerInfo[playerid][pDeaths] = 0;
PlayerInfo[playerid][pTikis] = 0;
format(string, 128, "{00BFFF}%s{FFFFFF} has joined the lobby.", PlayerName(playerid));
SendClientMessageToAll(-1, string);
CheckAccount(playerid);
return 1;
}
Код:
public OnPlayerDisconnect(playerid, reason)
{
new string[512];
SaveAccount(playerid);
if(reason == 0)
{
format(string, 256, "{00BFFF}%s{FFFFFF}has left the server. Reason:{00BFFF}Timeout{FFFFFF}", PlayerName(playerid));
SendClientMessageToAll(-1, string);
}
else if(reason == 1)
{
format(string, 256, "{00BFFF}%s{FFFFFF}has left the server. Reason:{00BFFF}Quit{FFFFFF}", PlayerName(playerid));
SendClientMessageToAll(-1, string);
}
else if(reason == 2)
{
format(string, 256, "{00BFFF}%s{FFFFFF}has left the server. Reason:{00BFFF}Kicked/Banned{FFFFFF}", PlayerName(playerid));
SendClientMessageToAll(-1, string);
}
PlayerInfo[playerid][pKey] = 0;
PlayerInfo[playerid][pAdmin] = 0;
PlayerInfo[playerid][pBanned] = 0;
PlayerInfo[playerid][pPermBand] = 0;
PlayerInfo[playerid][pBanReason] = 0;
PlayerInfo[playerid][pPrisonReason] = 0;
PlayerInfo[playerid][pAdminJailed] = 0;
PlayerInfo[playerid][pPrisonedBy] = 0;
PlayerInfo[playerid][pDonor] = 0;
PlayerInfo[playerid][pExp] = 0;
PlayerInfo[playerid][pCash] = 0;
PlayerInfo[playerid][pKills] = 0;
PlayerInfo[playerid][pDeaths] = 0;
PlayerInfo[playerid][pTikis] = 0;
return 1;
}
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch( dialogid )
{
case DIALOG_REGISTER:
{
if (!response) return PKick(playerid);
if(response)
{
if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "{FFFFFF}Registering...","{FF0000}You have entered an invalid password.\n{FFFFFF}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,"Key",udb_hash(inputtext));
INI_WriteInt(File,"Admin",0);
INI_WriteInt(File,"Banned", 0);
INI_WriteInt(File,"PermBand",0);
INI_WriteInt(File,"BanReason",0);
INI_WriteInt(File,"PrisonReason",0);
INI_WriteInt(File,"AdminJailed",0);
INI_WriteInt(File,"PrisonedBy",0);
INI_WriteInt(File,"Donor",0);
INI_WriteInt(File,"Exp", 0);
INI_WriteInt(File,"Cash", 0);
INI_WriteInt(File,"Account",0);
INI_WriteInt(File,"Kills",0);
INI_WriteInt(File,"Deaths", 0);
INI_WriteInt(File,"Model", 0);
INI_WriteInt(File,"Clothes", 0);
INI_WriteInt(File,"Tikis", 0);
INI_Close(File);
}
}
case DIALOG_LOGIN:
{
if (!response) return Kick (playerid);
if(response)
{
if(udb_hash(inputtext) == PlayerInfo[playerid][pKey])
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
SetPlayerScore(playerid, PlayerInfo[playerid][pExp]);
}
}
else
{
SendClientMessage(playerid, -1, "{FF0000}Your password is incorrect. Please, talk to an administrator regarding this.");
PKick(playerid);
}
return 1;
}
}
return 1;
}


