Search in sources :

Example 1 with ViolationData

use of fr.neatmonster.nocheatplus.checks.ViolationData in project NoCheatPlus by NoCheatPlus.

the class MovingListener method noFallVL.

private final boolean noFallVL(final Player player, final String tag, final MovingData data, final MovingConfig cc) {
    data.noFallVL += 1.0;
    // if (noFall.executeActions(player, data.noFallVL, 1.0, cc.noFallActions).willCancel()
    final ViolationData vd = new ViolationData(noFall, player, data.noFallVL, 1.0, cc.noFallActions);
    if (tag != null) {
        vd.setParameter(ParameterName.TAGS, tag);
    }
    return noFall.executeActions(vd).willCancel();
}
Also used : ViolationData(fr.neatmonster.nocheatplus.checks.ViolationData)

Example 2 with ViolationData

use of fr.neatmonster.nocheatplus.checks.ViolationData in project NoCheatPlus by NoCheatPlus.

the class MovingListener method checkExtremeMove.

/**
 * Check for extremely large moves. Initial intention is to prevent cheaters
 * from creating extreme load. SurvivalFly or CreativeFly is needed.
 *
 * @param player
 * @param from
 * @param to
 * @param data
 * @param cc
 * @return
 */
@SuppressWarnings("unused")
private Location checkExtremeMove(final Player player, final PlayerLocation from, final PlayerLocation to, final MovingData data, final MovingConfig cc) {
    final PlayerMoveData thisMove = data.playerMoves.getCurrentMove();
    final PlayerMoveData lastMove = data.playerMoves.getFirstPastMove();
    // TODO: Latency effects.
    // h + v violation (full move).
    double violation = 0.0;
    // Vertical move.
    // TODO: Configurable
    final boolean allowVerticalVelocity = false;
    if (Math.abs(thisMove.yDistance) > Magic.EXTREME_MOVE_DIST_VERTICAL) {
        // About -1.85 seems to be the negative maximum for velocity use in survival mode. Falling can result in slightly less than -3.
        if (lastMove.toIsValid && Math.abs(thisMove.yDistance) < Math.abs(lastMove.yDistance) && (thisMove.yDistance > 0.0 && lastMove.yDistance > 0.0 || thisMove.yDistance < 0.0 && lastMove.yDistance < 0.0) || allowVerticalVelocity && data.getOrUseVerticalVelocity(thisMove.yDistance) != null) {
        // Speed decreased or velocity is present.
        } else {
            // Violation.
            // Could subtract lastMove.yDistance.
            violation += thisMove.yDistance;
        }
    }
    // Horizontal move.
    if (thisMove.hDistance > Magic.EXTREME_MOVE_DIST_HORIZONTAL) {
        // Exclude valid moves first.
        // TODO: Attributes might allow unhealthy moves as well.
        // Observed maximum use so far: 5.515
        // TODO: Velocity flag too (if combined with configurable distances)?
        // Will change with model change.
        final double amount = thisMove.hDistance - data.getHorizontalFreedom();
        if (amount < 0.0 || lastMove.toIsValid && thisMove.hDistance - lastMove.hDistance <= 0.0 || data.useHorizontalVelocity(amount) >= amount) {
        // Speed decreased or velocity is present.
        } else {
            // Violation.
            // Could subtract lastMove.yDistance.
            violation += thisMove.hDistance;
        }
    }
    if (violation > 0.0) {
        // Ensure a set back location is present.
        if (!data.hasSetBack()) {
            data.setSetBack(from);
        }
        // Process violation as sub check of the appropriate fly check.
        violation *= 100.0;
        final Check check;
        final ActionList actions;
        final double vL;
        if (thisMove.flyCheck == CheckType.MOVING_SURVIVALFLY) {
            check = survivalFly;
            actions = cc.survivalFlyActions;
            data.survivalFlyVL += violation;
            vL = data.survivalFlyVL;
        } else {
            check = creativeFly;
            actions = cc.creativeFlyActions;
            data.creativeFlyVL += violation;
            vL = data.creativeFlyVL;
        }
        final ViolationData vd = new ViolationData(check, player, vL, violation, actions);
        // TODO: Reduce copy and paste (method to fill in locations, once using exact coords and latering default actions).
        if (vd.needsParameters()) {
            vd.setParameter(ParameterName.LOCATION_FROM, String.format(Locale.US, "%.2f, %.2f, %.2f", from.getX(), from.getY(), from.getZ()));
            vd.setParameter(ParameterName.LOCATION_TO, String.format(Locale.US, "%.2f, %.2f, %.2f", to.getX(), to.getY(), to.getZ()));
            vd.setParameter(ParameterName.DISTANCE, String.format(Locale.US, "%.2f", TrigUtil.distance(from, to)));
            vd.setParameter(ParameterName.TAGS, "EXTREME_MOVE");
        }
        // Some resetting is done in MovingListener.
        if (check.executeActions(vd).willCancel()) {
            // Set back + view direction of to (more smooth).
            return MovingUtil.getApplicableSetBackLocation(player, to.getYaw(), to.getPitch(), from, data, cc);
        }
    }
    // No cancel intended.
    return null;
}
Also used : PlayerMoveData(fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData) Check(fr.neatmonster.nocheatplus.checks.Check) ActionList(fr.neatmonster.nocheatplus.actions.ActionList) ViolationData(fr.neatmonster.nocheatplus.checks.ViolationData)

Example 3 with ViolationData

use of fr.neatmonster.nocheatplus.checks.ViolationData in project NoCheatPlus by NoCheatPlus.

the class SurvivalFly method handleHoverViolation.

/**
 * Hover violations have to be handled in this check, because they are handled as SurvivalFly violations (needs executeActions).
 * @param player
 * @param loc
 * @param blockCache
 * @param cc
 * @param data
 */
public final void handleHoverViolation(final Player player, final PlayerLocation loc, final MovingConfig cc, final MovingData data) {
    data.survivalFlyVL += cc.sfHoverViolation;
    // TODO: Extra options for set back / kick, like vl?
    data.sfVLTime = data.getPlayerMoveCount();
    data.sfVLInAir = true;
    final ViolationData vd = new ViolationData(this, player, data.survivalFlyVL, cc.sfHoverViolation, cc.survivalFlyActions);
    if (vd.needsParameters()) {
        vd.setParameter(ParameterName.LOCATION_FROM, String.format(Locale.US, "%.2f, %.2f, %.2f", loc.getX(), loc.getY(), loc.getZ()));
        vd.setParameter(ParameterName.LOCATION_TO, "(HOVER)");
        vd.setParameter(ParameterName.DISTANCE, "0.0(HOVER)");
        vd.setParameter(ParameterName.TAGS, "hover");
    }
    if (executeActions(vd).willCancel()) {
        // Set back or kick.
        final Location newTo = MovingUtil.getApplicableSetBackLocation(player, loc.getYaw(), loc.getPitch(), loc, data, cc);
        if (newTo != null) {
            data.prepareSetBack(newTo);
            player.teleport(newTo, BridgeMisc.TELEPORT_CAUSE_CORRECTION_OF_POSITION);
        } else {
            // Solve by extra actions ? Special case (probably never happens)?
            player.kickPlayer("Hovering?");
        }
    } else {
    // Ignore.
    }
}
Also used : ViolationData(fr.neatmonster.nocheatplus.checks.ViolationData) PlayerLocation(fr.neatmonster.nocheatplus.utilities.location.PlayerLocation) Location(org.bukkit.Location)

Example 4 with ViolationData

use of fr.neatmonster.nocheatplus.checks.ViolationData in project NoCheatPlus by NoCheatPlus.

the class VehicleMorePackets method check.

/**
 * Checks a player.
 *
 * (More information on the MorePacket class.)
 *
 * @param player
 *            the player
 * @param thisMove
 * @param setBack Already decided set back, if not null.
 * @param cc
 * @param data
 * @return the location
 */
public SetBackEntry check(final Player player, final VehicleMoveData thisMove, final SetBackEntry setBack, final MovingData data, final MovingConfig cc, final IPlayerData pData) {
    // Take time once, first:
    final long time = System.currentTimeMillis();
    final boolean allowSetSetBack = setBack == null && data.vehicleSetBackTaskId == -1;
    SetBackEntry newTo = null;
    // Take a packet from the buffer.
    data.vehicleMorePacketsBuffer--;
    if (setBack != null || data.vehicleSetBackTaskId != -1) {
        // TODO: This is bad. Needs to check if still scheduled (a BukkitTask thing) and just skip.
        return data.vehicleSetBacks.getValidMidTermEntry();
    }
    final boolean debug = pData.isDebugActive(type);
    // Player used up buffer, they fail the check.
    if (data.vehicleMorePacketsBuffer < 0) {
        // Increment violation level.
        data.vehicleMorePacketsVL = -data.vehicleMorePacketsBuffer;
        // Execute whatever actions are associated with this check and the violation level and find out if we should
        // cancel the event.
        final ViolationData vd = new ViolationData(this, player, data.vehicleMorePacketsVL, -data.vehicleMorePacketsBuffer, cc.vehicleMorePacketsActions);
        if (debug || vd.needsParameters()) {
            vd.setParameter(ParameterName.PACKETS, Integer.toString(-data.vehicleMorePacketsBuffer));
        }
        if (executeActions(vd).willCancel()) {
            newTo = data.vehicleSetBacks.getValidMidTermEntry();
        }
    }
    if (data.vehicleMorePacketsLastTime + 1000 < time) {
        // More than 1 second elapsed, but how many?
        final double seconds = (time - data.vehicleMorePacketsLastTime) / 1000.0;
        // For each second, fill the buffer.
        data.vehicleMorePacketsBuffer += packetsPerTimeframe * seconds;
        // If there was a long pause (maybe server lag?), allow buffer to grow up to 100.
        if (seconds > 2) {
            if (data.vehicleMorePacketsBuffer > 100) {
                data.vehicleMorePacketsBuffer = 100;
            }
        } else if (data.vehicleMorePacketsBuffer > MovingData.vehicleMorePacketsBufferDefault) {
            // Only allow growth up to 50.
            data.vehicleMorePacketsBuffer = MovingData.vehicleMorePacketsBufferDefault;
        }
        // Set the new "last" time.
        data.vehicleMorePacketsLastTime = time;
        // Set the new set back location.
        if (allowSetSetBack && newTo == null) {
            data.vehicleSetBacks.setMidTermEntry(thisMove.from);
            if (debug) {
                debug(player, "Update vehicle morepackets set back: " + thisMove.from);
            }
        }
    } else if (data.vehicleMorePacketsLastTime > time) {
        // Security check, maybe system time changed.
        data.vehicleMorePacketsLastTime = time;
    }
    return newTo;
}
Also used : SetBackEntry(fr.neatmonster.nocheatplus.checks.moving.location.setback.SetBackEntry) ViolationData(fr.neatmonster.nocheatplus.checks.ViolationData)

Example 5 with ViolationData

use of fr.neatmonster.nocheatplus.checks.ViolationData in project NoCheatPlus by NoCheatPlus.

the class FastClick method check.

// /**
// * Checks a player.
// *
// * @param player
// *            the player
// * @param cc
// * @return true, if successful
// */
// public boolean check(final Player player) {
// // Take time once.
// final long time = System.currentTimeMillis();
// 
// final InventoryData data = InventoryData.getData(player);
// 
// boolean cancel = false;
// 
// // If the last inventory click has been made within 45 milliseconds.
// if (time - data.fastClickLastTime < 45L) {
// if (data.fastClickLastCancelled) {
// 
// // Calculate the difference between the limit and the time elapsed.
// final double difference = 45L - time + data.fastClickLastTime;
// final InventoryConfig cc = InventoryConfig.getConfig(player);
// final ViolationData vd = new ViolationData(this, player, data.fastClickVL + difference, difference, cc.fastClickActions);
// if (TickTask.getLag(150, true) > 1.7f){
// // Don't increase vl here.
// cancel = vd.hasCancel();
// }
// else{
// // Increment the violation level.
// data.fastClickVL += difference;
// 
// // Find out if we need to cancel the event.
// cancel = executeActions(vd);
// }
// } else
// data.fastClickLastCancelled = true;
// } else {
// data.fastClickLastCancelled = false;
// 
// // Reduce the violation level.
// data.fastClickVL *= 0.98D;
// }
// 
// // Remember the current time.s
// data.fastClickLastTime = time;
// 
// return cancel;
// }
public boolean check(final Player player, final long now, final InventoryView view, final int slot, final ItemStack cursor, final ItemStack clicked, final boolean isShiftClick, final InventoryData data, final InventoryConfig cc, final IPlayerData pData) {
    // Take time once.
    final float amount;
    if (cursor != null && cc.fastClickTweaks1_5) {
        final Material cursorMat = cursor.getType();
        final int cursorAmount = Math.max(1, cursor.getAmount());
        final Material clickedMat = clicked == null ? Material.AIR : clicked.getType();
        if (cursorMat != data.fastClickLastCursor && (!isShiftClick || clicked == null || clicked.getType() != data.fastClickLastClicked) || cursorMat == Material.AIR || cursorAmount != data.fastClickLastCursorAmount) {
            amount = 1f;
        } else {
            if (clickedMat == Material.AIR || clickedMat == cursorMat || isShiftClick && clickedMat == data.fastClickLastClicked) {
                amount = Math.min(cc.fastClickNormalLimit, cc.fastClickShortTermLimit) / (float) (isShiftClick && clickedMat != Material.AIR ? (1.0 + Math.max(cursorAmount, InventoryUtil.getStackCount(view, clicked))) : cursorAmount) * 0.75f;
            } else {
                amount = 1f;
            }
        }
        data.fastClickLastCursor = cursorMat;
        data.fastClickLastClicked = clickedMat;
        data.fastClickLastCursorAmount = cursorAmount;
    } else {
        data.fastClickLastCursor = null;
        data.fastClickLastClicked = null;
        data.fastClickLastCursorAmount = 0;
        amount = 1f;
    }
    data.fastClickFreq.add(now, amount);
    float shortTerm = data.fastClickFreq.bucketScore(0);
    if (shortTerm > cc.fastClickShortTermLimit) {
        // Check for lag.
        shortTerm /= (float) TickTask.getLag(data.fastClickFreq.bucketDuration(), true);
    }
    shortTerm -= cc.fastClickShortTermLimit;
    float normal = data.fastClickFreq.score(1f);
    if (normal > cc.fastClickNormalLimit) {
        // Check for lag.
        normal /= (float) TickTask.getLag(data.fastClickFreq.bucketDuration() * data.fastClickFreq.numberOfBuckets(), true);
    }
    normal -= cc.fastClickNormalLimit;
    final double violation = Math.max(shortTerm, normal);
    boolean cancel = false;
    if (violation > 0) {
        data.fastClickVL += violation;
        final ViolationData vd = new ViolationData(this, player, data.fastClickVL, violation, cc.fastClickActions);
        cancel = executeActions(vd).willCancel();
    }
    if (pData.isDebugActive(type) && pData.hasPermission(Permissions.ADMINISTRATION_DEBUG, player)) {
        player.sendMessage("FastClick: " + data.fastClickFreq.bucketScore(0) + " | " + data.fastClickFreq.score(1f) + " | cursor=" + cursor + " | clicked=" + clicked);
    }
    return cancel;
}
Also used : Material(org.bukkit.Material) ViolationData(fr.neatmonster.nocheatplus.checks.ViolationData)

Aggregations

ViolationData (fr.neatmonster.nocheatplus.checks.ViolationData)25 Location (org.bukkit.Location)5 Material (org.bukkit.Material)4 PlayerLocation (fr.neatmonster.nocheatplus.utilities.location.PlayerLocation)3 PlayerMoveData (fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData)2 ActionList (fr.neatmonster.nocheatplus.actions.ActionList)1 Check (fr.neatmonster.nocheatplus.checks.Check)1 BlockInteractData (fr.neatmonster.nocheatplus.checks.blockinteract.BlockInteractData)1 MovingConfig (fr.neatmonster.nocheatplus.checks.moving.MovingConfig)1 MovingData (fr.neatmonster.nocheatplus.checks.moving.MovingData)1 SetBackEntry (fr.neatmonster.nocheatplus.checks.moving.location.setback.SetBackEntry)1 ModelFlying (fr.neatmonster.nocheatplus.checks.moving.model.ModelFlying)1 PlayerMoveInfo (fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveInfo)1 IPlayerData (fr.neatmonster.nocheatplus.players.IPlayerData)1 BlockCache (fr.neatmonster.nocheatplus.utilities.map.BlockCache)1 WrapBlockCache (fr.neatmonster.nocheatplus.utilities.map.WrapBlockCache)1 ArrayList (java.util.ArrayList)1 GameMode (org.bukkit.GameMode)1 ItemStack (org.bukkit.inventory.ItemStack)1