Skip to content

Commit

Permalink
Store past moves as MoveData (raw sketch, no change on logic).
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Dec 13, 2015
1 parent 742877d commit cfc2db9
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 26 deletions.
Expand Up @@ -41,7 +41,10 @@ public CreativeFly() {
* @param time Millis.
* @return
*/
public Location check(final Player player, final PlayerLocation from, final PlayerLocation to, final MoveData moveData, final MovingData data, final MovingConfig cc, final long time) {
public Location check(final Player player, final PlayerLocation from, final PlayerLocation to, final MovingData data, final MovingConfig cc, final long time) {

// Edge data for this move.
final MoveData thisMove = data.thisMove;

// Ensure we have a set-back location.
if (!data.hasSetBack()) {
Expand All @@ -59,8 +62,8 @@ public Location check(final Player player, final PlayerLocation from, final Play
}

// Calculate some distances.
final double yDistance = moveData.yDistance;
final double hDistance = moveData.hDistance;
final double yDistance = thisMove.yDistance;
final double hDistance = thisMove.hDistance;

// Sprinting.
final boolean sprinting = time <= data.timeSprinting + cc.sprintingGrace;
Expand Down
@@ -1,6 +1,8 @@
package fr.neatmonster.nocheatplus.checks.moving;

import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;

import org.bukkit.Location;
Expand All @@ -16,6 +18,7 @@
import fr.neatmonster.nocheatplus.checks.moving.locations.LocationTrace;
import fr.neatmonster.nocheatplus.checks.moving.model.LiftOffEnvelope;
import fr.neatmonster.nocheatplus.checks.moving.model.MoveConsistency;
import fr.neatmonster.nocheatplus.checks.moving.model.MoveData;
import fr.neatmonster.nocheatplus.checks.moving.velocity.AccountEntry;
import fr.neatmonster.nocheatplus.checks.moving.velocity.FrictionAxisVelocity;
import fr.neatmonster.nocheatplus.checks.moving.velocity.SimpleAxisVelocity;
Expand Down Expand Up @@ -146,6 +149,18 @@ public static void onReload() {
public float walkSpeed = 0.0f;
public float flySpeed = 0.0f;

/**
* Keep track of past moves edge data. First entry always is the last fully
* processed move, or invalid, even during processing. The currently
* processed move always is thisMove. The list length always stays the same.
*/
public final LinkedList<MoveData> moveData = new LinkedList<MoveData>();
/**
* The move currently being processed. Will be inserted to first position
* when done, and exchanged for the invalidated last element of moveData.
*/
public MoveData thisMove = new MoveData();

// Velocity handling.
/** Vertical velocity modeled as an axis (positive and negative possible) */
private final SimpleAxisVelocity verVel = new SimpleAxisVelocity();
Expand Down Expand Up @@ -254,12 +269,39 @@ public MovingData(final MovingConfig config) {
super(config);
morePacketsFreq = new ActionFrequency(config.morePacketsEPSBuckets, 500);
morePacketsBurstFreq = new ActionFrequency(12, 5000);

// Past moves data: initialize with dummies.
for (int i = 0; i < 2; i++) { // Two past moves allow better workarounds than 1.
moveData.add(new MoveData());
}
}

/**
* Invalidate thisMove and all elements in moveData.
*/
private void invalidateMoveData() {
final Iterator<MoveData> it = moveData.iterator();
while (it.hasNext()) {
it.next().invalidate();
}
thisMove.invalidate();
}

/**
* Call after processing with a valid thisMove field. Insert thisMove as
* first in moveData, set thisMove to invalidated last element of moveData.
*/
public void finishThisMove() {
moveData.addFirst(thisMove);
thisMove = moveData.removeLast();
thisMove.invalidate();
}

/**
* Clear the data of the fly checks (not more-packets).
*/
public void clearFlyData() {
invalidateMoveData();
bunnyhopDelay = 0;
sfJumpPhase = 0;
jumpAmplifier = 0;
Expand Down Expand Up @@ -325,6 +367,7 @@ public void onSetBack(final Location setBack) {
* Move event: Mildly reset some data, prepare setting a new to-Location.
*/
public void prepareSetBack(final Location loc) {
invalidateMoveData();
clearAccounting();
sfJumpPhase = 0;
lastYDist = lastHDist = Double.MAX_VALUE;
Expand Down Expand Up @@ -398,12 +441,14 @@ public void onWorldUnload(final String worldName) {
}

/**
* Just reset the "last locations" references.
* Reset edge data for last moves.
* @param x
* @param y
* @param z
*/
public void resetPositions(final double x, final double y, final double z, final float yaw, final float pitch) {
invalidateMoveData();
moveData.get(0).set(x, y, z, yaw, pitch);
fromX = toX = x;
fromY = toY = y;
fromZ = toZ = z;
Expand Down Expand Up @@ -456,6 +501,7 @@ public void resetPositions() {
}

public void resetLastDistances() {
// TODO: Will change with moveData in use.
lastHDist = lastYDist = Double.MAX_VALUE;
}

Expand All @@ -465,6 +511,7 @@ public void resetLastDistances() {
* @param to
*/
public void setPositions(final Location from, final Location to) {
// TODO: Will change with moveData in use..
fromX = from.getX();
fromY = from.getY();
fromZ = from.getZ();
Expand Down
Expand Up @@ -544,7 +544,7 @@ else if (time < data.timeSprinting) {
}

// Set some data for this move.
moveInfo.data.set(pFrom, pTo);
data.thisMove.set(pFrom, pTo);

// Potion effect "Jump".
final double jumpAmplifier = survivalFly.getJumpAmplifier(player);
Expand Down Expand Up @@ -665,7 +665,7 @@ else if (data.verticalBounce != null) {
// Actual check.
if (newTo == null) {
// Only check if passable has not already set back.
newTo = survivalFly.check(player, pFrom, pTo, isSamePos, mightBeMultipleMoves, moveInfo.data, data, cc, time);
newTo = survivalFly.check(player, pFrom, pTo, isSamePos, mightBeMultipleMoves, data, cc, time);
}
// Only check NoFall, if not already vetoed.
if (checkNf) {
Expand Down Expand Up @@ -710,7 +710,7 @@ else if (mightSkipNoFall) {
else if (checkCf) {
// CreativeFly
if (newTo == null) {
newTo = creativeFly.check(player, pFrom, pTo, moveInfo.data, data, cc, time);
newTo = creativeFly.check(player, pFrom, pTo, data, cc, time);
}
data.sfHoverTicks = -1;
data.sfLowJump = false;
Expand Down Expand Up @@ -745,10 +745,10 @@ else if (checkCf) {
processBounce(player, pFrom.getY(), pTo.getY(), data, cc);
}
// Set positions.
// TODO: Consider setting in Monitor (concept missing for changing coordinates, could double-check).
data.setPositions(from, to);
data.lastHDist = moveInfo.data.hDistance;
data.lastYDist = moveInfo.data.yDistance;
data.lastHDist = data.thisMove.hDistance;
data.lastYDist = data.thisMove.yDistance;
data.finishThisMove();
return false;
}
else {
Expand Down Expand Up @@ -905,7 +905,9 @@ private void onVehicleLeaveMiss(final Player player, final MovingData data, fina
*/
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled = false)
public void onPlayerMoveMonitor(final PlayerMoveEvent event) {
// TODO: revise: cancelled events.

// TODO: Use stored move data to verify if from/to have changed (thus a teleport will result, possibly a minor issue due to the teleport).

final long now = System.currentTimeMillis();
final Player player = event.getPlayer();

Expand Down Expand Up @@ -952,6 +954,7 @@ public void onPlayerMoveMonitor(final PlayerMoveEvent event) {
* @param data
*/
private void onCancelledMove(final Player player, final Location from, final int tick, final long now, final MovingData mData, final CombinedData data) {
// TODO: Revise handling of cancelled events.
data.lastMoveTime = now; // TODO: Move to MovingData?
// TODO: teleported + other resetting ?
Combined.feedYawRate(player, from.getYaw(), now, from.getWorld().getName(), data);
Expand Down
Expand Up @@ -121,8 +121,9 @@ public SurvivalFly() {
* @param isSamePos
* @return the location
*/
public Location check(final Player player, final PlayerLocation from, final PlayerLocation to, final boolean isSamePos, final boolean mightBeMultipleMoves, final MoveData moveData, final MovingData data, final MovingConfig cc, final long now) {
public Location check(final Player player, final PlayerLocation from, final PlayerLocation to, final boolean isSamePos, final boolean mightBeMultipleMoves, final MovingData data, final MovingConfig cc, final long now) {
tags.clear();
final MoveData thisMove = data.thisMove;

// Calculate some distances.
final double xDistance, yDistance, zDistance, hDistance;
Expand All @@ -133,14 +134,14 @@ public Location check(final Player player, final PlayerLocation from, final Play
hasHdist = false;
} else {
xDistance = to.getX() - from.getX();
yDistance = moveData.yDistance;
yDistance = thisMove.yDistance;
zDistance = to.getZ() - from.getZ();
if (xDistance == 0.0 && zDistance == 0.0) {
hDistance = 0.0;
hasHdist = false;
} else {
hasHdist = true;
hDistance = moveData.hDistance;
hDistance = thisMove.hDistance;
}
}

Expand Down
Expand Up @@ -3,7 +3,6 @@
import org.bukkit.Location;
import org.bukkit.entity.Player;

import fr.neatmonster.nocheatplus.checks.moving.model.MoveData;
import fr.neatmonster.nocheatplus.compat.MCAccess;
import fr.neatmonster.nocheatplus.utilities.BlockCache;
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
Expand All @@ -25,8 +24,6 @@ public class MoveInfo {
public final BlockCache cache;
public final PlayerLocation from;
public final PlayerLocation to;
/** Not initialized in set. */
public final MoveData data = new MoveData();

public MoveInfo(final MCAccess mcAccess){
cache = mcAccess.getBlockCache(null);
Expand Down Expand Up @@ -65,7 +62,6 @@ public final void cleanup(){
from.cleanup();
to.cleanup();
cache.cleanup();
data.reset();
}

}
Expand Up @@ -4,26 +4,97 @@
import fr.neatmonster.nocheatplus.utilities.TrigUtil;

/**
* Carry data of a move, involving from- and to- location.
* Carry data of a move, involving from- and to- locations.
*
* @author asofold
*
*/
public class MoveData {

// TODO: Invalidation flag?

/////////////////////////////
// Guaranteed to be set.
/////////////////////////////
/**
* Indicate if data has been set. Likely there will be sets of properties
* with a flag for each such set.
*/
public boolean valid = false;

public double yDistance = Double.MAX_VALUE;
public double hDistance = Double.MAX_VALUE;

public void set(PlayerLocation from, PlayerLocation to) {
yDistance = to.getY()- from.getY();
hDistance = TrigUtil.xzDistance(from, to);
// TODO: Last coords,
// TODO: Velocity used, fly check, ...


/////////////////////////////
// Not guaranteed to be set.
/////////////////////////////

public boolean headObstructed = false;

// TODO: ground/reset/web/...


/**
* Set the minimal properties, likely to be used.
*
* @param from
* @param to
*/
public void set(final PlayerLocation from, final PlayerLocation to) {
set(from.getX(), from.getY(), from.getZ(), from.getYaw(), from.getPitch(),
to.getX(), to.getY(), to.getZ(), to.getYaw(), to.getPitch());
}

/**
* Set some basic move edge data and reset all other properties properly.
* @param fromX
* @param fromY
* @param fromZ
* @param toX
* @param toY
* @param toZ
*/
public void set(final double fromX, final double fromY, final double fromZ, final float fromYaw, final float fromPitch,
final double toX, final double toY, final double toZ, final float toYaw, final float toPitch) {
yDistance = toY - fromY;
hDistance = TrigUtil.distance(fromX, fromZ, toX, toZ);
headObstructed = false;
// Set Valid last.
valid = true;
}

public void reset() {
yDistance = Double.MAX_VALUE;
hDistance = Double.MAX_VALUE;
/**
* Set with teleport / set-back.
* @param x
* @param y
* @param z
* @param yaw
* @param pitch
*/
public void set(final double x, final double y, final double z, final float yaw, final float pitch) {
yDistance = Double.MAX_VALUE; // TODO: 0 ?
hDistance = Double.MAX_VALUE; // TODO: 0 ?
headObstructed = false;
valid = true;
}

/**
* Fast invalidation: just set the flags.
*/
public void invalidate() {
valid = false;
}

// public void reset() {
// // TODO: Might not need this method: it's always set(...) or set invalid to true.
// valid = false;
// // Reset properties after resetting valid.
// yDistance = Double.MAX_VALUE;
// hDistance = Double.MAX_VALUE;
// headObstructed = false;
// }

}

0 comments on commit cfc2db9

Please sign in to comment.