mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-03 06:28:52 +00:00
Merge pull request #116 from psycowithespn/master
Implement inventory hack check. Fixes Issue 55
This commit is contained in:
commit
216ee45096
8 files changed
+130
-1
No files matched your search
@@ -60,6 +60,7 @@ public class Anticheat extends JavaPlugin
|
|||||||
eventList.add(new BlockListener());
|
eventList.add(new BlockListener());
|
||||||
eventList.add(new EntityListener());
|
eventList.add(new EntityListener());
|
||||||
eventList.add(new VehicleListener());
|
eventList.add(new VehicleListener());
|
||||||
|
eventList.add(new InventoryListener());
|
||||||
// Order is important in some cases, don't screw with these unless needed, especially config
|
// Order is important in some cases, don't screw with these unless needed, especially config
|
||||||
setupConfig();
|
setupConfig();
|
||||||
// Xray must come before events
|
// Xray must come before events
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* AntiCheat for Bukkit.
|
||||||
|
* Copyright (C) 2012 AntiCheat Team | http://gravitydevelopment.net
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.h31ix.anticheat.event;
|
||||||
|
|
||||||
|
import net.h31ix.anticheat.Anticheat;
|
||||||
|
import net.h31ix.anticheat.manage.Backend;
|
||||||
|
import net.h31ix.anticheat.manage.CheckManager;
|
||||||
|
import net.h31ix.anticheat.manage.CheckType;
|
||||||
|
import net.h31ix.anticheat.util.Configuration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
|
||||||
|
public class InventoryListener extends EventListener{
|
||||||
|
|
||||||
|
private final Backend backend = getBackend();
|
||||||
|
private final CheckManager checkManager = getCheckManager();
|
||||||
|
private final Configuration config = Anticheat.getManager().getConfiguration();
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInventoryClick(InventoryClickEvent event)
|
||||||
|
{
|
||||||
|
if (event.getWhoClicked() instanceof Player)
|
||||||
|
{
|
||||||
|
Player player = (Player) event.getWhoClicked();
|
||||||
|
if(checkManager.willCheck(player, CheckType.FAST_INVENTORY))
|
||||||
|
{
|
||||||
|
if(backend.checkInventoryClicks(player))
|
||||||
|
{
|
||||||
|
event.setCancelled(!config.silentMode());
|
||||||
|
log("tried to use inventories too fast", player, CheckType.FAST_INVENTORY);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
decrease(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -83,6 +83,9 @@ public class Backend
|
|||||||
private Map<String, Long> movingExempt = new HashMap<String, Long>();
|
private Map<String, Long> movingExempt = new HashMap<String, Long>();
|
||||||
private Map<String, Long> blockTime = new HashMap<String, Long>();
|
private Map<String, Long> blockTime = new HashMap<String, Long>();
|
||||||
private Map<String, Integer> blocksDropped = new HashMap<String, Integer>();
|
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 Magic magic;
|
private Magic magic;
|
||||||
private AnticheatManager micromanage = null;
|
private AnticheatManager micromanage = null;
|
||||||
@@ -883,6 +886,51 @@ public class Backend
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean checkInventoryClicks(Player player)
|
||||||
|
{
|
||||||
|
String name = player.getName();
|
||||||
|
long time = System.currentTimeMillis();
|
||||||
|
if (!inventoryTime.containsKey(name) || !inventoryChanges.containsKey(name))
|
||||||
|
{
|
||||||
|
inventoryTime.put(name, 0l);
|
||||||
|
if(!inventoryChanges.containsKey(name))
|
||||||
|
{
|
||||||
|
inventoryChanges.put(name, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (inventoryChanges.containsKey(name) && inventoryChanges.get(name) > magic.INVENTORY_MAXVIOLATIONS)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (inventoryTime.containsKey(name))
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
lastInventoryTime.put(name, time);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public void clearChatLevel(Player player)
|
public void clearChatLevel(Player player)
|
||||||
{
|
{
|
||||||
chatLevel.remove(player.getName());
|
chatLevel.remove(player.getName());
|
||||||
|
|||||||
@@ -52,7 +52,8 @@ public enum CheckType
|
|||||||
XRAY(Permission.CHECK_XRAY),
|
XRAY(Permission.CHECK_XRAY),
|
||||||
LONG_REACH(Permission.CHECK_LONGREACH),
|
LONG_REACH(Permission.CHECK_LONGREACH),
|
||||||
FAST_PROJECTILE(Permission.CHECK_FASTPROJECTILE),
|
FAST_PROJECTILE(Permission.CHECK_FASTPROJECTILE),
|
||||||
ITEM_SPAM(Permission.CHECK_ITEMSPAM);
|
ITEM_SPAM(Permission.CHECK_ITEMSPAM),
|
||||||
|
FAST_INVENTORY(Permission.CHECK_FASTINVENTORY);
|
||||||
|
|
||||||
private final Permission permission;
|
private final Permission permission;
|
||||||
private final Map<String, Integer> level = new HashMap<String, Integer>();
|
private final Map<String, Integer> level = new HashMap<String, Integer>();
|
||||||
|
|||||||
@@ -304,6 +304,18 @@ public class Magic
|
|||||||
* Maximum times a player can fail the speed check before action is taken; Type=integer, +Leniency=Increase.
|
* Maximum times a player can fail the speed check before action is taken; Type=integer, +Leniency=Increase.
|
||||||
*/
|
*/
|
||||||
public final int SPEED_MAX;
|
public final int SPEED_MAX;
|
||||||
|
/**
|
||||||
|
* Number of times a player can fail the inventory check before action is taken; Type=integer, +Leniency=Increase.
|
||||||
|
*/
|
||||||
|
public final int INVENTORY_MAXVIOLATIONS;
|
||||||
|
/**
|
||||||
|
* Time player is forced to wait after inventory detection; Type=integer; +Leniency=Decrease.
|
||||||
|
*/
|
||||||
|
public final int INVENTORY_MAXVIOLATIONTIME;
|
||||||
|
/**
|
||||||
|
* Time between inventory changes that triggers inventory violations; Type=integer; +Leniency=Decrease.
|
||||||
|
*/
|
||||||
|
public final int INVENTORY_TIMEMAX;
|
||||||
|
|
||||||
private FileConfiguration defaults;
|
private FileConfiguration defaults;
|
||||||
private FileConfiguration magic;
|
private FileConfiguration magic;
|
||||||
@@ -382,6 +394,9 @@ public class Magic
|
|||||||
XZ_SPEED_MAX_WATER = getDouble("XZ_SPEED_MAX_WATER");
|
XZ_SPEED_MAX_WATER = getDouble("XZ_SPEED_MAX_WATER");
|
||||||
XZ_SPEED_MAX_WATER_SPRINT = getDouble("XZ_SPEED_MAX_WATER_SPRINT");
|
XZ_SPEED_MAX_WATER_SPRINT = getDouble("XZ_SPEED_MAX_WATER_SPRINT");
|
||||||
SPEED_MAX = getInt("SPEED_MAX");
|
SPEED_MAX = getInt("SPEED_MAX");
|
||||||
|
INVENTORY_MAXVIOLATIONS = getInt("INVENTORY_MAXVIOLATIONS");
|
||||||
|
INVENTORY_MAXVIOLATIONTIME = getInt("INVENTORY_MAXVIOLATIONTIME");
|
||||||
|
INVENTORY_TIMEMAX = getInt("INVENTORY_TIMEMAX");
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getInt(String path)
|
private int getInt(String path)
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ public enum Permission
|
|||||||
CHECK_FASTPROJECTILE,
|
CHECK_FASTPROJECTILE,
|
||||||
CHECK_ITEMSPAM,
|
CHECK_ITEMSPAM,
|
||||||
CHECK_VISUAL,
|
CHECK_VISUAL,
|
||||||
|
CHECK_FASTINVENTORY,
|
||||||
|
|
||||||
/* System Nodes */
|
/* System Nodes */
|
||||||
SYSTEM_LOG,
|
SYSTEM_LOG,
|
||||||
|
|||||||
@@ -67,3 +67,6 @@ XZ_SPEED_MAX_SNEAK: 0.2
|
|||||||
XZ_SPEED_MAX_WATER: 0.19
|
XZ_SPEED_MAX_WATER: 0.19
|
||||||
XZ_SPEED_MAX_WATER_SPRINT: 0.3
|
XZ_SPEED_MAX_WATER_SPRINT: 0.3
|
||||||
SPEED_MAX: 3
|
SPEED_MAX: 3
|
||||||
|
INVENTORY_MAXVIOLATIONS: 2
|
||||||
|
INVENTORY_MAXVIOLATIONTIME: 10000
|
||||||
|
INVENTORY_TIMEMAX: 50
|
||||||
@@ -122,6 +122,9 @@ permissions:
|
|||||||
anticheat.check.vclip:
|
anticheat.check.vclip:
|
||||||
description: Allow players to become slimeballs and clip down through blocks
|
description: Allow players to become slimeballs and clip down through blocks
|
||||||
default: false
|
default: false
|
||||||
|
anticheat.check.fastinventory:
|
||||||
|
description: Allows players to use fastloot and similar inventory hacks
|
||||||
|
default: false
|
||||||
anticheat.check.exempt:
|
anticheat.check.exempt:
|
||||||
description: Total exemption from checks
|
description: Total exemption from checks
|
||||||
default: false
|
default: false
|
||||||
@@ -150,3 +153,4 @@ permissions:
|
|||||||
anticheat.check.itemspam: true
|
anticheat.check.itemspam: true
|
||||||
anticheat.check.visual: true
|
anticheat.check.visual: true
|
||||||
anticheat.check.vclip: true
|
anticheat.check.vclip: true
|
||||||
|
anticheat.check.fastinventory: true
|
||||||
Reference in new issue
Block a user