From b57d7745e4b28757c3bbfe0cd98cfa4e259c1b6c Mon Sep 17 00:00:00 2001 From: asofold Date: Wed, 29 Oct 2014 01:09:26 +0100 Subject: [PATCH] [BLEEDING] Refine logging on logout. Actually set-back on logout. * Always log location of logout if debug is set. * Also check inconsistent logout if manahattan distance is > 0. * Only perform "passable check" only if enabled and not dead/sleeping. * Try to actually set-back. --- .../checks/moving/MovingListener.java | 46 ++++++++++++------- .../nocheatplus/checks/moving/Passable.java | 1 + .../nocheatplus/logging/DebugUtil.java | 23 ++++++++++ .../nocheatplus/logging/LogUtil.java | 1 - 4 files changed, 54 insertions(+), 17 deletions(-) diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java index f67fc865..ec931ed9 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java @@ -1353,28 +1353,42 @@ public class MovingListener extends CheckListener implements TickListener, IRemo @Override public void playerLeaves(final Player player) { + final MovingConfig cc = MovingConfig.getConfig(player); final MovingData data = MovingData.getData(player); - // Check for missed moves. final Location loc = player.getLocation(useLoc); - if (!BlockProperties.isPassable(loc)) { - boolean warn = false; - if (data.toX != Double.MAX_VALUE) { - final Location refLoc = new Location(loc.getWorld(), data.toX, data.toY, data.toZ); - final double d = refLoc.distanceSquared(loc); - if (d > 0.0) { - if (BlockProperties.isPassable(refLoc)) { - warn = true; - StringBuilder builder = new StringBuilder(128); - DebugUtil.addMove(refLoc, loc, null, builder); - LogUtil.logWarning("[NoCheatPlus] Potential exploit: Player " + player.getName() + " logs out having moved into a block: " + builder.toString()); + // Debug logout. + if (cc.debug) { + LogUtil.logInfo("[NoCheatPlus] Player " + player.getName() + " leaves at location: " + loc.toString()); + } + if (!player.isSleeping() && !player.isDead()) { + // Check for missed moves. + // TODO: Consider to catch all, at least (debug-) logging-wise. + if (!BlockProperties.isPassable(loc)) { + if (data.toX != Double.MAX_VALUE) { + final Location refLoc = new Location(loc.getWorld(), data.toX, data.toY, data.toZ); + final double d = refLoc.distanceSquared(loc); + if (d > 0.0) { + // TODO: Consider to always set back here. Might skip on big distances. + if (TrigUtil.manhattan(loc, refLoc) > 0 || BlockProperties.isPassable(refLoc)) { + if (passable.isEnabled(player)) { + LogUtil.logWarning("[NoCheatPlus] Potential exploit: Player " + player.getName() + " leaves, having moved into a block (not tracked by moving checks): " + player.getWorld().getName() + " / " + DebugUtil.formatMove(refLoc, loc)); + // TODO: Actually trigger a passable violation (+tag). + if (d > 1.25) { + LogUtil.logWarning("[NoCheatPlus] SKIP set-back for " + player.getName() + ", because distance is too high (risk of false positives): " + d); + } else { + LogUtil.logInfo("[NoCheatPlus] Set back player " + player.getName() + ": " + DebugUtil.formatLocation(refLoc)); + data.prepareSetBack(refLoc); + if (!player.teleport(refLoc)) { + LogUtil.logWarning("[NoCheatPlus] FAILED to set back player " + player.getName()); + } + } + } + } } } } - if (warn) { - // TODO: Additional debug info. Might include full moving trace ? - } + useLoc.setWorld(null); } - useLoc.setWorld(null); // Adjust data. survivalFly.setReallySneaking(player, false); noFall.onLeave(player); diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/Passable.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/Passable.java index d24d9fd5..4cdb2b34 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/Passable.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/Passable.java @@ -103,6 +103,7 @@ public class Passable extends Check { loc = null; tags += "into"; } else if (BlockProperties.isPassable(from.getBlockCache(), loc.getX(), loc.getY(), loc.getZ(), from.getTypeId(lbX, lbY, lbZ))) { + // Keep loc. tags += "into_shift"; } // } else if (BlockProperties.isPassableExact(from.getBlockCache(), loc.getX(), loc.getY(), loc.getZ(), from.getTypeId(lbX, lbY, lbZ))) { diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/logging/DebugUtil.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/logging/DebugUtil.java index 8bb881f0..e19738b8 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/logging/DebugUtil.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/logging/DebugUtil.java @@ -20,6 +20,29 @@ import fr.neatmonster.nocheatplus.utilities.build.BuildParameters; public class DebugUtil { // TODO: Add useLoc1 and useLoc2. + + /** + * Just the coordinates. + * @param loc + * @return + */ + public static String formatLocation(final Location loc) { + StringBuilder b = new StringBuilder(128); + addLocation(loc, b); + return b.toString(); + } + + /** + * Just the coordinates. + * @param from + * @param to + * @return + */ + public static String formatMove(Location from, Location to) { + StringBuilder builder = new StringBuilder(128); + DebugUtil.addMove(from, to, null, builder); + return builder.toString(); + } public static boolean isSamePos(final double x1, final double y1, final double z1, final double x2, final double y2, final double z2){ return x1 == x2 && y1 == y2 && z1 == z2; diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/logging/LogUtil.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/logging/LogUtil.java index d5157758..627ffa32 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/logging/LogUtil.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/logging/LogUtil.java @@ -5,7 +5,6 @@ import java.io.StringWriter; import java.util.Date; import java.util.List; import java.util.logging.Level; -import java.util.logging.Logger; import org.bukkit.Bukkit;