Ok i will give now :
public class AntiFeedManager
{
public static final int GAME_ID = 0;
final Map<Integer,Long> _lastDeathTimes;
private final TIntObjectHashMap<Map<Integer, Connections>> _eventIPs;
public static final AntiFeedManager getInstance()
{
return SingletonHolder._instance;
}
protected AntiFeedManager()
{
_lastDeathTimes = new ConcurrentHashMap<>();
_eventIPs = new TIntObjectHashMap<>();
}
/**
* Set time of the last player's death to current
* @param objectId Player's objectId
*/
public final void setLastDeathTime(int objectId)
{
_lastDeathTimes.put(objectId, System.currentTimeMillis());
ThreadPoolManager.getInstance().scheduleGeneral(new DeleteDeathTime(objectId), 120000);
}
private class DeleteDeathTime implements Runnable
{
int id;
public DeleteDeathTime(int objectId)
{
id = objectId;
}
@Override
public void run()
{
_lastDeathTimes.remove(id);
}
}
/**
* 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 final boolean check(L2Character attacker, L2Character target)
{
if (!Config.ANTIFEED_ENABLE)
return true;
if (target == null)
return false;
final L2PcInstance targetPlayer = target.getActingPlayer();
if (targetPlayer == null)
return false;
if (Config.ANTIFEED_INTERVAL > 0
&& _lastDeathTimes.containsKey(targetPlayer.getObjectId()))
return (System.currentTimeMillis() - _lastDeathTimes.get(targetPlayer.getObjectId())) > Config.ANTIFEED_INTERVAL;
if (Config.ANTIFEED_DUALBOX && attacker != null)
{
final L2PcInstance attackerPlayer = attacker.getActingPlayer();
if (attackerPlayer == null)
return false;
final L2GameClient targetClient = targetPlayer.getClient();
final L2GameClient attackerClient = attackerPlayer.getClient();
if (targetClient == null
|| attackerClient == null
|| targetClient.isDetached()
|| attackerClient.isDetached())
// unable to check ip address
return !Config.ANTIFEED_DISCONNECTED_AS_DUALBOX;
return !targetClient.getConnection().getInetAddress().equals(attackerClient.getConnection().getInetAddress());
}
return true;
}
/**
* Clears all timestamps
*/
public final void clear()
{
_lastDeathTimes.clear();
}
/**
* Register new event for dualbox check.
* Should be called only once.
* @param eventId
*/
public final void registerEvent(int eventId)
{
if (!_eventIPs.containsKey(eventId))
_eventIPs.put(eventId, new HashMap<Integer, Connections>());
}
/**
* 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 final boolean removePlayer(int eventId, L2PcInstance player)
{
final L2GameClient client = player.getClient();
if (client == null)
return false; // unable to determine IP address
final Map<Integer, Connections> event = _eventIPs.get(eventId);
if (event == null)
return false; // no such event registered
final Integer addrHash = Integer.valueOf(client.getConnection().getInetAddress().hashCode());
Connections conns = event.get(addrHash);
if (conns == null)
return false; // address not registered
synchronized (event)
{
if (conns.testAndDecrement())
event.remove(addrHash);
}
return true;
}
/**
* Remove player connection IP address from all registered events lists.
* @param client
*/
public final void onDisconnect(L2GameClient client)
{
if (client == null)
return;
final Integer addrHash = Integer.valueOf(client.getConnection().getInetAddress().hashCode());
_eventIPs.forEachValue(new DisconnectProcedure(addrHash));
}
/**
* Clear all entries for this eventId.
* @param eventId
*/
public final void clear(int eventId)
{
final Map<Integer, Connections> event = _eventIPs.get(eventId);
if (event != null)
event.clear();
}
protected static final class Connections
{
private int _num = 0;
/**
* and false if maximum number is reached.
* @param max
* @return true if successfully incremented number of connections
*/
public final synchronized boolean testAndIncrement(int max)
{
if (_num < max)
{
_num++;
return true;
}
return false;
}
/**
* @return true if all connections are removed
*/
public final synchronized boolean testAndDecrement()
{
if (_num > 0)
_num--;
return _num == 0;
}
}
private static final class DisconnectProcedure implements TObjectProcedure<Map<Integer, Connections>>
{
private final Integer _addrHash;
public DisconnectProcedure(Integer addrHash)
{
_addrHash = addrHash;
}