Kick playerid + all with the same ip
#1

CLOSED.
Reply
#2

PHP код:
stock GetIPs(playerid)
{
    new 
allip[33],
    
playersip[33],
    
count 0;
    
GetPlayerIp(playerid,playersip,sizeof(playersip));
    for(new 
i=0i<MAX_PLAYERSi++)
    {
        if(
IsPlayerConnected(i) && !IsPlayerNPC(i) && != playerid)
        {
            
GetPlayerIp(i,allip,sizeof(allip));
            if(
strcmp(allipplayersiptrue) == 0count++;
        }
    }
    return 
count;

PHP код:
public OnPlayerConnect(playerid)
{
    new 
IPs GetIPs(playerid);
    if(
IPs >= && !IsPlayerNPC(playerid))
    {
    
SendClientMessage(playerid, -1,"Error: You are already connected in game with the same Internet Protocol!");
    
Kick(playerid);
    }
    return 
0;

Reply
#3

Thanks a lot, it will be useful for my needs, thanks again +REP
Reply
#4

Here's a little code I came up with. Looks a bit messy but should work well.

pawn Код:
#define MAX_IP_LIMIT    2

public OnPlayerConnect(playerid)
{
    KickIP(playerid);
    return 1;
}

KickIP(playerid, limit = MAX_IP_LIMIT, bool:kickall = false)
{
    if(!IsPlayerConnected(playerid)) return 0;
    new cnt = 1, kickip[16], playerip[16];
    GetPlayerIp(playerid, kickip, sizeof(kickip));
    if(kickall)
    {
        new playerstokick[MAX_PLAYERS];
        for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
        {
            if(!IsPlayerConnected(i) || IsPlayerNPC(i) || i == playerid) continue;
            GetPlayerIp(i, playerip, sizeof(playerip));
            if(!strcmp(playerip, kickip, true)) playerstokick[(cnt++ - 1)] = i;
        }
        if(cnt <= limit) return 0;
        for(new i = 0; i < cnt; i++)
        {
            SetTimerEx("KickPlayer", 200, false, "i", playerstokick[i]);
            //SendClientMessage(playerid, -1, "Error: You have exceeded the IP limit!");
        }
    }
    else
    {
        for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
        {
            if(!IsPlayerConnected(i) || IsPlayerNPC(i) || i == playerid) continue;
            GetPlayerIp(i, playerip, sizeof(playerip));
            if(!strcmp(playerip, kickip, true)) cnt++;
        }
        if(cnt <= limit) return 0;
        SetTimerEx("KickPlayer", 200, false, "i", playerid);
        //SendClientMessage(playerid, -1, "Error: You have already reached the IP limit!");
    }
    return cnt;
}

forward KickPlayer(playerid);
public KickPlayer(playerid) return Kick(playerid);
Code broken down:
pawn Код:
#define MAX_IP_LIMIT    2
Used to easily specify the limit of IP's in-game. 2 by default, meaning only a maximum of 2 players can have the same IP while connected in-game.

The function 'KickIP' has 3 parameters. The 2nd and 3rd parameters are optional.

Код:
KickIP(playerid, limit = MAX_IP_LIMIT, bool:kickall = false)
The 'limit' parameter specifies the limit of matching IPs that can be in-game at any time. This is your MAX_IP_LIMIT by default, which can be modified at the top of the script.

The 'kickall' parameter is used to determine whether every single matching IP should be kicked. If the parameter is set to 'true', everyone who matches the IP will be kicked if the number of matching IPs exceeds the IP limit. If set to false, only the specified player 'playerid' will be kicked if the number of matching IPs exceeds the limit.

If you want to kick just the one player for exceeding the IP limit, but you don't want to disrupt already connected players:
pawn Код:
public OnPlayerConnect(playerid)
{
    KickIP(playerid);
    return 1;
}
If you want to kick everyone on the same IP if they exceed the IP limit: (This is probably what you want)
pawn Код:
public OnPlayerConnect(playerid)
{
    KickIP(playerid, .kickall = true);
    return 1;
}
I also added a 'KickPlayer' public, which is sort of a 'delayed kick' in case you want to send a message to the player as shown in the example by Michael B. Due to security measures added in 0.3e, the player is instantaneously kicked before any messages can be displayed, hence the reason for the delayed kick.

EDIT: Awww, should have refreshed the page first...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)