Jump to content
  • 0

Question

Posted (edited)

I'm limiting players from the same IP in a zone, but I'm not having much success, I'm using AntiFeed to do this action.

 

Code:

if ((_maxPlayers > 0) && !AntiFeedManager.getInstance().tryAddPlayer(getId(), player, _maxPlayers))
			{
				player.sendPacket(new ExShowScreenMessage(player.getName() + " maximum "+ AntiFeedManager.getInstance().getLimit(player, _maxPlayers) +" connection(s) per IP address allowed.", 5000, SMPOS.TOP_CENTER, true));
				player.teleportTo(TeleportType.TOWN);
				return;
			}

 

on the first try when I go to the zone I am moved out with no (Boot) inside the zone. On the second attempt I remain and if I log a boot the same procedure happens and I am allowed to keep 2. What is an ideal solution to block multiple players with the same IP?

Edited by Vision

8 answers to this question

Recommended Posts

  • 0
Posted

Few to none relevant information regarding your issue. You pasted few lines of code which we know nothing about or where you placed it. Also, you mention that you use 'AntiFeed', which basically is something custom we know nothing about, there's not enough info to help you.

 

If you want to block 2 players that use the same ip from accessing a zone, the best way is to check their ip when they enter the zone. If another player that is in the same zone shares the same ip, don't let the player enter (tp him back). There's no way players can cheat their way through, unless your movement system/zone system is fcked. If you feel players can cheat their way into the zone, you can additionally run a task every X minutes/seconds to check for players using the same ip inside the restricted zone and kick them.

  • 0
Posted (edited)

  

On 10/13/2022 at 10:03 AM, An4rchy said:

Few to none relevant information regarding your issue. You pasted few lines of code which we know nothing about or where you placed it. Also, you mention that you use 'AntiFeed', which basically is something custom we know nothing about, there's not enough info to help you.

 

If you want to block 2 players that use the same ip from accessing a zone, the best way is to check their ip when they enter the zone. If another player that is in the same zone shares the same ip, don't let the player enter (tp him back). There's no way players can cheat their way through, unless your movement system/zone system is fcked. If you feel players can cheat their way into the zone, you can additionally run a task every X minutes/seconds to check for players using the same ip inside the restricted zone and kick them.

 

or you can make the character that is in the zone to be teleported out as soon as other character with same ip enters zone. this is undestroyable.

 

onEnter.

 

for (Player player1 : World.getInstance().getPlayers())
                {
                    if (player1.isInsideZone(ZoneId.YOURZONEID) && player1.getClient().getConnection().getInetAddress().getHostAddress() == player.getClient().getConnection().getInetAddress().getHostAddress() )
                    {
                        player1.abortAttack();
                        player1.abortCast();
                        player1.teleportTo(TeleportType.TOWN);
                        player.sendMessage("You're character that is using same ip address has been teleported out from this area. Dual-Box is not allowed in this zone.")
                    player1.sendMessage("You have been teleported out. Dual-Box is not allowed in this zone..");
                    }
                }

 

 

 

if you want to have only 2 players with same ip use this::serious:

 

        int a = 0;

for (Player player1 : World.getInstance().getPlayers())
                {

           
                    if (player1.isInsideZone(ZoneId.YOURZONEID) && player1.getClient().getConnection().getInetAddress().getHostAddress() == player.getClient().getConnection().getInetAddress().getHostAddress() )
                    {

                       a = a++;

                       if(a > 1){
                        player1.abortAttack();
                        player1.abortCast();
                        player1.teleportTo(TeleportType.TOWN);
                        player.sendMessage("You're character that is using same ip address has been teleported out from this area. Dual-Box is not allowed in this zone.")
                    player1.sendMessage("You have been teleported out. Dual-Box is not allowed in this zone..");

                    }
                    }
                }

 

 

Edited by arm4729
  • 0
Posted
5 hours ago, An4rchy said:

Few to none relevant information regarding your issue. You pasted few lines of code which we know nothing about or where you placed it. Also, you mention that you use 'AntiFeed', which basically is something custom we know nothing about, there's not enough info to help you.

 

If you want to block 2 players that use the same ip from accessing a zone, the best way is to check their ip when they enter the zone. If another player that is in the same zone shares the same ip, don't let the player enter (tp him back). There's no way players can cheat their way through, unless your movement system/zone system is fcked. If you feel players can cheat their way into the zone, you can additionally run a task every X minutes/seconds to check for players using the same ip inside the restricted zone and kick them.

 

package net.sf.l2j.gameserver.data.manager;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

import net.sf.l2j.Config;
import net.sf.l2j.gameserver.model.actor.Creature;
import net.sf.l2j.gameserver.model.actor.Player;
import net.sf.l2j.gameserver.network.GameClient;

public class AntiFeedManager
{
	public static final int GAME_ID = 0;
	public static final int OLYMPIAD_ID = 1;
	public static final int EVENT_ID = 2;
	
	private final Map<Integer, Long> _lastDeathTimes = new ConcurrentHashMap<>();
	private final Map<Integer, Map<Integer, AtomicInteger>> _eventIPs = new ConcurrentHashMap<>();
	
	/**
	 * Set time of the last player's death to current
	 * @param objectId Player's objectId
	 */
	public void setLastDeathTime(int objectId)
	{
		_lastDeathTimes.put(objectId, System.currentTimeMillis());
	}
	
	/**
	 * Check if current kill should be counted as non-feeded.
	 * @param attacker Attacker character
	 * @param target Target character
	 * @return True if kill is non-feeded.
	 */
	public boolean check(Creature attacker, Creature target)
	{
		if (!Config.ANTIFEED_ENABLE)
			return true;
		
		if (target == null)
			return false;
		
		final Player targetPlayer = target.getActingPlayer();
		if (targetPlayer == null)
			return false;
		
		// Players in offline mode should't be valid targets.
		if (targetPlayer.getClient().isDetached())
			return false;
		
		if ((Config.ANTIFEED_INTERVAL > 0) && _lastDeathTimes.containsKey(targetPlayer.getObjectId()) && ((System.currentTimeMillis() - _lastDeathTimes.get(targetPlayer.getObjectId())) < Config.ANTIFEED_INTERVAL))
			return false;
		
		if (Config.ANTIFEED_DUALBOX && (attacker != null))
		{
			final Player attackerPlayer = attacker.getActingPlayer();
			if (attackerPlayer == null)
				return false;
			
			final GameClient targetClient = targetPlayer.getClient();
			final GameClient attackerClient = attackerPlayer.getClient();
			if ((targetClient == null) || (attackerClient == null) || targetClient.isDetached() || attackerClient.isDetached())
				return !Config.ANTIFEED_DISCONNECTED_AS_DUALBOX; // unable to check ip address
			
			return !targetClient.getConnection().getInetAddress().equals(attackerClient.getConnection().getInetAddress());
		}
		
		return true;
	}
	
	/**
	 * Clears all timestamps
	 */
	public void clear()
	{
		_lastDeathTimes.clear();
	}
	
	/**
	 * Register new event for dualbox check. Should be called only once.
	 * @param eventId
	 */
	public void registerEvent(int eventId)
	{
		_eventIPs.putIfAbsent(eventId, new ConcurrentHashMap<>());
	}
	
	/**
	 * @param eventId
	 * @param player
	 * @param max
	 * @return If number of all simultaneous connections from player's IP address lower than max then increment connection count and return true.<br>
	 * False if number of all simultaneous connections from player's IP address higher than max.
	 */
	public boolean tryAddPlayer(int eventId, Player player, int max)
	{
		return tryAddClient(eventId, player.getClient(), max);
	}
	
	/**
	 * @param eventId
	 * @param client
	 * @param max
	 * @return If number of all simultaneous connections from player's IP address lower than max then increment connection count and return true.<br>
	 * False if number of all simultaneous connections from player's IP address higher than max.
	 */
	public boolean tryAddClient(int eventId, GameClient client, int max)
	{
		if (client == null)
			return false; // unable to determine IP address
		
		final Map<Integer, AtomicInteger> event = _eventIPs.get(eventId);
		if (event == null)
			return false; // no such event registered
		
		final Integer addrHash = client.getConnection().getInetAddress().hashCode();
	    final AtomicInteger connectionCount = event.computeIfAbsent(addrHash, k -> new AtomicInteger());
	    int whiteListCount = Config.DUALBOX_CHECK_WHITELIST.getOrDefault(addrHash, Integer.valueOf(0)).intValue();
	    if (whiteListCount < 0 || connectionCount.get() + 1 <= max + whiteListCount)
	    {
	      connectionCount.incrementAndGet();
	      return true;
	    } 
	    
		return false;
	}
	
	/**
	 * Decreasing number of active connection from player's IP address
	 * @param eventId
	 * @param player
	 * @return true if success and false if any problem detected.
	 */
	public boolean removePlayer(int eventId, Player player)
	{
		return removeClient(eventId, player.getClient());
	}
	
	/**
	 * Decreasing number of active connection from player's IP address
	 * @param eventId
	 * @param client
	 * @return true if success and false if any problem detected.
	 */
	public boolean removeClient(int eventId, GameClient client)
	{
		if (client == null || client.getConnection() == null)
			return false; // unable to determine IP address
		
		final Map<Integer, AtomicInteger> event = _eventIPs.get(eventId);
		if (event == null)
			return false; // no such event registered
		
		final Integer addrHash = Integer.valueOf(client.getConnection().getInetAddress().hashCode());
	    return (event.computeIfPresent(addrHash, (k, v) -> (v.decrementAndGet() == 0) ? null : v) != null);
	}
	
	/**
	 * Remove player connection IP address from all registered events lists.
	 * @param client
	 */
	public void onDisconnect(GameClient client)
	{
		if ((client == null))
			return;
		
		_eventIPs.forEach((k, v) -> removeClient(k, client));
	}
	
	/**
	 * Clear all entries for this eventId.
	 * @param eventId
	 */
	public void clear(int eventId)
	{
		final Map<Integer, AtomicInteger> event = _eventIPs.get(eventId);
		if (event != null)
			event.clear();
	}
	
	/**
	 * @param player
	 * @param max
	 * @return maximum number of allowed connections (whitelist + max)
	 */
	public int getLimit(Player player, int max)
	{
		return getLimit(player.getClient(), max);
	}
	
	/**
	 * @param client
	 * @param max
	 * @return maximum number of allowed connections (whitelist + max)
	 */
	public int getLimit(GameClient client, int max)
	{
		if (client == null)
			return max;
		
		final Integer addrHash = client.getConnection().getInetAddress().hashCode();
		int limit = max;
		if (Config.DUALBOX_CHECK_WHITELIST.containsKey(addrHash))
			limit += Config.DUALBOX_CHECK_WHITELIST.get(addrHash);
		
		return limit;
	}
	
	public static AntiFeedManager getInstance()
	{
		return SingletonHolder.INSTANCE;
	}
	
	private static class SingletonHolder
	{
		protected static final AntiFeedManager INSTANCE = new AntiFeedManager();
	}
}

 

 

I use L2jMobius AntiFedd, it works perfectly in other places except in the zone

 

Register Event:


	public FarmZone(int id)
	{
		super(id);
		AntiFeedManager.getInstance().registerEvent(id);
	}
	

 

Check onEnter :

 


	@Override
	protected void onEnter(Creature character)
	{
		character.setInsideZone(ZoneId.FARM, true);
		
		if (character instanceof Player)
		{
			final Player player = (Player) character;
			
			if ((_maxPlayers > 0) && !AntiFeedManager.getInstance().tryAddPlayer(getId(), player, _maxPlayers))
			{
				player.sendPacket(new ExShowScreenMessage(player.getName() + " maximum "+ AntiFeedManager.getInstance().getLimit(player, _maxPlayers) +" connection(s) per IP address allowed.", 5000, SMPOS.TOP_CENTER, true));
				player.teleportTo(TeleportType.TOWN);
				return;
			}
			

 

 

Clear Players onExit:

 


	@Override
	protected void onExit(Creature character)
	{
		character.setInsideZone(ZoneId.FARM, false);
		
		if (character instanceof Player)
		{
			final Player player = (Player) character;
			
			AntiFeedManager.getInstance().removePlayer(getId(), player);

 

  • 0
Posted (edited)

i give you what you want in 3 lines of code but you paste all this non sense code... if all you wanna do is not having 2 players with same ip in a specific zone you should use what i pasted above. why are you using code that you don't have any clue what is doing ?

 

 

what is this line is supposed to do ?? i bet you are clueless you should start by understanding you're code , if you can't read code as machine how you expect to write it ?

final AtomicInteger connectionCount = event.computeIfAbsent(addrHash, k -> new AtomicInteger());

 

 

 

anyway if you really wanna use this system you should paste all zone lines not only exit and enter.

 

 

	public boolean tryAddClient(, GameClient client, int max)
	{
		if (client == null)
			return false; // unable to determine IP address
		
 -->> i think you're problem is related to "event" probably this is antifeed for an automatic event engine .. and probably events are registered when they are starting , you might not have any active event at the this of this time check.. man just use the 3 lines i pasted above.	
	final Map<Integer, AtomicInteger> event = _eventIPs.get(eventId);
		if (event == null)
			return false; // no such event registered
		
		final Integer addrHash = client.getConnection().getInetAddress().hashCode();
	    final AtomicInteger connectionCount = event.computeIfAbsent(addrHash, k -> new AtomicInteger());
	    int whiteListCount = Config.DUALBOX_CHECK_WHITELIST.getOrDefault(addrHash, Integer.valueOf(0)).intValue();
	    if (whiteListCount < 0 || connectionCount.get() + 1 <= max + whiteListCount)
	    {
	      connectionCount.incrementAndGet();
	      return true;
	    } 
	    
		return false;
	}
Edited by arm4729
  • 0
Posted (edited)

sry little offtopic but some1 dont have code for player limit in zone ? max clan/ally members in zone ?  acis files thx 

Edited by KejbL
  • 0
Posted (edited)

int a = 0;

for (Player player1 : World.getInstance().getPlayers())
                {

                   
                    if (player1.isInsideZone(ZoneId.YOURZONEID) && player1.getClan() == player.getClan()
                    {

                        a = a++;

                        (if a > 8){
                        player.abortAttack();
                        player.abortCast();
                        player.teleportTo(TeleportType.TOWN);
                        player.sendMessage("Clan members limit reached in this zone. You have been teleported out.")
                        }
                    }
                }

 

Edited by arm4729
  • 0
Posted (edited)

I redid my system and it is now working perfectly.

 

code :

			if (getCharacters().stream().filter(creature -> creature.getActingPlayer().getClient().getConnection().getInetAddress().getHostAddress().equals(player.getClient().getConnection().getInetAddress().getHostAddress())).count() >= 1 + _maxPlayers)
			{
				player.teleportTo(TeleportType.TOWN);
				return;
			}

 

Edited by Williams
  • Upvote 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...