diff --git a/src/main/java/com/rammelkast/anticheatreloaded/AntiCheatReloaded.java b/src/main/java/com/rammelkast/anticheatreloaded/AntiCheatReloaded.java index 65cd481..35b6be4 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/AntiCheatReloaded.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/AntiCheatReloaded.java @@ -93,60 +93,13 @@ public class AntiCheatReloaded extends JavaPlugin { if (!VersionUtil.isSupported()) { Bukkit.getConsoleSender().sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.RED + "The version of this server is NOT supported by ACR! The plugin will be buggy!"); } + getLogger().info("Enabling checks that use ProtcolLib"); // Enable packetlisteners BlinkCheck.startTimer(); BlinkCheck.listenPackets(); KillAuraCheck.listenPackets(); - // Check if other AC's are installed - Bukkit.getScheduler().runTaskLater(this, new Runnable() { - public void run() { - if (Bukkit.getPluginManager().getPlugin("NoCheatPlus") != null) { - getLogger().severe("*----------------------------------------------*"); - getLogger().severe("You are also running NoCheatPlus!"); - getLogger().severe("Multiple anticheats create false cheat detections."); - getLogger().severe("Please remove or disable NoCheatPlus to silence this warning."); - getLogger().severe("*----------------------------------------------*"); - } - if (Bukkit.getPluginManager().getPlugin("Matrix") != null) { - getLogger().severe("*----------------------------------------------*"); - getLogger().severe("You are also running Matrix!"); - getLogger().severe("Multiple anticheats create false cheat detections."); - getLogger().severe("Please remove or disable NoCheatPlus to silence this warning."); - getLogger().severe("*----------------------------------------------*"); - } - if (Bukkit.getPluginManager().getPlugin("AAC") != null) { - getLogger().severe("*----------------------------------------------*"); - getLogger().severe("You are also running AAC!"); - getLogger().severe("Multiple anticheats create false cheat detections."); - getLogger().severe("Please remove or disable AAC to silence this warning."); - getLogger().severe("*----------------------------------------------*"); - } - if (Bukkit.getPluginManager().getPlugin("Spartan") != null) { - getLogger().severe("*----------------------------------------------*"); - getLogger().severe("You are also running Spartan!"); - getLogger().severe("Multiple anticheats create false cheat detections."); - getLogger().severe("Please remove or disable AAC to silence this warning."); - getLogger().severe("*----------------------------------------------*"); - } - if (Bukkit.getPluginManager().getPlugin("NoAura") != null) { - getLogger().severe("*----------------------------------------------*"); - getLogger().severe("You are also running NoAura!"); - getLogger().severe("Multiple anticheats create false cheat detections."); - getLogger().severe("Please remove or disable AAC to silence this warning."); - getLogger().severe("*----------------------------------------------*"); - } - if (Bukkit.getPluginManager().getPlugin("AntiCheat") != null || Bukkit.getPluginManager().getPlugin("AntiCheatPlus") != null) { - getLogger().severe("*----------------------------------------------*"); - getLogger().severe("You are also running AntiCheat!"); - getLogger().severe("Multiple anticheats create false cheat detections."); - getLogger().severe("Please remove or disable AntiCheat to silence this warning."); - getLogger().severe("*----------------------------------------------*"); - } - } - }, 90L); - updateManager = new UpdateManager(); // End tests @@ -175,7 +128,6 @@ public class AntiCheatReloaded extends JavaPlugin { public String call() throws Exception { return VersionUtil.getVersion(); } - })); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java b/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java index 3ba8ac8..3fc1883 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java @@ -178,6 +178,9 @@ public class Backend { SpeedCheck.SPEED_VIOLATIONS.remove(player.getUniqueId()); ElytraCheck.JUMP_Y_VALUE.remove(player.getUniqueId().toString()); KillAuraCheck.ANGLE_FLAGS.remove(player.getUniqueId().toString()); + KillAuraCheck.CLICKSPEED_MAP.remove(player.getUniqueId().toString()); + KillAuraCheck.DEVIATION_SCORES.remove(player.getUniqueId().toString()); + KillAuraCheck.DIFF_MAP.remove(player.getUniqueId().toString()); } public CheckResult checkFastBow(Player player, float force) { diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/combat/KillAuraCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/combat/KillAuraCheck.java index 12129b8..30bb501 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/combat/KillAuraCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/combat/KillAuraCheck.java @@ -19,7 +19,9 @@ package com.rammelkast.anticheatreloaded.check.combat; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.bukkit.Location; @@ -30,11 +32,15 @@ import org.bukkit.event.entity.EntityDamageEvent; import com.rammelkast.anticheatreloaded.AntiCheatReloaded; import com.rammelkast.anticheatreloaded.check.CheckResult; +import com.rammelkast.anticheatreloaded.config.providers.Magic; import com.rammelkast.anticheatreloaded.util.checkassist.KillauraAssist; public class KillAuraCheck { public static final Map ANGLE_FLAGS = new HashMap(); + public static final Map DEVIATION_SCORES = new HashMap(); + public static final Map DIFF_MAP = new HashMap(); + public static final Map CLICKSPEED_MAP = new HashMap(); private static final KillauraAssist KILLAURA_ASSIST; private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED); @@ -77,6 +83,82 @@ public class KillAuraCheck { return PASS; } + public static CheckResult checkFightSpeed(Player player, EntityDamageEvent event) { + if (!CLICKSPEED_MAP.containsKey(player.getUniqueId().toString())) { + CLICKSPEED_MAP.put(player.getUniqueId().toString(), new ClickSpeed()); + return PASS; + } + ClickSpeed clickSpeed = CLICKSPEED_MAP.get(player.getUniqueId().toString()); + clickSpeed.registerClick(); + int deviationScore = clickSpeed.getDeviationScore(); + // Prevents false positives since scores under 2000 aren't reliable + if (deviationScore < 2000) { + return PASS; + } + + if (!DEVIATION_SCORES.containsKey(player.getUniqueId().toString())) { + DEVIATION_SCORES.put(player.getUniqueId().toString(), deviationScore); + return PASS; + } + + Magic magic = AntiCheatReloaded.getManager().getConfiguration().getMagic(); + int lastScore = DEVIATION_SCORES.get(player.getUniqueId().toString()); + DEVIATION_SCORES.put(player.getUniqueId().toString(), deviationScore); + int diff = Math.abs(deviationScore - lastScore); + if (!DIFF_MAP.containsKey(player.getUniqueId().toString())) { + DIFF_MAP.put(player.getUniqueId().toString(), diff); + return PASS; + } + int lastDiff = DIFF_MAP.get(player.getUniqueId().toString()); + DIFF_MAP.put(player.getUniqueId().toString(), diff); + if (Math.abs(diff - lastDiff) < magic.KILLAURA_FIGHTSPEED_MINDIFF()) { + event.setCancelled(true); + return new CheckResult(CheckResult.Result.FAILED, "had a suspiciously consistant fighting speed (absdiff=" + Math.abs(diff - lastDiff) + ")"); + } + return PASS; + } + + private static class ClickSpeed { + private final List clicks; + private long lastClick; + + public ClickSpeed() { + this.clicks = new ArrayList(); + this.lastClick = System.currentTimeMillis(); + } + + public void registerClick() { + this.lastClick = System.currentTimeMillis(); + this.clicks.add(this.lastClick); + } + + public int getDeviationScore() { + long last = 0; + List deviation = new ArrayList(); + List toRemove = new ArrayList(); + for (long clickTime : this.clicks) { + if (clickTime > (this.lastClick - 5000)) { + if (last == 0) { + last = clickTime; + continue; + } + deviation.add((int) (clickTime - last)); + } else { + toRemove.add(clickTime); + } + } + this.clicks.removeAll(toRemove); + if (deviation.isEmpty()) { + return -1; + } + float averageDeviationScore = deviation.get(0); + for (int i = 1; i < deviation.size(); i++) { + averageDeviationScore += deviation.get(i); + } + return Math.round(averageDeviationScore / deviation.size()); + } + } + static { KILLAURA_ASSIST = new KillauraAssist(); } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/ElytraCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/ElytraCheck.java index 93cff46..f37b0be 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/ElytraCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/ElytraCheck.java @@ -30,9 +30,6 @@ import com.rammelkast.anticheatreloaded.AntiCheatReloaded; import com.rammelkast.anticheatreloaded.check.CheckResult; import com.rammelkast.anticheatreloaded.util.Distance; -/** - * TODO - */ public class ElytraCheck { public static final HashMap JUMP_Y_VALUE = new HashMap(); diff --git a/src/main/java/com/rammelkast/anticheatreloaded/config/providers/Magic.java b/src/main/java/com/rammelkast/anticheatreloaded/config/providers/Magic.java index 67310f5..c849ecc 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/config/providers/Magic.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/config/providers/Magic.java @@ -382,6 +382,10 @@ public interface Magic { * The maximum amount of violations before flagging player as a cheater; TYPE=INTEGER, Leniency=INCREASE */ public int KILLAURA_MAX_ANGLE_VIOLATIONS(); + /** + * The minimum score difference for the fight speed check to consider a player legit; TYPE=INTEGER, Leniency=DECREASE + */ + public int KILLAURA_FIGHTSPEED_MINDIFF(); /** * The maximum angle difference allowed when breaking or placing blocks; TYPE=INTEGER, Leniency=INCREASE */ diff --git a/src/main/java/com/rammelkast/anticheatreloaded/event/EntityListener.java b/src/main/java/com/rammelkast/anticheatreloaded/event/EntityListener.java index 21df348..b05d43a 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/event/EntityListener.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/event/EntityListener.java @@ -160,6 +160,14 @@ public class EntityListener extends EventListener { noHack = false; } } + if (getCheckManager().willCheck(player, CheckType.KILLAURA)) { + CheckResult result = KillAuraCheck.checkFightSpeed(player, event); + if (result.failed()) { + event.setCancelled(!silentMode()); + log(result.getMessage(), player, CheckType.KILLAURA); + noHack = false; + } + } if (noHack) { decrease(player); } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/event/EventListener.java b/src/main/java/com/rammelkast/anticheatreloaded/event/EventListener.java index be84ed0..8a9827b 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/event/EventListener.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/event/EventListener.java @@ -29,6 +29,7 @@ import com.rammelkast.anticheatreloaded.check.CheckType; import com.rammelkast.anticheatreloaded.config.Configuration; import com.rammelkast.anticheatreloaded.manage.*; import com.rammelkast.anticheatreloaded.util.User; +import com.rammelkast.anticheatreloaded.util.VersionUtil; import java.util.EnumMap; import java.util.HashMap; @@ -49,7 +50,7 @@ public class EventListener implements Listener { if (message == null || message.equals("")) { message = ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.GRAY + player.getName() + " failed " + CheckType.getName(type); } else { - message = ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.GRAY + player.getName() + " failed " + CheckType.getName(type) + ChatColor.DARK_GRAY + " | " + ChatColor.GRAY + message; + message = ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.GRAY + player.getName() + " failed " + CheckType.getName(type) + ChatColor.DARK_GRAY + " | " + ChatColor.GRAY + message + ChatColor.DARK_GRAY + " | " + ChatColor.GRAY + "ping: " + VersionUtil.getPlayerPing(player) + "ms"; } if (user != null) { // npc logCheat(type, user); diff --git a/src/main/java/com/rammelkast/anticheatreloaded/manage/AntiCheatManager.java b/src/main/java/com/rammelkast/anticheatreloaded/manage/AntiCheatManager.java index 1b27ef1..0ffac73 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/manage/AntiCheatManager.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/manage/AntiCheatManager.java @@ -11,12 +11,11 @@ * 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. + * 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 . */ - package com.rammelkast.anticheatreloaded.manage; import java.util.Map; @@ -33,7 +32,6 @@ import com.rammelkast.anticheatreloaded.config.Configuration; /** * The internal hub for all managers. */ - public class AntiCheatManager { private static AntiCheatReloaded plugin = null; private static Configuration configuration; diff --git a/src/main/resources/magic.yml b/src/main/resources/magic.yml index 856426c..93365d2 100644 --- a/src/main/resources/magic.yml +++ b/src/main/resources/magic.yml @@ -259,6 +259,10 @@ KILLAURA_MAX_ANGLE_DIFFERENCE: 50 # The maximum amount of violations before flagging player as a cheater # Increase this in case of false positives KILLAURA_MAX_ANGLE_VIOLATIONS: 3 +# The minimum score difference for the fight speed check to consider a player legit +# Increasing this will tighten check but might punish combat consistancy +# Decrease this in case of false positives +KILLAURA_FIGHTSPEED_MINDIFF: 3 # The maximum angle difference allowed when placing or breaking a block # Increase this in case of false positives, can be slightly decreased to tighten check ILLEGALINTERACT_MAX_ANGLE_DIFFERENCE: 75 \ No newline at end of file