SF: Fix horizontal buffer allowing negative values + adjust tags.

* Horizontal buffer is not modeled such that it can't become negative.
* hvel tag added for using horizontal velocity.
* hspeed tag is only added on hspeed violations.
This commit is contained in:
asofold 2013-07-22 16:47:11 +02:00
parent 0bb978dbf1
commit ec956a9be0
3 changed files with 45 additions and 36 deletions

View File

@ -26,6 +26,7 @@ import fr.neatmonster.nocheatplus.checks.inventory.Items;
import fr.neatmonster.nocheatplus.checks.moving.MovingConfig; import fr.neatmonster.nocheatplus.checks.moving.MovingConfig;
import fr.neatmonster.nocheatplus.checks.moving.MovingData; import fr.neatmonster.nocheatplus.checks.moving.MovingData;
import fr.neatmonster.nocheatplus.checks.moving.MovingListener; import fr.neatmonster.nocheatplus.checks.moving.MovingListener;
import fr.neatmonster.nocheatplus.checks.moving.SurvivalFly;
import fr.neatmonster.nocheatplus.compat.BridgeHealth; import fr.neatmonster.nocheatplus.compat.BridgeHealth;
import fr.neatmonster.nocheatplus.components.JoinLeaveListener; import fr.neatmonster.nocheatplus.components.JoinLeaveListener;
import fr.neatmonster.nocheatplus.permissions.Permissions; import fr.neatmonster.nocheatplus.permissions.Permissions;
@ -231,7 +232,8 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
if (mData.fromX != Double.MAX_VALUE){ if (mData.fromX != Double.MAX_VALUE){
// TODO: What would mData.lostSprintCount > 0 mean here? // TODO: What would mData.lostSprintCount > 0 mean here?
final double hDist = TrigUtil.distance(loc.getX(), loc.getZ(), mData.fromX, mData.fromZ); final double hDist = TrigUtil.distance(loc.getX(), loc.getZ(), mData.fromX, mData.fromZ);
if (hDist >= 0.23 && mData.sfHorizontalBuffer > 0.5){ if (hDist >= 0.23 && mData.sfHorizontalBuffer > 0.5 * SurvivalFly.hBufMax) {
// TODO: Might remove checking sfHorizontalBuffer.
final MovingConfig mc = MovingConfig.getConfig(player); final MovingConfig mc = MovingConfig.getConfig(player);
// Check if fly checks is an issue at all, re-check "real sprinting". // Check if fly checks is an issue at all, re-check "real sprinting".
if (now <= mData.timeSprinting + mc.sprintingGrace && MovingListener.shouldCheckSurvivalFly(player, mData, mc)){ if (now <= mData.timeSprinting + mc.sprintingGrace && MovingListener.shouldCheckSurvivalFly(player, mData, mc)){

View File

@ -169,7 +169,7 @@ public class MovingData extends ACheckData {
public double passableVL; public double passableVL;
// Data of the survival fly check. // Data of the survival fly check.
public double sfHorizontalBuffer = 0; public double sfHorizontalBuffer = 0.0;
/** Event-counter to cover up for sprinting resetting server side only. Set in the FighListener. */ /** Event-counter to cover up for sprinting resetting server side only. Set in the FighListener. */
public int lostSprintCount = 0; public int lostSprintCount = 0;
public int sfJumpPhase = 0; public int sfJumpPhase = 0;
@ -218,7 +218,7 @@ public class MovingData extends ACheckData {
clearAccounting(); clearAccounting();
clearNoFallData(); clearNoFallData();
removeAllVelocity(); removeAllVelocity();
sfHorizontalBuffer = 0; sfHorizontalBuffer = 0.0;
lostSprintCount = 0; lostSprintCount = 0;
toWasReset = fromWasReset = false; // TODO: true maybe toWasReset = fromWasReset = false; // TODO: true maybe
sfHoverTicks = sfHoverLoginTicks = -1; sfHoverTicks = sfHoverLoginTicks = -1;
@ -248,7 +248,7 @@ public class MovingData extends ACheckData {
// Keep jump amplifier // Keep jump amplifier
// Keep bunny-hop delay (?) // Keep bunny-hop delay (?)
// keep jump phase. // keep jump phase.
sfHorizontalBuffer = Math.min(0, sfHorizontalBuffer); sfHorizontalBuffer = 0.0;
lostSprintCount = 0; lostSprintCount = 0;
toWasReset = fromWasReset = false; // TODO: true maybe toWasReset = fromWasReset = false; // TODO: true maybe
sfHoverTicks = -1; sfHoverTicks = -1;

View File

@ -51,7 +51,10 @@ public class SurvivalFly extends Check {
public static final double modIce = 2.5D; public static final double modIce = 2.5D;
/** Faster moving down stream (water mainly). */ /** Faster moving down stream (water mainly). */
public static final double modDownStream = 0.19 / (walkSpeed * modSwim); public static final double modDownStream = 0.19 / (walkSpeed * modSwim);
/** Maximal horizontal buffer. It can be higher, but normal resetting should keep this limit. */
public static final double hBufMax = 1.0;
// Vertical speeds/modifiers. // Vertical speeds/modifiers.
public static final double climbSpeed = walkSpeed * modSprint; // TODO. public static final double climbSpeed = walkSpeed * modSprint; // TODO.
@ -115,6 +118,7 @@ public class SurvivalFly extends Check {
final boolean sprinting; final boolean sprinting;
if (data.lostSprintCount > 0) { if (data.lostSprintCount > 0) {
// Sprint got toggled off, though the client is still (legitimately) moving at sprinting speed. // Sprint got toggled off, though the client is still (legitimately) moving at sprinting speed.
// NOTE: This could extend the "sprinting grace" period, theoretically, until on ground.
if (resetTo && (fromOnGround || from.isResetCond()) || hDistance <= walkSpeed){ if (resetTo && (fromOnGround || from.isResetCond()) || hDistance <= walkSpeed){
// Invalidate. // Invalidate.
data.lostSprintCount = 0; data.lostSprintCount = 0;
@ -193,10 +197,8 @@ public class SurvivalFly extends Check {
else{ else{
data.hVelActive.clear(); data.hVelActive.clear();
hFreedom = 0.0; hFreedom = 0.0;
if (hDistance != 0D){ if (data.sfHorizontalBuffer < hBufMax && hDistance > 0.0){
// TODO: Confine conditions further ? hBufRegain(hDistance, hDistanceAboveLimit, data);
// TODO: Code duplication: hDistAfterFailure
data.sfHorizontalBuffer = Math.min(1D, data.sfHorizontalBuffer - hDistanceAboveLimit);
} }
} }
@ -206,7 +208,7 @@ public class SurvivalFly extends Check {
// TODO: Complete re-modeling. // TODO: Complete re-modeling.
if (hDistanceAboveLimit <= 0D && hDistance > 0.1D && yDistance == 0D && data.sfLastYDist == 0D && !toOnGround && !fromOnGround && BlockProperties.isLiquid(to.getTypeId())) { if (hDistanceAboveLimit <= 0D && hDistance > 0.1D && yDistance == 0D && data.sfLastYDist == 0D && !toOnGround && !fromOnGround && BlockProperties.isLiquid(to.getTypeId())) {
// TODO: Relative hdistance. // TODO: Relative hdistance.
// TODO: Might check actual bounds, might implement + use BlockProperties.getCorrectedBounds. // TODO: Might check actual bounds (collidesBlock). Might implement + use BlockProperties.getCorrectedBounds or getSomeHeight.
hDistanceAboveLimit = Math.max(hDistanceAboveLimit, hDistance); hDistanceAboveLimit = Math.max(hDistanceAboveLimit, hDistance);
tags.add("waterwalk"); tags.add("waterwalk");
} }
@ -798,8 +800,7 @@ public class SurvivalFly extends Check {
*/ */
private double[] hDistAfterFailure(final Player player, final PlayerLocation from, final PlayerLocation to, double hAllowedDistance, final double hDistance, double hDistanceAboveLimit, final double yDistance, final boolean sprinting, final boolean downStream, final MovingData data, final MovingConfig cc) { private double[] hDistAfterFailure(final Player player, final PlayerLocation from, final PlayerLocation to, double hAllowedDistance, final double hDistance, double hDistanceAboveLimit, final double yDistance, final boolean sprinting, final boolean downStream, final MovingData data, final MovingConfig cc) {
// TODO: Check bunny first ? // TODO: Not entirely sure about this checking order.
// TODO: check hdist first ?
// Check velocity. // Check velocity.
double hFreedom = 0.0; // Horizontal velocity used (!). double hFreedom = 0.0; // Horizontal velocity used (!).
@ -810,23 +811,18 @@ public class SurvivalFly extends Check {
hFreedom += data.useHorizontalVelocity(hDistanceAboveLimit - hFreedom); hFreedom += data.useHorizontalVelocity(hDistanceAboveLimit - hFreedom);
} }
if (hFreedom > 0.0){ if (hFreedom > 0.0){
tags.add("hvel");
hDistanceAboveLimit = Math.max(0.0, hDistanceAboveLimit - hFreedom); hDistanceAboveLimit = Math.max(0.0, hDistanceAboveLimit - hFreedom);
} }
// TODO: Checking order with bunny/normal-buffer ?
// After failure permission checks ( + speed modifier + sneaking + blocking + speeding) and velocity (!). // After failure permission checks ( + speed modifier + sneaking + blocking + speeding) and velocity (!).
if (hDistanceAboveLimit > 0.0){ if (hDistanceAboveLimit > 0.0){
hAllowedDistance = getAllowedhDist(player, from, to, sprinting, downStream, hDistance, walkSpeed, data, cc, true); hAllowedDistance = getAllowedhDist(player, from, to, sprinting, downStream, hDistance, walkSpeed, data, cc, true);
hDistanceAboveLimit = hDistance - hAllowedDistance; hDistanceAboveLimit = hDistance - hAllowedDistance;
if (hFreedom > 0.0){ if (hFreedom > 0.0){
// Duplicates above, due to re-checking the allowed distance.
hDistanceAboveLimit -= hFreedom; hDistanceAboveLimit -= hFreedom;
} }
if (hAllowedDistance > 0.0){ // TODO: Fix !
// (Horizontal buffer might still get used.)
tags.add("hspeed");
}
} }
// "Bunny-hop". // "Bunny-hop".
@ -856,7 +852,7 @@ public class SurvivalFly extends Check {
// Increase buffer by the needed amount. // Increase buffer by the needed amount.
final double amount = hDistance - hAllowedDistance; final double amount = hDistance - hAllowedDistance;
// TODO: Might use min(hAllowedDistance and some maximal thing like sprinting speed?) // TODO: Might use min(hAllowedDistance and some maximal thing like sprinting speed?)
data.sfHorizontalBuffer = Math.min(1D, data.sfHorizontalBuffer) + amount; // Cheat ! data.sfHorizontalBuffer = Math.min(hBufMax, data.sfHorizontalBuffer) + amount; // Cheat !
tags.add("bunnyfly"); tags.add("bunnyfly");
} }
} }
@ -864,29 +860,40 @@ public class SurvivalFly extends Check {
} }
// Horizontal buffer. // Horizontal buffer.
if (hDistanceAboveLimit > 0D && data.sfHorizontalBuffer != 0D) { if (hDistanceAboveLimit > 0.0) {
if (data.sfHorizontalBuffer > 0D) { // Handle buffer only if moving too far.
if (data.sfHorizontalBuffer > 0.0) {
// Consume buffer.
tags.add("hbufuse"); tags.add("hbufuse");
final double amount = Math.min(data.sfHorizontalBuffer, hDistanceAboveLimit);
hDistanceAboveLimit -= amount;
// Ensure we never end up below zero.
data.sfHorizontalBuffer = Math.max(0.0, data.sfHorizontalBuffer - amount);
} }
else { // else: No consumption.
tags.add("hbufpen"); } else if (data.sfHorizontalBuffer < hBufMax && hDistance > 0.0) {
} hBufRegain(hDistance, hDistanceAboveLimit, data);
// Try to consume the "buffer".
hDistanceAboveLimit -= data.sfHorizontalBuffer;
data.sfHorizontalBuffer = 0D;
// Put back the "over-consumed" buffer.
if (hDistanceAboveLimit < 0D) {
data.sfHorizontalBuffer = -hDistanceAboveLimit;
}
} else if (hDistance != 0D){
// TODO: Code duplication (see check).
data.sfHorizontalBuffer = Math.min(1D, data.sfHorizontalBuffer - hDistanceAboveLimit);
} }
// Add the hspeed tag on violation.
if (hDistanceAboveLimit > 0.0){
tags.add("hspeed");
}
return new double[]{hAllowedDistance, hDistanceAboveLimit, hFreedom}; return new double[]{hAllowedDistance, hDistanceAboveLimit, hFreedom};
} }
/**
* Legitimate move: increase horizontal buffer somehow.
* @param hDistance
* @param hDistanceAboveLimit
* @param data
*/
private void hBufRegain(final double hDistance, final double hDistanceAboveLimit, final MovingData data){
// TODO: Consider different concepts (full resetting with harder conditions | maximum regain amount).
// TODO: Confine general conditions for buffer regain further ?
data.sfHorizontalBuffer = Math.min(hBufMax, data.sfHorizontalBuffer - hDistanceAboveLimit);
}
/** /**
* Inside liquids vertical speed checking. * Inside liquids vertical speed checking.
* @param from * @param from