[HELP] OnRconLoginAttempt - 3 Chances
#1

How to give him 3 chances to type the pass, before he gets banned?


pawn Код:
public OnRconLoginAttempt(ip[], password[], success)
{
    if(!success)
    {
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            SendClientMessage(i, 0xF0F0FFF, "Wrong Password. Good Bye!");
            Ban(i);
        }
    }
    return 1;
}
Reply
#2

Would this work?
pawn Код:
new LoginAttempt[MAX_PLAYERS] = 0;

public OnRconLoginAttempt(ip[], password[], success)
{
    if(!success)
    {
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            LoginAttempt[i]++;
            if(LoginAttempt[i] > 2)
            {
                SendClientMessage(i, 0xF0F0FFF, "Wrong Password. Good Bye!");
                Ban(i);
            }
        }
    }
    return 1;
}
Edit: No it won't
I guess the challenge is to find the playerid.
Reply
#3

pawn Код:
public OnRconLoginAttempt(ip[], password[], success)
{
    if(!success)
    {
        new pip[32];
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                GetPlayerIp(i, pip, sizeof(pip));
                if(strcmp(pip, ip) == 0)
                {
                    AddPVarInt(i, "FailedLogins", 1);
                    if(GetPVarInt(i, "FailedLogins") == 3)
                    {
                        SendClientMessage(i, 0xF0F0FFF, "Wrong Password. Good Bye!");
                        Ban(i);
                    }
                }
            }
        }
    }
    return 1;
}
Add this function to your script

pawn Код:
stock AddPVarInt(playerid, varname[], int_value)
{
    SetPVarInt(playerid, varname, GetPVarInt(playerid, varname) + int_value);
}
Reply
#4

This works, yeah I did test it:
pawn Код:
new LoginAttempt[MAX_PLAYERS] = 0;

public OnRconLoginAttempt(ip[], password[], success)
{
    if(!success)
    {
        new pip[16];
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            GetPlayerIp(i, pip, sizeof(pip));
            if(strcmp(pip, ip) == 0)
            {
                LoginAttempt[i]++;
                if(LoginAttempt[i] > 2)
                {
                    SendClientMessage(i, COLOR_RED, "Wrong Password. Good Bye!");
                    Ban(i);
                }
            }
        }
    }
    return 1;
}
Reply
#5

Sorry, but I guess this one is the best way:

At TOP:
pawn Код:
new RCONAttempts[MAX_PLAYERS];
pawn Код:
public OnRconLoginAttempt(ip[], password[], success)
{
    if(!success)
    {
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                new pIP[16]; GetPlayerIP(playerid, pIP, 16);
                if(!strcmp(ip, pIP))
                {
                    RCONAttempts[i]++;
                    if(RCONAttempts[i]>=3)
                    {
                        SendClientMessage(i, 0xF0F0FFF, "Wrong Password. Good Bye!");
                        Ban(i);
                        RCONAttempts[i]=0;
                    }
                }
            }
        }
    }
    return 1;
}
And add at OnPlayerConnect:
pawn Код:
RCONAttempts[playerid]=0;

You need to reset the tries when the ID connects.

Tell me if there is any bug.


Jeffry
Reply
#6

Quote:
Originally Posted by Jeffry
Посмотреть сообщение
Sorry, but I guess this one is the best way:

At TOP:
pawn Код:
new RCONAttempts[MAX_PLAYERS];
pawn Код:
public OnRconLoginAttempt(ip[], password[], success)
{
    if(!success)
    {
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                new pIP[16]; GetPlayerIP(playerid, pIP, 16);
                if(!strcmp(ip, pIP))
                {
                    RCONAttempts[i]++;
                    if(RCONAttempts[i]>=3)
                    {
                        SendClientMessage(i, 0xF0F0FFF, "Wrong Password. Good Bye!");
                        Ban(i);
                        RCONAttempts[i]=0;
                    }
                }
            }
        }
    }
    return 1;
}
And add at OnPlayerConnect:
pawn Код:
RCONAttempts[playerid]=0;

You need to reset the tries when the ID connects.

Tell me if there is any bug.


Jeffry
That's exactly what I said?
Reply
#7

Not completely. You don't have the thing at OnPlayerConnect, and the IsPlayerConnected at the loop is missing. ^^
But your one looks quite okey as well.
Reply
#8

Quote:
Originally Posted by Jeffry
Посмотреть сообщение
Not completely. You don't have the thing at OnPlayerConnect, and the IsPlayerConnected at the loop is missing. ^^
But your one looks quite okey as well.
Well you won't be able to /rcon login if you are not connected, so I don't see the point in putting it there?
Reply
#9

It's just to prevent it will loop all these things through the player, it would cause lag and this prevents it.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)