mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-02 22:16:03 +00:00
Add NoSlow check, fix broken strafe check, fix false positives with speed check, fix BadPackets false positive.
This commit is contained in:
1 parent
5f181c556e
commit
7cd90cfb61
15 files changed
+185
-25
No files matched your search
@@ -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;
|
||||
|
||||
|
||||
Reference in new issue
Block a user