Login-attempts loop doesn't work!
#1

'Sup y'all?

I made a loop, which checks how many times the player entered an incorrect password! If it reaches 3, the player will be automatically kicked! But it doesn't work, unfortunately, there is always written: "Wrong password, 2 login-attempts left!". It won't count down until 1 and then after the third time kick the player! What am I doing wrong?

PHP код:
    public OnDialogResponse(playeriddialogidresponselistiteminputtext[]) {
        switch(
dialogid)
        {
            case 
DIALOG_REGISTER:
            {
                if(!
response)
                    return 
Kick(playerid);
                if(
response)
                {
                    if(!
strlen(inputtext))
                        return 
ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_INPUT""WHITE"Registering...",""RED"You have entered an invalid password.\n"WHITE"Type your password below to register a new account.","Register","Quit");
                    if(
INI_Open(getINI(playerid)))
                    {
                        
INI_WriteString("Password",inputtext);
                        
INI_WriteInt("Cash"0);
                        
INI_WriteInt("Admin"0);
                        
INI_WriteInt("FirstTime"0);
                        
INI_WriteInt("Skin"0);
                        
INI_WriteInt("Score"0);
                        
INI_WriteInt("Kills"0);
                        
INI_WriteInt("Deaths"0);
                        
INI_Save();
                        
INI_Close();
                        
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_INPUT,""WHITE"Login",""WHITE"Type your password below to login.","Login","Quit");
                    }
                }
            } case 
DIALOG_LOGIN:
              {
                if(!
response)
                    return 
Kick playerid );
                if(
response)
                {
                    if(!
strlen(inputtext))
                        return 
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_INPUT""WHITE"Login",""RED"You have entered an invalid password.\n"WHITE"Type your password below to login.","Login","Quit");
                    if(
INI_Open(getINI(playerid)))
                    {
                        
INI_ReadString(PlayerInfo[playerid][pPass],"Password",20);
                        if(
strcmp(inputtext,PlayerInfo[playerid][pPass],false)) {
               
                            
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_INPUT""WHITE"Login",""RED"You have entered an incorrect password.\n"WHITE"Type your password below to login.","Login","Quit");
                            
                            for(new 
0MAX_LOGIN_ATTEMPTSi++)
                                {
                                    if(
IsPlayerConnected(i) == 1)
                                    {
                                        
SendClientMessage(playerid,COLOR_RED,"Wrong password, 2 login-attempts left!");
                                    }
                                    else if(
IsPlayerConnected(i) == 2)
                                    {
                                        
SendClientMessage(playerid,COLOR_RED,"Wrong password, 1 login-attempt left!");
                                    }
                                    else if(
IsPlayerConnected(i) == 3)
                                    {
                                        
Kick(playerid);
                                    }
                                }
                        }
                        else  {
                        
SendClientMessage(playerid,TEAM_GROVE_COLOR,"You have successfully logged in! Welcome back, homie!");
                        
PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
                        }
                        
                        
GivePlayerMoneyplayeridINI_ReadInt"Cash" ) );
                        
PlayerInfo[playerid][pAdmin] = INI_ReadInt("Admin");
                        
PlayerInfo[playerid][pKills] = INI_ReadInt("Kills");
                        
PlayerInfo[playerid][pDeaths] = INI_ReadInt("Deaths");
                        
gFirstTimeHasJoined[playerid] = INI_ReadInt("FirstTime");
                        
gPlayerSkinForEver[playerid] = INI_ReadInt("Skin");
                        
SetPlayerScoreplayeridINI_ReadInt"Score" ) );
                        
INI_Close();
                    }
                }
            }
        }
        return 
1;
    } 
Reply
#2

Lol, I didn't "roll on my own", I am using SII, and I followed Kush's tutorial a long time ago... I don't know, maybe he made the mistake then, I just followed his tutorial about SII a long time ago!
Reply
#3

NP dude, it's really similar, I know!

Hmm, but Kush isn't online since a long time and that loop isn't really that much about "SII", it's a generally loop just in that "dialog-case"...

Anybody else got an idea?
Reply
#4

That is because you're doing a useless loop and using IsPlayerConnected.
You will have to create a variable first, at the top of your gamemode.
pawn Код:
new TimesAttempted[MAX_PLAYERS];
Then OnPlayerConnect public.
pawn Код:
TimesAttempted[playerid] = 0;
Now, your code should be like this.
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
        switch(dialogid)
        {
            case DIALOG_REGISTER:
            {
                if(!response)
                    return Kick(playerid);
                if(response)
                {
                    if(!strlen(inputtext))
                        return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""WHITE"Registering...",""RED"You have entered an invalid password.\n"WHITE"Type your password below to register a new account.","Register","Quit");
                    if(INI_Open(getINI(playerid)))
                    {
                        INI_WriteString("Password",inputtext);
                        INI_WriteInt("Cash", 0);
                        INI_WriteInt("Admin", 0);
                        INI_WriteInt("FirstTime", 0);
                        INI_WriteInt("Skin", 0);
                        INI_WriteInt("Score", 0);
                        INI_WriteInt("Kills", 0);
                        INI_WriteInt("Deaths", 0);
                        INI_Save();
                        INI_Close();
                        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""WHITE"Login",""WHITE"Type your password below to login.","Login","Quit");
                    }
                }
            } case DIALOG_LOGIN:
              {
                if(!response)
                    return Kick ( playerid );
                if(response)
                {
                    if(!strlen(inputtext))
                        return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""WHITE"Login",""RED"You have entered an invalid password.\n"WHITE"Type your password below to login.","Login","Quit");
                    if(INI_Open(getINI(playerid)))
                    {
                        INI_ReadString(PlayerInfo[playerid][pPass],"Password",20);
                        if(strcmp(inputtext,PlayerInfo[playerid][pPass],false)) {
                        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""WHITE"Login",""RED"You have entered an incorrect password.\n"WHITE"Type your password below to login.","Login","Quit");
                            TimesAttempted[playerid] += 1;
                            if(TimesAttempted[playerid] == 1) SendClientMessage(playerid,COLOR_RED,"Wrong password, 2 login-attempts left!");
                            else if(TimesAttempted[playerid] == 2) SendClientMessage(playerid,COLOR_RED,"Wrong password, 1 login-attempt left!");
                            else if(TimesAttempted[playerid] == 3) Kick(playerid);
                        }else  {
                        SendClientMessage(playerid,TEAM_GROVE_COLOR,"You have successfully logged in! Welcome back, homie!");
                        PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
                        }

                        GivePlayerMoney( playerid, INI_ReadInt( "Cash" ) );
                        PlayerInfo[playerid][pAdmin] = INI_ReadInt("Admin");
                        PlayerInfo[playerid][pKills] = INI_ReadInt("Kills");
                        PlayerInfo[playerid][pDeaths] = INI_ReadInt("Deaths");
                        gFirstTimeHasJoined[playerid] = INI_ReadInt("FirstTime");
                        gPlayerSkinForEver[playerid] = INI_ReadInt("Skin");
                        SetPlayerScore( playerid, INI_ReadInt( "Score" ) );
                        INI_Close();
                    }
                }
            }
        }
        return 1;
    }
Reply
#5

Thank you, you're completely right, it was useless! So only one more thing:

I want that a message appears when the player get kicked, which is telling everybody why he got kicked:

"SYSTEM: Player %s has been kicked by the server (Repeating incorrect login-attempts)!"

I just don't know if I can create a variable for the player under this callback and then get his name, otherwise I would have done it by myself!
Reply
#6

Add format with a sentence you would like to send under if(TimesAttempted[playerid] == 3), then simply SendClientMessageToAll under the format function, and under it, KICK the playerid.
Reply
#7

This doesn't work in the callback, it gives me these errors:

Код:
D:\Program Files\GTA San Andreas\SAMP_Server\gamemodes\deathmatch.pwn(1744) : error 003: declaration of a local variable must appear in a compound block
D:\Program Files\GTA San Andreas\SAMP_Server\gamemodes\deathmatch.pwn(1744) : error 017: undefined symbol "tname"
D:\Program Files\GTA San Andreas\SAMP_Server\gamemodes\deathmatch.pwn(1744) : warning 215: expression has no effect
D:\Program Files\GTA San Andreas\SAMP_Server\gamemodes\deathmatch.pwn(1744) : error 001: expected token: ";", but found "]"
D:\Program Files\GTA San Andreas\SAMP_Server\gamemodes\deathmatch.pwn(1744) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
PHP код:
                            new tname[MAX_PLAYER_NAME];
                            
GetPlayerName(playerid,tname,sizeof(tname));
                            new 
rstring[256];
                            
format(rstring,sizeof(rstring),"SYSTEM: Player %s has been kicked by the server (Exceeding login-attempts)!",tname);
                            
SendClientMessageToAll(COLOR_RED,rstring);
                             
Kick(playerid); 
By the way, I've already given you a reputation-point, 'cause I think you deserve it!
Reply
#8

Thank you, by the way; TRY THIS.
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
        switch(dialogid)
        {
            case DIALOG_REGISTER:
            {
                if(!response)
                    return Kick(playerid);
                if(response)
                {
                    if(!strlen(inputtext))
                        return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""WHITE"Registering...",""RED"You have entered an invalid password.\n"WHITE"Type your password below to register a new account.","Register","Quit");
                    if(INI_Open(getINI(playerid)))
                    {
                        INI_WriteString("Password",inputtext);
                        INI_WriteInt("Cash", 0);
                        INI_WriteInt("Admin", 0);
                        INI_WriteInt("FirstTime", 0);
                        INI_WriteInt("Skin", 0);
                        INI_WriteInt("Score", 0);
                        INI_WriteInt("Kills", 0);
                        INI_WriteInt("Deaths", 0);
                        INI_Save();
                        INI_Close();
                        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""WHITE"Login",""WHITE"Type your password below to login.","Login","Quit");
                    }
                }
            } case DIALOG_LOGIN:
              {
                if(!response)
                    return Kick ( playerid );
                if(response)
                {
                    if(!strlen(inputtext))
                        return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""WHITE"Login",""RED"You have entered an invalid password.\n"WHITE"Type your password below to login.","Login","Quit");
                    if(INI_Open(getINI(playerid)))
                    {
                        INI_ReadString(PlayerInfo[playerid][pPass],"Password",20);
                        if(strcmp(inputtext,PlayerInfo[playerid][pPass],false)) {
                        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""WHITE"Login",""RED"You have entered an incorrect password.\n"WHITE"Type your password below to login.","Login","Quit");
                            TimesAttempted[playerid] += 1;
                            if(TimesAttempted[playerid] == 1) SendClientMessage(playerid,COLOR_RED,"Wrong password, 2 login-attempts left!");
                            else if(TimesAttempted[playerid] == 2) SendClientMessage(playerid,COLOR_RED,"Wrong password, 1 login-attempt left!");
                            else if(TimesAttempted[playerid] == 3) {
                                new tname[MAX_PLAYER_NAME], string[128];
                                GetPlayerName(playerid, tname, sizeof(tname));
                                format(rstring,sizeof(rstring),"SYSTEM: Player %s has been kicked by the server (Exceeding login-attempts)!",tname);
                                SendClientMessageToAll(COLOR_RED, rstring);
                                Kick(playerid);
                            }
                        }else  {
                        SendClientMessage(playerid,TEAM_GROVE_COLOR,"You have successfully logged in! Welcome back, homie!");
                        PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
                        }

                        GivePlayerMoney( playerid, INI_ReadInt( "Cash" ) );
                        PlayerInfo[playerid][pAdmin] = INI_ReadInt("Admin");
                        PlayerInfo[playerid][pKills] = INI_ReadInt("Kills");
                        PlayerInfo[playerid][pDeaths] = INI_ReadInt("Deaths");
                        gFirstTimeHasJoined[playerid] = INI_ReadInt("FirstTime");
                        gPlayerSkinForEver[playerid] = INI_ReadInt("Skin");
                        SetPlayerScore( playerid, INI_ReadInt( "Score" ) );
                        INI_Close();
                    }
                }
            }
        }
        return 1;
    }
Reply
#9

Код:
D:\Program Files\GTA San Andreas\SAMP_Server\gamemodes\deathmatch.pwn(1744) : error 003: declaration of a local variable must appear in a compound block
D:\Program Files\GTA San Andreas\SAMP_Server\gamemodes\deathmatch.pwn(1744) : error 017: undefined symbol "tname"
D:\Program Files\GTA San Andreas\SAMP_Server\gamemodes\deathmatch.pwn(1744) : warning 215: expression has no effect
D:\Program Files\GTA San Andreas\SAMP_Server\gamemodes\deathmatch.pwn(1744) : error 001: expected token: ";", but found "]"
D:\Program Files\GTA San Andreas\SAMP_Server\gamemodes\deathmatch.pwn(1744) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
PHP код:
    public OnDialogResponse(playeriddialogidresponselistiteminputtext[]) {
        switch(
dialogid)
        {
            case 
DIALOG_REGISTER:
            {
                if(!
response)
                    return 
Kick(playerid);
                if(
response)
                {
                    if(!
strlen(inputtext))
                        return 
ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_INPUT""WHITE"Registering...",""RED"You have entered an invalid password.\n"WHITE"Type your password below to register a new account.","Register","Quit");
                    if(
INI_Open(getINI(playerid)))
                    {
                        
INI_WriteString("Password",inputtext);
                        
INI_WriteInt("Cash"0);
                        
INI_WriteInt("Admin"0);
                        
INI_WriteInt("FirstTime"0);
                        
INI_WriteInt("Skin"0);
                        
INI_WriteInt("Score"0);
                        
INI_WriteInt("Kills"0);
                        
INI_WriteInt("Deaths"0);
                        
INI_Save();
                        
INI_Close();
                        
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_INPUT,""WHITE"Login",""WHITE"Type your password below to login.","Login","Quit");
                    }
                }
            } case 
DIALOG_LOGIN:
              {
                if(!
response)
                    return 
Kick playerid );
                if(
response)
                {
                    if(!
strlen(inputtext))
                        return 
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_INPUT""WHITE"Login",""RED"You have entered an invalid password.\n"WHITE"Type your password below to login.","Login","Quit");
                    if(
INI_Open(getINI(playerid)))
                    {
                        
INI_ReadString(PlayerInfo[playerid][pPass],"Password",20);
                        if(
strcmp(inputtext,PlayerInfo[playerid][pPass],false)) {
               
                            
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_INPUT""WHITE"Login",""RED"You have entered an incorrect password.\n"WHITE"Type your password below to login.","Login","Quit");
                            
TimesAttempted[playerid] += 1;
                            if(
TimesAttempted[playerid] == 1SendClientMessage(playerid,COLOR_RED,"Wrong password, 2 login-attempts left!");
                            else if(
TimesAttempted[playerid] == 2SendClientMessage(playerid,COLOR_RED,"Wrong password, 1 login-attempt left!");
                            else if(
TimesAttempted[playerid] == 3)
                            new 
tname[MAX_PLAYER_NAME], string[128];
                            
GetPlayerName(playeridtnamesizeof(tname));
                            
format(rstring,sizeof(rstring),"SYSTEM: Player %s has been kicked by the server (Exceeding login-attempts)!",tname);
                            
SendClientMessageToAll(COLOR_RED,rstring);
                             
Kick(playerid);
                        }
                        else  {
                        
SendClientMessage(playerid,BRIGHT_GREEN,"You have successfully logged in! Welcome back, homie!");
                        
PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
                        }
                        
                        
GivePlayerMoneyplayeridINI_ReadInt"Cash" ) );
                        
PlayerInfo[playerid][pAdmin] = INI_ReadInt("Admin");
                        
PlayerInfo[playerid][pKills] = INI_ReadInt("Kills");
                        
PlayerInfo[playerid][pDeaths] = INI_ReadInt("Deaths");
                        
gFirstTimeHasJoined[playerid] = INI_ReadInt("FirstTime");
                        
gPlayerSkinForEver[playerid] = INI_ReadInt("Skin");
                        
SetPlayerScoreplayeridINI_ReadInt"Score" ) );
                        
INI_Close();
                    }
                }
            }
        }
        return 
1;
    } 
Reply
#10

Either copy the code I posted or add "{" at the end of "else if(TimesAttempted[playerid] == 3)" and of course, under "Kick(playerid);" add "}".
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)