Loop mistake.
#1

So, i've been trying to make an anti-cheat, currently at the RCON Login attempt, but instead of banning the player once, it bans him 50 times.

This is my code & loop:
pawn Код:
public OnRconLoginAttempt(ip[], password[], success)
{
    if(!success)
    {
        new pip[24];
        for(new i; i<MAX_PLAYERS; i++) //Loop through all players
        {
            GetPlayerIp(i, pip, sizeof(pip));
            if(!strcmp(ip, pip, true)) //If a player's IP is the IP that failed the login
            {
                BanUser(i, "RCON Login Attempt", "Aaron");
            }
        }
    }
    return 1;
}
Reply
#2

You need to use a 'break' to break out of a loop.
The following code would work -
pawn Код:
public OnRconLoginAttempt(ip[], password[], success)
{
    if(!success)
    {
        new pip[17];
        for(new i; i<MAX_PLAYERS; i++) //Loop through all players
        {
            GetPlayerIp(i, pip, sizeof(pip));
            if(!strcmp(ip, pip, true)) //If a player's IP is the IP that failed the login
            {
                BanUser(i, "RCON Login Attempt", "Aaron");
                break;
            }
        }
    }
    return 1;
}
Secondly, a minor change, IPs are generally of 16 chars!
Reply
#3

Quote:
Originally Posted by Rajat_Pawar
Посмотреть сообщение
You need to use a 'break' to break out of a loop.
The following code would work -
pawn Код:
public OnRconLoginAttempt(ip[], password[], success)
{
    if(!success)
    {
        new pip[17];
        for(new i; i<MAX_PLAYERS; i++) //Loop through all players
        {
            GetPlayerIp(i, pip, sizeof(pip));
            if(!strcmp(ip, pip, true)) //If a player's IP is the IP that failed the login
            {
                BanUser(i, "RCON Login Attempt", "Aaron");
                break;
            }
        }
    }
    return 1;
}
Secondly, a minor change, IPs are generally of 16 chars!
Someone else helped me already, but thanks anyways!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)