From 824e67ffe65f5342defd1cce570344b45f7e2ae1 Mon Sep 17 00:00:00 2001 From: asofold Date: Sat, 2 Feb 2013 08:28:52 +0100 Subject: [PATCH] Use the keep-alive estimation for the new god-mode check. Might not fully do it, but should make occasional hits possible. --- .../nocheatplus/checks/fight/FightListener.java | 1 + .../nocheatplus/checks/fight/GodMode.java | 17 ++++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightListener.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightListener.java index 3e6d7ccf..9055294f 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightListener.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightListener.java @@ -327,6 +327,7 @@ public class FightListener extends CheckListener { // Remember the time. data.regainHealthTime = System.currentTimeMillis(); // Set god-mode health to maximum. + // TODO: Mind that health regain might half the ndt. data.godModeHealth = Math.max(data.godModeHealth, player.getHealth() + event.getAmount()); } diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/fight/GodMode.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/fight/GodMode.java index 24941693..00e52782 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/fight/GodMode.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/fight/GodMode.java @@ -6,7 +6,7 @@ import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.NoCheatPlus; import fr.neatmonster.nocheatplus.checks.Check; import fr.neatmonster.nocheatplus.checks.CheckType; -import fr.neatmonster.nocheatplus.checks.combined.CombinedData; +import fr.neatmonster.nocheatplus.utilities.CheckUtils; import fr.neatmonster.nocheatplus.utilities.TickTask; /* @@ -187,12 +187,15 @@ public class GodMode extends Check { if (dht <= 20) return false; } - // Check for lag. - // Simplified method: check moving timestamp, because a hit means a move usually. - final long lastMoveTime = CombinedData.getData(player).lastMoveTime; - final long time = System.currentTimeMillis(); - if (lastMoveTime > time || time - lastMoveTime > 1100){ - // TODO: reset anything in data ? + // Check for client side lag. + final long now = System.currentTimeMillis(); + final long maxAge = 5000; // Allows 5 seconds lag max. TODO: Balance, test. + long keepAlive = mcAccess.getKeepAliveTime(player); + if (keepAlive > now || keepAlive == Long.MIN_VALUE){ + keepAlive = CheckUtils.guessKeepAliveTime(player, now, maxAge); + } + if (keepAlive != Double.MIN_VALUE && now - keepAlive > 1000 && now - keepAlive < maxAge){ + // Assume lag. return false; }