Add NoSlow check, fix broken strafe check, fix false positives with speed check, fix BadPackets false positive.

This commit is contained in:
Rammelkast committed 2020-08-06 15:45:25 +02:00
1 parent 5f181c556e
commit 7cd90cfb61
15 files changed
+185 -25

No files matched your search

+3 -2
View File
@@ -24,7 +24,6 @@ Hacks blocked
* Flight/Glide
* ElytraFly
* WaterWalk/Jesus
* NoSwing
* FastBreak
* FastPlace
* Chat spam
@@ -49,4 +48,6 @@ Hacks blocked
* BadPackets
* Velocity/Anti-Knockback
* IllegalInteract (Scaffold)
* FastLadder
* FastLadder
* Strafe
* NoSlow
@@ -105,8 +105,9 @@ public class AntiCheatReloaded extends JavaPlugin {
: (ChatColor.RED + "(NOT SUPPORTED!)")));
getLogger().info("Enabling packet listeners");
PacketListener.listenKeepAlivePackets();
PacketListener.listenMovementPackets();
PacketListener.listenKeepAlivePackets();
PacketListener.listenUseItemPackets();
updateManager = new UpdateManager();
@@ -41,6 +41,7 @@ import com.rammelkast.anticheatreloaded.check.combat.VelocityCheck;
import com.rammelkast.anticheatreloaded.check.movement.AimbotCheck;
import com.rammelkast.anticheatreloaded.check.movement.ElytraCheck;
import com.rammelkast.anticheatreloaded.check.movement.FlightCheck;
import com.rammelkast.anticheatreloaded.check.movement.NoSlowCheck;
import com.rammelkast.anticheatreloaded.check.packet.MorePacketsCheck;
import com.rammelkast.anticheatreloaded.config.Configuration;
import com.rammelkast.anticheatreloaded.config.providers.Checks;
@@ -156,6 +157,8 @@ public class Backend {
KillAuraCheck.ANGLE_FLAGS.remove(uuid);
KillAuraCheck.PACKETORDER_FLAGS.remove(uuid);
FlightCheck.MOVING_EXEMPT.remove(uuid);
NoSlowCheck.LAST_RELEASE.remove(uuid);
NoSlowCheck.VIOLATIONS.remove(uuid);
}
public CheckResult checkFastBow(Player player, float force) {
@@ -63,7 +63,8 @@ public enum CheckType {
ILLEGAL_INTERACT(Permission.CHECK_ILLEGALINTERACT, "IllegalInteract"),
FASTLADDER(Permission.CHECK_FASTLADDER, "FastLadder"),
AIMBOT(Permission.CHECK_AIMBOT, "Aimbot"),
STRAFE(Permission.CHECK_STRAFE, "Strafe");
STRAFE(Permission.CHECK_STRAFE, "Strafe"),
NOSLOW(Permission.CHECK_NOSLOW, "NoSlow");
private final Permission permission;
private final String displayName;
@@ -0,0 +1,81 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
*
* 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 com.rammelkast.anticheatreloaded.check.movement;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.entity.Player;
import com.comphenix.protocol.events.PacketEvent;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.CheckResult;
import com.rammelkast.anticheatreloaded.check.CheckType;
import com.rammelkast.anticheatreloaded.config.providers.Checks;
import com.rammelkast.anticheatreloaded.event.EventListener;
import com.rammelkast.anticheatreloaded.util.MovementManager;
import com.rammelkast.anticheatreloaded.util.User;
public class NoSlowCheck {
public static final Map<UUID, Long> LAST_RELEASE = new HashMap<UUID, Long>();
public static final Map<UUID, Integer> VIOLATIONS = new HashMap<UUID, Integer>();
public static void runCheck(Player player, PacketEvent event) {
if (!AntiCheatReloaded.getManager().getCheckManager().willCheck(player, CheckType.NOSLOW))
return;
UUID uuid = player.getUniqueId();
User user = AntiCheatReloaded.getManager().getUserManager().getUser(uuid);
MovementManager movementManager = user.getMovementManager();
Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks();
final long time = System.currentTimeMillis();
final long lastRelease = LAST_RELEASE.getOrDefault(uuid, 0L);
LAST_RELEASE.put(uuid, time);
if (lastRelease == 0L)
return;
long difference = time - lastRelease;
long minimumDifference = checksConfig.getInteger(CheckType.NOSLOW, "minimumDifference");
if (difference < minimumDifference
&& movementManager.distanceXZ >= checksConfig.getDouble(CheckType.NOSLOW, "minimumDistXZ")) {
int violations = VIOLATIONS.getOrDefault(uuid, 1);
if (violations++ >= checksConfig.getInteger(CheckType.NOSLOW, "vlBeforeFlag")) {
violations = 0;
flag(player, event,
"toggled use item too fast (diff=" + difference + ", min=" + minimumDifference + ")");
}
VIOLATIONS.put(uuid, violations);
}
}
private static void flag(Player player, PacketEvent event, String message) {
event.setCancelled(true);
// We are currently not in the main server thread, so switch
AntiCheatReloaded.sendToMainThread(new Runnable() {
@Override
public void run() {
EventListener.log(new CheckResult(CheckResult.Result.FAILED, message).getMessage(), player,
CheckType.NOSLOW);
player.teleport(player.getLocation());
}
});
}
}
@@ -85,8 +85,10 @@ public class SpeedCheck {
predict += slimeIncrement;
}
// Adjust for speed effects
if (player.hasPotionEffect(PotionEffectType.SPEED))
if (movementManager.hasSpeedEffect)
predict += VersionUtil.getPotionLevel(player, PotionEffectType.SPEED) * 0.05D;
if (movementManager.hadSpeedEffect && !movementManager.hasSpeedEffect)
limit *= 1.2D;
// Adjust for jump boost effects
if (player.hasPotionEffect(PotionEffectType.JUMP))
predict += VersionUtil.getPotionLevel(player, PotionEffectType.JUMP) * 0.05D;
@@ -104,15 +106,17 @@ public class SpeedCheck {
// Strafing in air when nearing terminal velocity gives false positives
// This fixes the issue but gives hackers some leniency which means we need another check for this
double deltaMotionY = movementManager.motionY - movementManager.lastMotionY;
if (deltaMotionY < 0 && deltaMotionY >= -0.06)
predict *= 1.5D;
if ((deltaMotionY < 0 && deltaMotionY >= -0.08) || movementManager.airTicks >= 40
&& (movingTowards.getBlockY() - player.getWorld().getHighestBlockYAt(movingTowards)) <= 1.5)
predict *= (movementManager.airTicks > 60 ? 4.0D : (movementManager.airTicks > 30 ? 3.0D : 2.0D));
// Players can move faster in air with slow falling
if (VersionUtil.isSlowFalling(player))
predict *= 1.25D;
// Prevent NoSlow
// TODO better way for this
if (player.isBlocking() && movementManager.airTicks > 2)
if (movementManager.blockingTicks > 2 && movementManager.airTicks > 2)
predict *= 0.8D;
if (movementManager.blockingTicks > 10 && movementManager.airTicks > 2)
predict *= 0.5D;
// Fixes false positive when coming out of water
if (movementManager.nearLiquidTicks >= 7 && movementManager.airTicks >= 14
&& movementManager.motionY < -0.18 && movementManager.motionY > -0.182)
@@ -120,7 +124,7 @@ public class SpeedCheck {
if (distanceXZ - predict > limit) {
return new CheckResult(CheckResult.Result.FAILED, "moved too fast in air (speed=" + distanceXZ
+ ", limit=" + predict + ", block=" + player.isBlocking() + ", box=" + boxedIn + ", at=" + movementManager.airTicks + ")");
+ ", limit=" + predict + ", block=" + movementManager.blockingTicks + ", box=" + boxedIn + ", at=" + movementManager.airTicks + ")");
}
}
@@ -182,8 +186,12 @@ public class SpeedCheck {
if (boxedIn)
limit *= 1.1D;
// Adjust for speed effects
if (player.hasPotionEffect(PotionEffectType.SPEED))
if (movementManager.hasSpeedEffect)
limit += VersionUtil.getPotionLevel(player, PotionEffectType.SPEED) * 0.06D;
if (movementManager.hasSpeedEffect && movementManager.groundTicks > 3)
limit *= 1.4D;
if (movementManager.hadSpeedEffect && !movementManager.hasSpeedEffect)
limit *= 1.2D;
if (movementManager.iceInfluenceTicks >= 50) {
// When moving off ice
if (!Utilities.couldBeOnIce(movingTowards))
@@ -219,7 +227,7 @@ public class SpeedCheck {
if (distanceXZ - limit > 0) {
return new CheckResult(CheckResult.Result.FAILED,
"moved too fast on ground (speed=" + distanceXZ + ", limit=" + limit + ", blocking=" + player.isBlocking() + ")");
"moved too fast on ground (speed=" + distanceXZ + ", limit=" + limit + ", blocking=" + player.isBlocking() + ", gt=" + movementManager.groundTicks + ")");
}
}
@@ -29,6 +29,7 @@ import com.rammelkast.anticheatreloaded.check.CheckResult.Result;
import com.rammelkast.anticheatreloaded.config.providers.Checks;
import com.rammelkast.anticheatreloaded.util.MovementManager;
import com.rammelkast.anticheatreloaded.util.Utilities;
import com.rammelkast.anticheatreloaded.util.VersionUtil;
/**
*
@@ -41,14 +42,14 @@ public class StrafeCheck {
public static CheckResult runCheck(Player player, double x, double z, Location from, Location to) {
if (!Utilities.cantStandAtExp(from) || !Utilities.cantStandAtExp(to) || Utilities.isNearWater(player)
|| Utilities.isNearClimbable(player))
|| Utilities.isNearClimbable(player) || VersionUtil.isFlying(player) || player.isDead())
return PASS;
MovementManager movementManager = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId())
.getMovementManager();
Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks();
if (System.currentTimeMillis() - movementManager.lastTeleport >= checksConfig.getInteger(CheckType.STRAFE,
if (System.currentTimeMillis() - movementManager.lastTeleport <= checksConfig.getInteger(CheckType.STRAFE,
"accountForTeleports") || movementManager.elytraEffectTicks >= 20)
return PASS;
@@ -58,7 +58,7 @@ public class BadPacketsCheck {
MovementManager movementManager = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId())
.getMovementManager();
if (user.isLagging() || tps < checksConfig.getDouble(CheckType.MOREPACKETS, "minimumTps")
|| (System.currentTimeMillis() - movementManager.lastTeleport <= 100))
|| (System.currentTimeMillis() - movementManager.lastTeleport <= 150))
return;
double x = packet.getDoubles().read(0);
@@ -70,10 +70,13 @@ public class BadPacketsCheck {
Location current = new Location(previous.getWorld(), x, y, z, yaw, pitch);
double distance = previous.distanceSquared(current);
double maxDistance = checksConfig.getDouble(CheckType.BADPACKETS, "maxDistance");
// Fix falling false
if (movementManager.airTicks >= 40 && movementManager.motionY < 0 && movementManager.lastMotionY < 0)
maxDistance *= 1.5D;
boolean hasNewLocation = packet.getBooleans().read(0);
if (distance > maxDistance) {
flag(player, event, "moved too far between packets (distance="
+ new BigDecimal(distance).setScale(1, RoundingMode.HALF_UP) + ", max=" + maxDistance + ")");
+ new BigDecimal(distance).setScale(1, RoundingMode.HALF_UP) + ", max=" + maxDistance + ", at=" + movementManager.airTicks + ")");
return;
} else if (distance < 1E-10 && !hasNewLocation) {
// TODO this gives false positives when teleporting
@@ -135,10 +135,7 @@ public class PlayerListener extends EventListener {
@EventHandler
public void onPlayerTeleport(PlayerTeleportEvent event) {
if (event.getCause() == TeleportCause.ENDER_PEARL || event.getCause() == TeleportCause.PLUGIN) {
getBackend().logTeleport(event.getPlayer());
}
getBackend().logTeleport(event.getPlayer());
AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
}
@@ -1,3 +1,21 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
*
* 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 com.rammelkast.anticheatreloaded.event;
import org.bukkit.entity.Player;
@@ -20,6 +20,7 @@ package com.rammelkast.anticheatreloaded.util;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
@@ -81,6 +82,12 @@ public class MovementManager {
public int sneakingTicks;
// Ticks counter after being near a liquid
public int nearLiquidTicks;
// Ticks of player blocking
public int blockingTicks;
// If the player has a speed effect
public boolean hasSpeedEffect = false;
// If the player had speed effect previous tick
public boolean hadSpeedEffect = false;
// Time of last update
public long lastUpdate;
@@ -146,6 +153,11 @@ public class MovementManager {
this.sneakingTicks++;
else
this.sneakingTicks = 0;
if (player.isBlocking())
this.blockingTicks++;
else
this.blockingTicks = 0;
if (Utilities.isNearWater(player))
this.nearLiquidTicks = 8;
@@ -155,6 +167,9 @@ public class MovementManager {
else
this.nearLiquidTicks = 0;
}
this.hadSpeedEffect = this.hasSpeedEffect;
this.hasSpeedEffect = player.hasPotionEffect(PotionEffectType.SPEED);
double lastDistanceSq = Math.sqrt(this.lastDistance.getXDifference() * this.lastDistance.getXDifference()
+ this.lastDistance.getZDifference() * this.lastDistance.getZDifference());
@@ -24,7 +24,9 @@ import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerDigType;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.movement.NoSlowCheck;
import com.rammelkast.anticheatreloaded.check.packet.BadPacketsCheck;
import com.rammelkast.anticheatreloaded.check.packet.MorePacketsCheck;
@@ -38,6 +40,8 @@ public class PacketListener {
@Override
public void onPacketReceiving(PacketEvent event) {
Player player = event.getPlayer();
if (player == null || !player.isOnline())
return;
// Run MorePackets check
MorePacketsCheck.runCheck(player, event);
@@ -76,5 +80,16 @@ public class PacketListener {
}
});
}
public static void listenUseItemPackets() {
AntiCheatReloaded.getProtocolManager().addPacketListener(new PacketAdapter(AntiCheatReloaded.getPlugin(),
ListenerPriority.LOWEST, new PacketType[] { PacketType.Play.Client.BLOCK_DIG }) {
@Override
public void onPacketReceiving(PacketEvent event) {
if (event.getPacket().getPlayerDigTypes().read(0) == PlayerDigType.RELEASE_USE_ITEM)
NoSlowCheck.runCheck(event.getPlayer(), event);
}
});
}
}
@@ -27,7 +27,7 @@ public enum Permission {
CHECK_SNEAK, CHECK_SPEED, CHECK_VCLIP, CHECK_SPIDER, CHECK_NOFALL, CHECK_FASTBOW, CHECK_FASTEAT, CHECK_FASTHEAL,
CHECK_KILLAURA, CHECK_UNICODE, CHECK_FASTPROJECTILE, CHECK_ITEMSPAM, CHECK_FASTINVENTORY,
CHECK_MOREPACKETS, CHECK_BADPACKETS, CHECK_VELOCITY, CHECK_CRITICALS, CHECK_ILLEGALINTERACT, CHECK_FASTLADDER,
CHECK_AIMBOT, CHECK_STRAFE,
CHECK_AIMBOT, CHECK_STRAFE, CHECK_NOSLOW,
/* System Nodes */
SYSTEM_LOG, SYSTEM_RESET, SYSTEM_HELP, SYSTEM_VERSION, SYSTEM_REPORT, SYSTEM_NOTICE, SYSTEM_CHECK, SYSTEM_RELOAD,
+13 -1
View File
@@ -18,7 +18,7 @@ flight:
accountForTpsDrops: 250
# How many milliseconds to account for teleports
# Increase this is you debug 'had too little Y dropoff' after teleports
accountForTeleports: 100
accountForTeleports: 150
# Checks for climbing behaviour in air
# Debugs as 'tried to climb air'
airClimb:
@@ -306,6 +306,18 @@ sneak:
# Minimum time in milliseconds between sneak toggles
minToggleTime: 75
# NoSlow check settings
# Checks if the player moves too fast while blocking
noslow:
# Should this check be enabled?
enabled: true
# Minimum time difference in milliseconds between toggling use item state
minimumDifference: 75
# Minimum movement distance needed to flag
minimumDistXZ: 0.15
# Amount of no slowdown moments before flagging
vlBeforeFlag: 3
# Spider check settings
# Checks if the player tries to climb a non-climbable block
spider:
+6 -2
View File
@@ -127,9 +127,12 @@ permissions:
anticheat.check.aimbot:
description: Allow players to use aimbot
default: false
anticheat.check.aimbot:
anticheat.check.strafe:
description: Allow players to use strafe hacks
default: false
anticheat.check.noslow:
description: Allow players to use NoSlow hacks
default: false
anticheat.check.exempt:
description: Total exemption from checks
default: false
@@ -161,4 +164,5 @@ permissions:
anticheat.check.illegalinteract: true
anticheat.check.fastladder: true
anticheat.check.aimbot: true
anticheat.check.strafe: true
anticheat.check.strafe: true
anticheat.check.noslow: true