Started on movement check recode. First up: speed check!

This commit is contained in:
Rammelkast committed 2020-06-10 20:29:49 +02:00
1 parent 610d53550f
commit 636f94b408
11 files changed
+241 -103

No files matched your search

+25 -22
View File
@@ -21,29 +21,32 @@ Please include the following information with your issue, this allows me to fix
Hacks blocked
-------
* Flight
* Glide
* FastLadder
* Jesus
* Step
* Criticals
* Anti-Knockback
* FastBow
* FastDrop
* Reach
* Spider
* Speed
* NoFall
* Sneak
* vClip
* Flight/Glide
* ElytraFly
* WaterWalk/Jesus
* NoSwing
* FastBreak
* FastPlace
* Spam
* Chat spam
* Command spam
* Sprint
* (Packet)Sneak
* Speed
* Vclip
* Spider
* NoFall
* FastBow
* FastEat
* ElytraFly
* FastHeal
* KillAura (Aimbot)
* Reach
* Unicode chat
* GhostHand
* KillAura
* Scaffold
* MorePackets
* BadPackets
* FastProjectile
* ItemSpam
* FastInventory
* AutoTool
* MorePackets/Timer
* BadPackets
* Velocity/Anti-Knockback
* IllegalInteract (Scaffold)
* FastLadder
+1 -1
View File
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.rammelkast.anticheatreloaded</groupId>
<artifactId>AntiCheatReloaded</artifactId>
<version>1.8.2-PRE</version>
<version>1.9.0-PRE</version>
<name>AntiCheatReloaded</name>
<url>https://www.spigotmc.org/resources/anticheatreloaded.23799/</url>
<properties>
@@ -166,7 +166,7 @@ public class Backend {
GlideCheck.LAST_MOTION_Y.remove(uuid);
GlideCheck.LAST_FALL_DISTANCE.remove(uuid);
GlideCheck.VIOLATIONS.remove(uuid);
SpeedCheck.SPEED_VIOLATIONS.remove(uuid);
SpeedCheck.JUMPBEHAVIOUR_VIOLATIONS.remove(uuid);
ElytraCheck.JUMP_Y_VALUE.remove(uuid);
KillAuraCheck.ANGLE_FLAGS.remove(uuid);
FlightCheck.MOVING_EXEMPT.remove(uuid);
@@ -780,7 +780,8 @@ public class Backend {
}
public void logTeleport(final Player player) {
FlightCheck.MOVING_EXEMPT.put(player.getUniqueId(), System.currentTimeMillis() + magic.TELEPORT_TIME());
// TODO check this
//FlightCheck.MOVING_EXEMPT.put(player.getUniqueId(), System.currentTimeMillis() + magic.TELEPORT_TIME());
/* Data for fly/speed should be reset */
nofallViolation.remove(player.getUniqueId());
@@ -22,8 +22,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
@@ -31,88 +30,92 @@ import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.Backend;
import com.rammelkast.anticheatreloaded.check.CheckResult;
import com.rammelkast.anticheatreloaded.util.Distance;
import com.rammelkast.anticheatreloaded.util.MovementManager;
import com.rammelkast.anticheatreloaded.util.Utilities;
import com.rammelkast.anticheatreloaded.util.VersionUtil;
/**
* This check is an outdated mess which needs to be replaced
* @author Rammelkast
*
* Features:
* + AirSpeed A
* + AirAcceleration A
* + JumpBehaviour A
*
* Planned:
* + GroundSpeed A
* + GroundAcceleration A
* + AirSpeed B
* + JumpBehaviour B
*/
public class SpeedCheck {
public static final Map<UUID, Integer> SPEED_VIOLATIONS = new HashMap<UUID, Integer>();
public static final Map<UUID, Integer> JUMPBEHAVIOUR_VIOLATIONS = new HashMap<UUID, Integer>();
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
public static boolean isSpeedExempt(Player player, Backend backend) {
return backend.isMovingExempt(player) || backend.justVelocity(player) || VersionUtil.isFlying(player);
}
public static CheckResult checkXZSpeed(Player player, double x, double z) {
public static CheckResult checkXZSpeed(Player player, double x, double z, Location movingTowards) {
Backend backend = AntiCheatReloaded.getManager().getBackend();
if (!isSpeedExempt(player, backend) && player.getVehicle() == null) {
String reason = "";
double max = backend.getMagic().XZ_SPEED_MAX();
if (player.getLocation().getBlock().getType() == Material.SOUL_SAND) {
if (player.isSprinting()) {
reason = "on soulsand while sprinting ";
max = backend.getMagic().XZ_SPEED_MAX_SOULSAND_SPRINT();
} else if (player.hasPotionEffect(PotionEffectType.SPEED)) {
reason = "on soulsand with speed potion ";
max = backend.getMagic().XZ_SPEED_MAX_SOULSAND_POTION();
} else {
reason = "on soulsand ";
max = backend.getMagic().XZ_SPEED_MAX_SOULSAND();
}
} else if (VersionUtil.isFlying(player)) {
reason = "while flying ";
max = backend.getMagic().XZ_SPEED_MAX_FLY();
} else if (player.hasPotionEffect(PotionEffectType.SPEED)) {
if (player.isSprinting()) {
reason = "with speed potion while sprinting ";
max = backend.getMagic().XZ_SPEED_MAX_POTION_SPRINT();
} else {
reason = "with speed potion ";
max = backend.getMagic().XZ_SPEED_MAX_POTION();
}
} else if (player.isSprinting()) {
String blockDownName = player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType().name();
if (blockDownName.endsWith("ICE")
&& (player.getEyeLocation().getBlock().getRelative(BlockFace.UP).getType() != Material.AIR)) {
if (player.getLocation().getBlock().getType().name().endsWith("TRAPDOOR")) {
reason = "while boosting on " + blockDownName.toLowerCase().replaceAll("_", " ")
+ " and trapdoor";
max = backend.getMagic().XZ_SPEED_MAX_SPRINT()
+ (blockDownName.equals("BLUE_ICE") ? 0.35925D : 0.35D);
} else {
reason = "while boosting on " + blockDownName.toLowerCase().replaceAll("_", " ") + " ";
max = backend.getMagic().XZ_SPEED_MAX_SPRINT()
+ (blockDownName.equals("BLUE_ICE") ? 0.20925D : 0.2D);
}
} else {
reason = "while sprinting ";
max = backend.getMagic().XZ_SPEED_MAX_SPRINT();
}
}
float speed = player.getWalkSpeed();
max += speed > 0 ? player.getWalkSpeed() - 0.2f : 0;
if (x > max || z > max) {
int num = backend.increment(player, SPEED_VIOLATIONS, backend.getMagic().SPEED_MAX());
if (num >= backend.getMagic().SPEED_MAX()) {
return new CheckResult(CheckResult.Result.FAILED,
"speed was too high " + reason + num + " times in a row (max="
+ backend.getMagic().SPEED_MAX() + ", speed=" + (x > z ? x : z) + ", max speed="
+ max + ")");
} else {
return PASS;
}
} else {
SPEED_VIOLATIONS.put(player.getUniqueId(), 0);
return PASS;
}
} else {
if (isSpeedExempt(player, backend) || player.getVehicle() != null)
return PASS;
MovementManager movementManager = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId())
.getMovementManager();
double distanceXZ = Math.sqrt(x * x + z * z);
// AirSpeed A
// As of right now, this falses with speed effects and slimes
if (movementManager.airTicks > 1) {
double multiplier = 0.9808305131D;
double predict = 0.3597320645 * Math.pow(multiplier, movementManager.airTicks + 1);
// Adjust for ice boost
if (movementManager.iceInfluenceTicks > 0) {
predict += 0.105 * Math.pow(1.09, movementManager.iceInfluenceTicks);
}
if (distanceXZ - predict > 0.03075) {
return new CheckResult(CheckResult.Result.FAILED,
"moved too fast in air (speed=" + distanceXZ + ", predict=" + predict + ")");
}
}
// AirAcceleration A
// As of right now, this falses with speed effects and slimes
if (movementManager.airTicks > 1 && movementManager.iceInfluenceTicks <= 0) {
double initialAcceleration = movementManager.acceleration;
// TODO calculate instead of defined value
if (initialAcceleration > 0.36) {
return new CheckResult(CheckResult.Result.FAILED,
"exceeded acceleration limits (acceleration=" + initialAcceleration + ", max=0.36)");
}
}
// JumpBehaviour A
// Has a rare false positive when sprintjumping around corners
// Works against YPorts and mini jumps
if (movementManager.touchedGroundThisTick) {
// This happens naturally as well when walking next to walls
if (movementManager.airTicksBeforeGrounded == movementManager.groundTicks) {
boolean movingFreely = Utilities.cantStandClose(movingTowards.getBlock())
&& Utilities.cantStandFar(movingTowards.getBlock());
if (movingFreely) {
int vl = JUMPBEHAVIOUR_VIOLATIONS.getOrDefault(player.getUniqueId(), 0);
// TODO config for this value
if (vl++ > 1) {
JUMPBEHAVIOUR_VIOLATIONS.remove(player.getUniqueId());
return new CheckResult(CheckResult.Result.FAILED,
"had unexpected jumping behaviour");
}
JUMPBEHAVIOUR_VIOLATIONS.put(player.getUniqueId(), vl);
return PASS;
} else {
JUMPBEHAVIOUR_VIOLATIONS.remove(player.getUniqueId());
}
}
}
return PASS;
}
public static CheckResult checkYSpeed(Player player, Distance distance) {
@@ -121,13 +124,12 @@ public class SpeedCheck {
&& (distance.getYDifference() > backend.getMagic().Y_SPEED_MAX())
&& !backend.isDoing(player, backend.velocitized, backend.getMagic().VELOCITY_TIME())
&& !player.hasPotionEffect(PotionEffectType.JUMP) && !VersionUtil.isFlying(player)
&& !VersionUtil.isRiptiding(player)
&& !Utilities.isNearBed(distance.getTo())
&& !VersionUtil.isRiptiding(player) && !Utilities.isNearBed(distance.getTo())
&& !Utilities.isSlime(AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId())
.getGoodLocation(player.getLocation()).getBlock())
&& !Utilities.couldBeOnBoat(player)) {
return new CheckResult(CheckResult.Result.FAILED,
"y speed was too high (speed=" + distance.getYDifference() + ", max=" + backend.getMagic().Y_SPEED_MAX() + ")");
return new CheckResult(CheckResult.Result.FAILED, "y speed was too high (speed=" + distance.getYDifference()
+ ", max=" + backend.getMagic().Y_SPEED_MAX() + ")");
} else {
return PASS;
}
@@ -366,6 +366,7 @@ public class PlayerListener extends EventListener {
final User user = getUserManager().getUser(player.getUniqueId());
user.setTo(to.getX(), to.getY(), to.getZ());
user.getMovementManager().handle(player, from, to, distance);
if (getCheckManager().willCheckQuick(player, CheckType.FLIGHT) && !VersionUtil.isFlying(player)) {
CheckResult result = FlightCheck.runCheck(player, distance);
@@ -430,7 +431,7 @@ public class PlayerListener extends EventListener {
changed = true;
}
}
CheckResult result = SpeedCheck.checkXZSpeed(player, x, z);
CheckResult result = SpeedCheck.checkXZSpeed(player, x, z, event.getTo());
if (result.failed()) {
if (!silentMode()) {
event.setTo(user.getGoodLocation(from.clone()));
@@ -43,6 +43,18 @@ public class Distance {
this.from = from;
this.to = to;
}
public Distance() {
l1Y = 0;
l2Y = 0;
XDiff = 0;
ZDiff = 0;
YDiff = 0;
this.from = null;
this.to = null;
}
public double fromY() {
return l2Y;
@@ -0,0 +1,73 @@
/*
* 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.util;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class MovementManager {
// Ticks in air
public int airTicks = 0;
// Ticks on ground
public int groundTicks = 0;
// Ticks on ice
public int iceTicks = 0;
// Ticks in air before last grounded moment
public int airTicksBeforeGrounded = 0;
// Ticks influenced by ice
public int iceInfluenceTicks = 0;
// If the player touched the ground again this tick
public boolean touchedGroundThisTick = false;
// Last recorded distance
public Distance lastDistance = new Distance();
// Movement acceleration
public double acceleration;
public void handle(Player player, Location from, Location to, Distance distance) {
boolean serverOnGround = !Utilities.cantStandAtExp(to) || Utilities.couldBeOnBoat(player);
this.touchedGroundThisTick = false;
if (!serverOnGround) {
this.groundTicks = 0;
this.airTicks++;
} else {
if (this.airTicks > 0)
this.touchedGroundThisTick = true;
this.airTicksBeforeGrounded = this.airTicks;
this.airTicks = 0;
this.groundTicks++;
}
if (Utilities.couldBeOnIce(to)) {
this.iceTicks++;
this.iceInfluenceTicks = 14;
} else {
this.iceTicks = 0;
if (this.iceInfluenceTicks > 0)
this.iceInfluenceTicks--;
}
double lastDistanceSq = Math.sqrt(this.lastDistance.getXDifference() * this.lastDistance.getXDifference()
+ this.lastDistance.getZDifference() * this.lastDistance.getZDifference());
double currentDistanceSq = Math.sqrt(distance.getXDifference() * distance.getXDifference()
+ distance.getZDifference() * distance.getZDifference());
this.acceleration = currentDistanceSq - lastDistanceSq;
}
}
@@ -33,7 +33,7 @@ public class PacketListener {
public static void listenMovementPackets() {
AntiCheatReloaded.getProtocolManager()
.addPacketListener(new PacketAdapter(AntiCheatReloaded.getPlugin(), ListenerPriority.LOWEST,
new PacketType[] { PacketType.Play.Client.POSITION, PacketType.Play.Client.POSITION_LOOK}) {
new PacketType[] { PacketType.Play.Client.POSITION, PacketType.Play.Client.POSITION_LOOK, PacketType.Play.Server.POSITION }) {
@Override
public void onPacketReceiving(PacketEvent event) {
Player player = event.getPlayer();
@@ -50,7 +50,6 @@ public class PacketListener {
@Override
public void onPacketSending(PacketEvent event) {
Player player = event.getPlayer();
// Compensate for teleport
MorePacketsCheck.compensate(player);
}
@@ -55,6 +55,8 @@ public class User {
private long lastServerPing, lastClientPong;
private int ping = -1;
private int lastPing = -1;
private MovementManager movementManager;
/**
* Initialize an AntiCheat user
@@ -65,6 +67,7 @@ public class User {
this.uuid = uuid;
this.name = getPlayer() != null && getPlayer().isOnline() ? getPlayer().getName() : "";
this.id = getPlayer() != null && getPlayer().isOnline() ? getPlayer().getEntityId() : -1;
this.movementManager = new MovementManager();
}
/**
@@ -218,7 +221,12 @@ public class User {
return location;
}
return goodLocation;
Location moveTo = goodLocation;
if (location != null) {
moveTo.setPitch(location.getPitch());
moveTo.setYaw(location.getYaw());
}
return moveTo;
}
/**
@@ -452,6 +460,10 @@ public class User {
public boolean isLagging() {
return Math.abs(this.ping - this.lastPing) > config.getMagic().LAG_DETERMINATION();
}
public MovementManager getMovementManager() {
return this.movementManager;
}
@Override
public String toString() {
@@ -131,6 +131,41 @@ public final class Utilities {
return false;
}
/**
* Determine whether a player could be standing on ice
*
* @param location the location to check
* @return true if the player could be standing on ice
*/
public static boolean couldBeOnIce(Location location) {
return isNearIce(new Location(location.getWorld(), fixXAxis(location.getX()), location.getY() - 0.01D,
location.getBlockZ()));
}
/**
* Determine whether a block is a type of ice
*
* @param block block to check
* @return true if block is a type of ice
*/
public static boolean isIce(Block block) {
Material type = block.getType();
return type.name().endsWith("ICE");
}
public static boolean isNearIce(Location location) {
return isIce(location.getBlock())
|| isIce(location.getBlock().getRelative(BlockFace.NORTH))
|| isIce(location.getBlock().getRelative(BlockFace.SOUTH))
|| isIce(location.getBlock().getRelative(BlockFace.EAST))
|| isIce(location.getBlock().getRelative(BlockFace.WEST))
|| isIce(location.getBlock().getRelative(BlockFace.NORTH_EAST))
|| isBed(location.getBlock().getRelative(BlockFace.NORTH_WEST))
|| isIce(location.getBlock().getRelative(BlockFace.SOUTH_EAST))
|| isIce(location.getBlock().getRelative(BlockFace.SOUTH_WEST));
}
/**
* Determine whether a player is fully submerged in water
*
+2 -2
View File
@@ -244,11 +244,11 @@ GLIDE_LIMIT: 5
# The amount of milliseconds to compensate for a teleport (50ms = 1 tick)
# Increase this in case of false positives
# Can be decreased in to tighten check
MOREPACKETS_TELEPORT_COMPENSATION: 200
MOREPACKETS_TELEPORT_COMPENSATION: 150
# The amount of milliseconds that were offset to flag for MorePackets (50ms = 1 tick)
# Increase this in case of false positives
# Can be decreased in to tighten check
MOREPACKETS_TRIGGER_BALANCE: 100
MOREPACKETS_TRIGGER_BALANCE: 50
# The maximum amount of overall lag compensating in milliseconds (50ms = 1 tick)
# Increase this in case of false positives
# Can be decreased in to tighten check