Problem with login system. -
Stoyanov - 24.10.2014
When i reach 3 wrong passwords, server kicks me. This is OK. But when i connect again and type correct password log me and my cash is 000000. It doesn't save the cash when kick you. Please Help. CODE:
Код:
case DIALOG_LOGIN:
{
if(!response) return Kick(playerid);
if(response)
{
if(udb_hash(inputtext) != PlayerInfo[playerid][pPass])
{
TimesAttempted[playerid] += 1;
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""COL_GREY"Login", ""COL_GREY"You have entered an incorrect {FF6347}password{B4B5B7}.\n"COL_GREY"Type your password below to login.", "Login", "Quit");
if(TimesAttempted[playerid] == 1)
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""COL_GREY"Login", ""COL_GREY"You have entered an incorrect {FF6347}password{B4B5B7}.\n"COL_GREY"Type your password below to login.", "Login", "Quit");
}
else if(TimesAttempted[playerid] == 2)
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""COL_GREY"Login", ""COL_GREY"You have entered an incorrect {FF6347}password{B4B5B7}.\n"COL_GREY"Type your password below to login.", "Login", "Quit");
}
else if(TimesAttempted[playerid] == 3)
{
Kick(playerid);
}
}
else
{
LoggedIn[playerid] = true;
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
SetPlayerFightingStyle(playerid, PlayerInfo[playerid][pFightStyle]);
ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX, ""COL_LGREEN"Success", ""COL_LGREEN"You have successfully logged in!", "Ok", "");
}
}
}
}
return 1;
}
Re: Problem with login system. -
gurmani11 - 24.10.2014
add saving data in OnPlayerDisconnect(playerid)
Re: Problem with login system. -
Stoyanov - 24.10.2014
Quote:
Originally Posted by gurmani11
add saving data in OnPlayerDisconnect(playerid)
|
Код:
public OnPlayerDisconnect(playerid, reason)
{
if(IsBeingSpeced[playerid])
{
foreach(new i : Player)
{
if(spectatorid[i] == playerid) TogglePlayerSpectating(i, false);
}
}
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File, "data");
INI_WriteInt(File, "Admin", PlayerInfo[playerid][pAdmin]);
INI_WriteInt(File, "VIP", PlayerInfo[playerid][pVIP]);
INI_WriteInt(File, "Wanted", GetPlayerWantedLevel(playerid));
INI_WriteInt(File, "Kills", PlayerInfo[playerid][pKills]);
INI_WriteInt(File, "Deaths", PlayerInfo[playerid][pDeaths]);
INI_WriteInt(File, "Jailed", PlayerInfo[playerid][pJailed]);
INI_WriteInt(File, "Muted", PlayerInfo[playerid][pMuted]);
INI_WriteInt(File, "Cash", GetPlayerMoney(playerid));
INI_WriteInt(File, "Score", GetPlayerScore(playerid));
INI_WriteInt(File, "Banned", PlayerInfo[playerid][pBanned]);
INI_WriteInt(File, "FightStyle", GetPlayerFightingStyle(playerid));
INI_Close(File);
return 1;
}
Re: Problem with login system. -
gurmani11 - 24.10.2014
pawn Код:
enum pInfo
{
pLoggedIn // add it in your own enum as you have it
}
new PlayerInfo[MAX_PLAYERS][pInfo];
So Lets add it in Login Dialog
pawn Код:
case DIALOG_LOGIN:
{
if(!response) return Kick(playerid);
if(response)
{
if(udb_hash(inputtext) != PlayerInfo[playerid][pPass])
{
TimesAttempted[playerid] += 1;
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""COL_GREY"Login", ""COL_GREY"You have entered an incorrect {FF6347}password{B4B5B7}.\n"COL_GREY"Type your password below to login.", "Login", "Quit");
if(TimesAttempted[playerid] == 1)
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""COL_GREY"Login", ""COL_GREY"You have entered an incorrect {FF6347}password{B4B5B7}.\n"COL_GREY"Type your password below to login.", "Login", "Quit");
}
else if(TimesAttempted[playerid] == 2)
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""COL_GREY"Login", ""COL_GREY"You have entered an incorrect {FF6347}password{B4B5B7}.\n"COL_GREY"Type your password below to login.", "Login", "Quit");
}
else if(TimesAttempted[playerid] == 3)
{
Kick(playerid);
}
}
else
{
LoggedIn[playerid] = true;
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
SetPlayerFightingStyle(playerid, PlayerInfo[playerid][pFightStyle]);
ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX, ""COL_LGREEN"Success", ""COL_LGREEN"You have successfully logged in!", "Ok", "");
PlayerInfo[playerid][pLoggedIn] = true; // Logged in is confirmed
}
}
}
}
return 1;
}
Lets check if player is logged in so we will save it
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
if(PlayerInfo[playerid][pLoggedIn] == true) // confirmed that he was logged in
{
if(IsBeingSpeced[playerid])
{
foreach(new i : Player)
{
if(spectatorid[i] == playerid) TogglePlayerSpectating(i, false);
}
}
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File, "data");
INI_WriteInt(File, "Admin", PlayerInfo[playerid][pAdmin]);
INI_WriteInt(File, "VIP", PlayerInfo[playerid][pVIP]);
INI_WriteInt(File, "Wanted", GetPlayerWantedLevel(playerid));
INI_WriteInt(File, "Kills", PlayerInfo[playerid][pKills]);
INI_WriteInt(File, "Deaths", PlayerInfo[playerid][pDeaths]);
INI_WriteInt(File, "Jailed", PlayerInfo[playerid][pJailed]);
INI_WriteInt(File, "Muted", PlayerInfo[playerid][pMuted]);
INI_WriteInt(File, "Cash", GetPlayerMoney(playerid));
INI_WriteInt(File, "Score", GetPlayerScore(playerid));
INI_WriteInt(File, "Banned", PlayerInfo[playerid][pBanned]);
INI_WriteInt(File, "FightStyle", GetPlayerFightingStyle(playerid));
INI_Close(File);
}
return 1;
}
Re: Problem with login system. -
Stoyanov - 24.10.2014
Still doesn't save my money. : (
Re: Problem with login system. -
gurmani11 - 24.10.2014
hmm then come in private chat lets check the gm
Respuesta: Problem with login system. -
aoEXE - 24.10.2014
How do you loads the money in the variable at login?
(LoadUser_%s)
Re: Problem with login system. -
Stoyanov - 24.10.2014
Yes.
Respuesta: Problem with login system. -
aoEXE - 24.10.2014
You have this in LoadUser public or not?
pawn Код:
INI_Int("Cash",PlayerInfo[playerid][pCash]);
Re: Problem with login system. -
Stoyanov - 24.10.2014
I have it
Код:
public LoadUser_data(playerid, name[], value[])
{
INI_Int("Password", PlayerInfo[playerid][pPass]);
INI_Int("Admin", PlayerInfo[playerid][pAdmin]);
INI_Int("VIP", PlayerInfo[playerid][pVIP]);
INI_Int("Wanted", PlayerInfo[playerid][pWanted]);
INI_Int("Kills", PlayerInfo[playerid][pKills]);
INI_Int("Deaths", PlayerInfo[playerid][pDeaths]);
INI_Int("Jailed", PlayerInfo[playerid][pJailed]);
INI_Int("Muted", PlayerInfo[playerid][pMuted]);
INI_Int("Cash", PlayerInfo[playerid][pCash]);
INI_Int("Score", PlayerInfo[playerid][pScore]);
INI_Int("Banned", PlayerInfo[playerid][pBanned]);
INI_Int("FightStyle", PlayerInfo[playerid][pFightStyle]);
return 1;
}