Recoded MorePackets, fixed false positive. This commit is a release candidate.

This commit is contained in:
Rammelkast committed 2020-05-13 17:16:04 +02:00
1 parent 918549bc11
commit f94a430d41
9 files changed
+100 -72

No files matched your search

@@ -166,8 +166,6 @@ public class AntiCheatReloaded extends JavaPlugin {
}
}
}.runTaskTimer(this, 40L, 1L);
// Launch MorePackets timer
MorePacketsCheck.startTimer();
}
@Override
@@ -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());
}
}
@@ -157,6 +157,7 @@ public class CommandReport extends CommandBase {
if (page <= pages && page > 0) {
cs.sendMessage(GOLD + "----------------------[" + GRAY + "Page " + page + "/" + pages + "" + GOLD + "]----------------------");
cs.sendMessage(GRAY + "Player: " + WHITE + name);
cs.sendMessage(GRAY + "Ping: " + WHITE + user.getPing() + "ms " + (user.isLagging() ? ChatColor.RED + "(lagging)" : ChatColor.GREEN + "(not lagging)"));
cs.sendMessage(GRAY + "Group: " + groupString);
for (int x = 0; x < 6; x++) {
int index = ((page - 1) * 5) + (x + ((page - 1)));
@@ -177,6 +178,7 @@ public class CommandReport extends CommandBase {
if (pages == 0 && page == 1) {
cs.sendMessage(GOLD + "----------------------[" + GRAY + "Page 1/1" + GOLD + "]----------------------");
cs.sendMessage(GRAY + "Player: " + WHITE + name);
cs.sendMessage(GRAY + "Ping: " + WHITE + user.getPing() + "ms " + (user.isLagging() ? ChatColor.RED + "(lagging)" : ChatColor.GREEN + "(not lagging)"));
cs.sendMessage(GRAY + "Group: " + groupString);
cs.sendMessage(GRAY + "This user has not failed any checks.");
cs.sendMessage(MENU_END);
@@ -359,13 +359,17 @@ public interface Magic {
*/
public int TELEPORT_MIN();
/**
* Maximum amount of packets a player can send in a second; Type=INTEGER, Leniency=INCREASE.
* The amount of milliseconds to compensate for a teleport; Type=INTEGER, Leniency=INCREASE.
*/
public int MOREPACKETS_LIMIT();
public int MOREPACKETS_TELEPORT_COMPENSATION();
/**
* The average ping settings used to account for lag; TYPE=INTEGER, Leniency=INCREASE
* The amount of milliseconds that were offset to flag for MorePackets; Type=INTEGER, Leniency=INCREASE.
*/
public int MOREPACKETS_AVERAGE_PING();
public int MOREPACKETS_TRIGGER_BALANCE();
/**
* The maximum amount of overall lag compensating in milliseconds; Type=INTEGER, Leniency=INCREASE.
*/
public int MOREPACKETS_MINIMUM_CLAMP();
/**
* Maximum amount of low/zero velocity moments before flagging; Type=INTEGER, Leniency=INCREASE.
*/
@@ -398,4 +402,8 @@ public interface Magic {
* Maximum amount of fastladder movements before flagging; TYPE=INTEGER, Leniency=INCREASE
*/
public int FASTLADDER_MAX_FLAGS();
/**
* The change milliseconds between two keepalives before considering a player to be lagging; TYPE=INTEGER, Leniency=DECREASE
*/
public int LAG_DETERMINATION();
}
@@ -47,6 +47,15 @@ public class PacketListener {
BadPacketsCheck.runCheck(player, event);
}
}
@Override
public void onPacketSending(PacketEvent event) {
Player player = event.getPlayer();
User user = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId());
// Compensate for teleport
MorePacketsCheck.compensate(player);
}
});
}
@@ -450,7 +450,7 @@ public class User {
}
public boolean isLagging() {
return Math.abs(this.ping - this.lastPing) > 50;
return Math.abs(this.ping - this.lastPing) > config.getMagic().LAG_DETERMINATION();
}
@Override