Improved inventory check

This commit is contained in:
h31ix committed 2012-12-17 16:34:02 -05:00
1 parent 1999b4a4f4
commit 5d9f29fc41
4 files changed
+28 -54

No files matched your search

@@ -43,8 +43,12 @@ public class InventoryListener extends EventListener{
{
if(backend.checkInventoryClicks(player))
{
event.setCancelled(!config.silentMode());
log("tried to use inventories too fast", player, CheckType.FAST_INVENTORY);
if(!config.silentMode())
{
event.setCancelled(!config.silentMode());
player.setHealth(0);
}
log("tried to use their inventory too fast", player, CheckType.FAST_INVENTORY);
}
else
{
@@ -87,7 +87,7 @@ public class Backend
private Map<String, Integer> blocksDropped = new HashMap<String, Integer>();
private Map<String, Long> lastInventoryTime = new HashMap<String, Long>();
private Map<String, Long> inventoryTime = new HashMap<String, Long>();
private Map<String, Integer> inventoryChanges = new HashMap<String, Integer>();
private Map<String, Integer> inventoryClicks = new HashMap<String, Integer>();
private Map<String, Material> itemInHand = new HashMap<String, Material>();
private Map<String, Integer> steps = new HashMap<String, Integer>();
private Map<String, Long> stepTime = new HashMap<String, Long>();
@@ -165,9 +165,9 @@ public class Backend
blocksDropped.remove(pN);
lastInventoryTime.remove(pN);
inventoryTime.remove(pN);
inventoryChanges.remove(pN);
inventoryClicks.remove(pN);
}
public boolean checkFreeze(Player player, double from, double to)
{
if((from-to) > 0)
@@ -967,46 +967,22 @@ public class Backend
public boolean checkInventoryClicks(Player player)
{
String name = player.getName();
long time = System.currentTimeMillis();
if (!inventoryTime.containsKey(name) || !inventoryChanges.containsKey(name))
int clicks = 1;
if(inventoryClicks.containsKey(name))
{
inventoryTime.put(name, 0l);
if (!inventoryChanges.containsKey(name))
{
inventoryChanges.put(name, 0);
}
clicks = inventoryClicks.get(name)+1;
}
else if (inventoryChanges.containsKey(name) && inventoryChanges.get(name) > magic.INVENTORY_MAXVIOLATIONS)
inventoryClicks.put(name, clicks);
if(clicks == 1)
{
long diff = System.currentTimeMillis() - lastInventoryTime.get(name);
if (inventoryTime.get(name) > 0 && diff < magic.INVENTORY_MAXVIOLATIONTIME)
{
inventoryTime.put(name, diff);
player.sendMessage(ChatColor.RED + "[AntiCheat] Inventory hack detected. Please wait 10 seconds before using inventories.");
return true;
}
else if (inventoryTime.get(name) > 0 && diff > magic.INVENTORY_MAXVIOLATIONTIME)
{
inventoryChanges.put(name, 0);
}
inventoryTime.put(name,System.currentTimeMillis());
}
else if (inventoryTime.containsKey(name))
else if(clicks == magic.INVENTORY_CHECK)
{
long last = lastInventoryTime.get(name);
long thisTime = time - last;
if (thisTime < magic.INVENTORY_TIMEMAX)
{
inventoryChanges.put(name, inventoryChanges.get(name) + 1);
if (inventoryChanges.get(name) > magic.INVENTORY_MAXVIOLATIONS)
{
inventoryTime.put(name, thisTime);
player.sendMessage(ChatColor.RED + "[AntiCheat] Inventory hack detected. Please wait 10 seconds before using inventories.");
return true;
}
}
inventoryTime.put(name, thisTime);
long time = System.currentTimeMillis()-inventoryTime.get(name);
inventoryClicks.put(name, 0);
return time < magic.INVENTORY_TIMEMIN;
}
lastInventoryTime.put(name, time);
return false;
}
@@ -1213,7 +1189,7 @@ public class Backend
public boolean isAscending(Player player)
{
return isAscending.contains(player.getName());
}
}
public boolean isSpeedExempt(Player player)
{
@@ -321,17 +321,13 @@ public class Magic
*/
public final int SPEED_MAX;
/**
* Number of times a player can fail the inventory check before action is taken; Type=integer, +Leniency=Increase.
* The number of clicks we should wait before checking if the player has used fast inventory; Type=integer; +Leniency=Increase.
*/
public final int INVENTORY_MAXVIOLATIONS;
public final int INVENTORY_CHECK;
/**
* Time player is forced to wait after inventory detection; Type=integer; +Leniency=Decrease.
* The minimum time it should have taken for the player to click X times; Type=integer; +Leniency=Increase.
*/
public final int INVENTORY_MAXVIOLATIONTIME;
/**
* Time between inventory changes that triggers inventory violations; Type=integer; +Leniency=Decrease.
*/
public final int INVENTORY_TIMEMAX;
public final long INVENTORY_TIMEMIN;
/**
* The number of steps we should wait before checking if the player has used timer cheating; Type=integer; +Leniency=Increase.
*/
@@ -422,9 +418,8 @@ public class Magic
XZ_SPEED_MAX_SOULSAND_SPRINT = getDouble("XZ_SPEED_MAX_SOULSAND_SPRINT");
XZ_SPEED_MAX_WATER_SPRINT = getDouble("XZ_SPEED_MAX_WATER_SPRINT");
SPEED_MAX = getInt("SPEED_MAX");
INVENTORY_MAXVIOLATIONS = getInt("INVENTORY_MAXVIOLATIONS");
INVENTORY_MAXVIOLATIONTIME = getInt("INVENTORY_MAXVIOLATIONTIME");
INVENTORY_TIMEMAX = getInt("INVENTORY_TIMEMAX");
INVENTORY_CHECK = getInt("INVENTORY_CHECK");
INVENTORY_TIMEMIN = getInt("INVENTORY_TIMEMIN");
TIMER_STEP_CHECK = getInt("TIMER_STEP_CHECK");
TIMER_TIMEMIN = getLong("TIMER_TIMEMIN");
}