mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-02 22:16:03 +00:00
Recoded MorePackets, fixed false positive. This commit is a release candidate.
This commit is contained in:
1 parent
918549bc11
commit
f94a430d41
9 files changed
+100
-72
No files matched your search
@@ -157,9 +157,11 @@ public class Backend {
|
||||
inventoryClicks.remove(uuid);
|
||||
lastFallPacket.remove(uuid);
|
||||
fastSneakViolations.remove(uuid);
|
||||
lastSneak.remove(uuid);
|
||||
AimbotCheck.LAST_DELTA_YAW.remove(uuid);
|
||||
VelocityCheck.VIOLATIONS.remove(uuid);
|
||||
MorePacketsCheck.MOVE_COUNT.remove(uuid);
|
||||
MorePacketsCheck.LAST_PACKET_TIME.remove(uuid);
|
||||
MorePacketsCheck.PACKET_BALANCE.remove(uuid);
|
||||
GlideCheck.LAST_MOTION_Y.remove(uuid);
|
||||
GlideCheck.LAST_FALL_DISTANCE.remove(uuid);
|
||||
GlideCheck.VIOLATIONS.remove(uuid);
|
||||
@@ -640,9 +642,15 @@ public class Backend {
|
||||
}
|
||||
|
||||
public CheckResult checkFastHeal(Player player) {
|
||||
User user = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId());
|
||||
if (lastHeal.containsKey(player.getUniqueId())) // Otherwise it was modified by a plugin, don't worry about it.
|
||||
{
|
||||
long healTime = magic.MIN_HEAL_TIME();
|
||||
double tps = AntiCheatReloaded.getPlugin().getTPS();
|
||||
if (tps < 17.5
|
||||
|| user.isLagging()) {
|
||||
return PASS;
|
||||
}
|
||||
long healTime = magic.MIN_HEAL_TIME() - (tps >= 18.5 ? 0 : 50);
|
||||
long l = lastHeal.get(player.getUniqueId());
|
||||
lastHeal.remove(player.getUniqueId());
|
||||
if ((System.currentTimeMillis() - l) < healTime) {
|
||||
@@ -654,8 +662,13 @@ public class Backend {
|
||||
}
|
||||
|
||||
public CheckResult checkFastEat(Player player) {
|
||||
User user = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId());
|
||||
if (startEat.containsKey(player.getUniqueId())) // Otherwise it was modified by a plugin, don't worry about it.
|
||||
{
|
||||
if (AntiCheatReloaded.getPlugin().getTPS() < 17.5
|
||||
|| user.isLagging()) {
|
||||
return PASS;
|
||||
}
|
||||
long l = startEat.get(player.getUniqueId());
|
||||
startEat.remove(player.getUniqueId());
|
||||
if ((System.currentTimeMillis() - l) < magic.EAT_TIME_MIN()) {
|
||||
|
||||
@@ -50,7 +50,7 @@ public class AimbotCheck {
|
||||
LAST_DELTA_YAW.put(uuid, dYaw);
|
||||
|
||||
float absoluteYawDifference = Math.abs(dYaw - lastDeltaYaw);
|
||||
if (absoluteYawDifference < 1E-8 && dYaw > 30 && dYaw < 360) {
|
||||
if (absoluteYawDifference < 1E-8 && dYaw > 30 && dYaw < 355) {
|
||||
return new CheckResult(CheckResult.Result.FAILED, "repeated yaw difference (dYaw=" + dYaw + ")");
|
||||
}
|
||||
return PASS;
|
||||
|
||||
@@ -23,14 +23,13 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
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.Magic;
|
||||
import com.rammelkast.anticheatreloaded.event.EventListener;
|
||||
|
||||
/**
|
||||
@@ -38,16 +37,8 @@ import com.rammelkast.anticheatreloaded.event.EventListener;
|
||||
*/
|
||||
public class MorePacketsCheck {
|
||||
|
||||
public static final Map<UUID, Integer> MOVE_COUNT = new HashMap<UUID, Integer>();
|
||||
|
||||
public static void startTimer() {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MOVE_COUNT.clear();
|
||||
}
|
||||
}.runTaskTimer(AntiCheatReloaded.getPlugin(), 20, 20);
|
||||
}
|
||||
public static final Map<UUID, Long> LAST_PACKET_TIME = new HashMap<UUID, Long>();
|
||||
public static final Map<UUID, Double> PACKET_BALANCE = new HashMap<UUID, Double>();
|
||||
|
||||
public static void runCheck(Player player, PacketEvent event) {
|
||||
// Confirm if we should even check for MorePackets
|
||||
@@ -56,50 +47,47 @@ public class MorePacketsCheck {
|
||||
if (!AntiCheatReloaded.getManager().getCheckManager().willCheck(player, CheckType.MOREPACKETS) || tps < 15) {
|
||||
return;
|
||||
}
|
||||
Location currentLocation = event.getPlayer().getLocation();
|
||||
if (!MOVE_COUNT.containsKey(player.getUniqueId())) {
|
||||
MOVE_COUNT.put(player.getUniqueId(), 1);
|
||||
} else {
|
||||
MOVE_COUNT.put(player.getUniqueId(), MOVE_COUNT.get(player.getUniqueId()) + 1);
|
||||
int ping = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId()).getPing();
|
||||
int limit = AntiCheatReloaded.getManager().getBackend().getMagic().MOREPACKETS_LIMIT();
|
||||
int averagePing = AntiCheatReloaded.getManager().getBackend().getMagic().MOREPACKETS_AVERAGE_PING();
|
||||
float pingLeniency = (float) ((ping / averagePing));
|
||||
if (pingLeniency < 1)
|
||||
pingLeniency = 1;
|
||||
if (pingLeniency > 2)
|
||||
pingLeniency = 2;
|
||||
float tpsLeniency = (float) ((19 / tps));
|
||||
if (tps > 19) {
|
||||
tpsLeniency = 1;
|
||||
}
|
||||
float leniency = pingLeniency * tpsLeniency;
|
||||
limit = Math.round(leniency * limit);
|
||||
final float finalLeniency = leniency;
|
||||
try {
|
||||
if (MOVE_COUNT.get(player.getUniqueId()) > limit) {
|
||||
final int packets = MOVE_COUNT.get(player.getUniqueId());
|
||||
MOVE_COUNT.remove(player.getUniqueId());
|
||||
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,
|
||||
"sent " + packets + " packets in one second (max="
|
||||
+ AntiCheatReloaded.getManager().getBackend().getMagic()
|
||||
.MOREPACKETS_LIMIT()
|
||||
+ ", leniency=" + finalLeniency + ")").getMessage(),
|
||||
player, CheckType.MOREPACKETS);
|
||||
player.teleport(currentLocation);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (NullPointerException exception) {
|
||||
// Irrelevant
|
||||
}
|
||||
|
||||
UUID uuid = player.getUniqueId();
|
||||
Magic magic = AntiCheatReloaded.getManager().getConfiguration().getMagic();
|
||||
long packetTimeNow = System.currentTimeMillis();
|
||||
long lastPacketTime = LAST_PACKET_TIME.getOrDefault(uuid, packetTimeNow - 50L);
|
||||
double packetBalance = PACKET_BALANCE.getOrDefault(uuid, 0D);
|
||||
|
||||
long rate = packetTimeNow - lastPacketTime;
|
||||
packetBalance += 50;
|
||||
packetBalance -= rate;
|
||||
if (packetBalance >= magic.MOREPACKETS_TRIGGER_BALANCE()) {
|
||||
int ticks = (int) Math.round(packetBalance / 50);
|
||||
packetBalance = -1 * (magic.MOREPACKETS_TRIGGER_BALANCE() / 2);
|
||||
flag(player, event, "overshot timer by " + ticks + " tick(s)");
|
||||
} else if (packetBalance < -1 * (magic.MOREPACKETS_MINIMUM_CLAMP())) {
|
||||
// Clamp minimum, 50ms=1tick of lag leniency
|
||||
packetBalance = -1 * (magic.MOREPACKETS_MINIMUM_CLAMP());
|
||||
}
|
||||
|
||||
LAST_PACKET_TIME.put(uuid, packetTimeNow);
|
||||
PACKET_BALANCE.put(uuid, packetBalance);
|
||||
}
|
||||
|
||||
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.MOREPACKETS);
|
||||
player.teleport(player.getLocation());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void compensate(Player player) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
Magic magic = AntiCheatReloaded.getManager().getConfiguration().getMagic();
|
||||
double packetBalance = PACKET_BALANCE.getOrDefault(uuid, 0D);
|
||||
PACKET_BALANCE.put(uuid, packetBalance - magic.MOREPACKETS_TELEPORT_COMPENSATION());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user