08.06.2016, 19:12
Hi guyz,i have made login/register system but i want that if player writes incorrect password 3 times,he will be kicked automatically for incorrect passwords attempts.
case DIALOG_LOGIN:
{
//if(!response) return Kick(playerid);
//if(response)
switch(response)
{
case 0: Kick(playerid);
case 1:
{
if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
PlayerLogged[playerid] = true;
new playername[24];
GetPlayerName(playerid, playername, sizeof(playername));
PlayerInfo[playerid][pName] = playername;
TogglePlayerSpectating(playerid, false);
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"Account Info");
INI_WriteString(File, "Name", PlayerInfo[playerid][pName]);
INI_Close(File);
ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
if(PlayerInfo[playerid][pBan] == 1)
{
SendClientMessage(playerid, COLOR_LIGHTRED, "You have been banned for logging into a banned account.");
SetTimerEx("UnsetBan", 500, 0, "i", playerid);
}
}
else
{
if(GetPVarInt(playerid, "WrongPassword") >= 5)
{
SendClientMessage(playerid,COLOR_LIGHTRED,"You have been banned for entering the wrong password in five times.");
//BanExtra(playerid,"Wrong Password","Anna-Bot");
//format(string, sizeof(string), "%s was banned for Wrong Password by Anna-Bot System.", PlayerName(playerid));
//BanLog(string);
}
else
{
new string[100];
SetPVarInt(playerid, "WrongPassword", 1+GetPVarInt(playerid, "WrongPassword"));
new amount = 5 - GetPVarInt(playerid, "WrongPassword");
format(string, sizeof(string),"Invalid password (%d tries left).", amount);
SendClientMessage(playerid,COLOR_LIGHTRED,string);
ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Server Account","An existing account is using your playername, please login to the account.\nIf you can't support this dialog select the (next) option.","Login", "Next");
//ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,"Login","You have entered an incorrect password.\n""Type your password below to login.","Login","Quit");
//WrongPassword(playerid);
}
}
return 1;
}
}
}
}
new gLoginAttempts[MAX_PLAYERS];
gLoginAttempts[playerid]=0;
gLoginAttempts[playerid]++; if(gLoginAttempts[playerid] == 3) return Kick(playerid);
gLoginAttempts[playerid]=0; // We reset them in case he managed to login from the 2nd attempt.
new LoginAttempts[MAX_PLAYERS];
LoginAttempts[playerid]++;
if(LoginAttempts[playerid] == 3)
LoginAttempts[playerid] = 0;