Search in sources :

Example 1 with SetBackEntry

use of fr.neatmonster.nocheatplus.checks.moving.location.setback.SetBackEntry in project NoCheatPlus by NoCheatPlus.

the class VehicleChecks method checkVehicleMove.

/**
 * The actual checks for vehicle moving. Nested passengers are not handled
 * here. Demands firstPastMove to be valid.
 * <hr>
 * Prerequisite is having currentMove set in the most appropriate way for
 * data.vehicleMoves.
 *
 * @param vehicle
 *            The vehicle that deosn't have a vehicle. Must be valid and not
 *            dead.
 * @param vehicleType
 *            Type of that vehicle.
 * @param moveInfo
 * @param firstPastMove
 * @param thisMove2
 * @param player
 *            The first player passenger of that vehicle. Not null, not
 *            dead.
 * @param vehicleLoc
 *            Current location of the vehicle. For reference checking, the
 *            given instance will not be stored anywhere from within here.
 * @param fake
 *            False if this is called directly from a VehicleMoveEvent
 *            (should be legacy or real errors). True if called from
 *            onVehicleUpdate.
 * @param data
 * @param cc2
 */
private void checkVehicleMove(final Entity vehicle, final EntityType vehicleType, final Location vehicleLocation, final World world, final VehicleMoveInfo moveInfo, final VehicleMoveData thisMove, final VehicleMoveData firstPastMove, final Player player, final boolean fake, final MovingData data, final MovingConfig cc, final IPlayerData pData) {
    // TODO: (private or public?)
    final boolean debug = pData.isDebugActive(checkType);
    data.joinOrRespawn = false;
    data.vehicleConsistency = MoveConsistency.getConsistency(thisMove, player.getLocation(useLoc1));
    switch(data.vehicleConsistency) {
        case FROM:
        case TO:
            // TODO: Drop MC 1.4!
            aux.resetPositionsAndMediumProperties(player, player.getLocation(useLoc1), data, cc);
            break;
        case INCONSISTENT:
            // TODO: Test with latency.
            break;
    }
    SetBackEntry newTo = null;
    data.sfNoLowJump = true;
    if (cc.noFallVehicleReset) {
        // Reset noFall data.
        // Might allow one time cheat.
        data.noFallSkipAirCheck = true;
        data.sfLowJump = false;
        data.clearNoFallData();
    }
    if (debug) {
        // Log move.
        outputDebugVehicleMove(player, vehicle, thisMove, fake);
    }
    // Ensure a common set back for now.
    if (!data.vehicleSetBacks.isDefaultEntryValid()) {
        ensureSetBack(player, thisMove, data, pData);
    }
    // TODO: Use set back storage for testing if this is appropriate (use SetBackEntry instead, remove Location retrieval then?).
    if ((newTo == null || data.vehicleSetBacks.getSafeMediumEntry().isValidAndOlderThan(newTo)) && pData.isCheckActive(CheckType.MOVING_VEHICLE_ENVELOPE, player)) {
        // Skip if this is the first move after set back, with to=set back.
        if (data.timeSinceSetBack == 0 || thisMove.to.hashCode() == data.lastSetBackHash) {
            // TODO: This is a hot fix, to prevent a set back loop. Depends on having only the morepackets set back for vehicles.
            // TODO: Perhaps might want to add || !data.equalsAnyVehicleSetBack(to)
            thisMove.specialCondition = true;
            if (debug) {
                debug(player, "Skip envelope check on first move after set back acknowledging the set back with an odd starting point (from).");
            }
        } else {
            // Set up basic details about what/how to check.
            vehicleEnvelope.prepareCheckDetails(vehicle, moveInfo, thisMove);
            // Check.
            final SetBackEntry tempNewTo = vehicleEnvelope.check(player, vehicle, thisMove, fake, data, cc, pData);
            if (tempNewTo != null) {
                newTo = tempNewTo;
            }
        }
    }
    // TODO: Still always update the frequency part?
    if ((newTo == null || data.vehicleSetBacks.getMidTermEntry().isValidAndOlderThan(newTo))) {
        if (pData.isCheckActive(CheckType.MOVING_VEHICLE_MOREPACKETS, player)) {
            final SetBackEntry tempNewTo = vehicleMorePackets.check(player, thisMove, newTo, data, cc, pData);
            if (tempNewTo != null) {
                newTo = tempNewTo;
            }
        } else {
            // Otherwise we need to clear their data.
            // TODO: Make mid-term set back resetting independent of more packets.
            data.clearVehicleMorePacketsData();
        }
    }
    // Schedule a set back?
    if (newTo == null) {
        // Update vehicle data for passive player passengers.
        final List<Entity> passengers = passengerUtil.handleVehicle.getHandle().getEntityPassengers(vehicle);
        if (passengers.size() > 1) {
            updateVehicleData(player, data, vehicle, moveInfo, passengers);
        }
        // Increase time since set back.
        data.timeSinceSetBack++;
        // Finally finish processing the current move and move it to past ones.
        data.vehicleMoves.finishCurrentMove();
    } else {
        setBack(player, vehicle, newTo, data, cc, pData);
    }
    useLoc1.setWorld(null);
}
Also used : Entity(org.bukkit.entity.Entity) SetBackEntry(fr.neatmonster.nocheatplus.checks.moving.location.setback.SetBackEntry)

Example 2 with SetBackEntry

use of fr.neatmonster.nocheatplus.checks.moving.location.setback.SetBackEntry 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 3 with SetBackEntry

use of fr.neatmonster.nocheatplus.checks.moving.location.setback.SetBackEntry in project NoCheatPlus by NoCheatPlus.

the class VehicleChecks method checkVehicleMove.

/**
 * Uses both useLoc1 and useLoc2, possibly others too.
 *
 * @param vehicle
 * @param vehicleType
 * @param from
 *            May be null, may be ignored anyway. Might be used as
 *            firstPastMove, in case of data missing.
 * @param to
 *            May be null, may be ignored anyway.
 * @param player
 * @param fake
 * @param data
 * @param pData2
 * @param debug
 */
private void checkVehicleMove(final Entity vehicle, final EntityType vehicleType, final Location from, final Location to, final Player player, final boolean fake, final MovingData data, final IPlayerData pData, boolean debug) {
    // TODO: Detect teleportation and similar.
    final MovingConfig cc = pData.getGenericInstance(MovingConfig.class);
    // Exclude certain vehicle types.
    if (cc.ignoredVehicles.contains(vehicleType)) {
        // 100% legit.
        data.clearVehicleData();
        return;
    }
    final World world = vehicle.getWorld();
    final VehicleMoveInfo moveInfo = aux.useVehicleMoveInfo();
    // vehicleLocation: Track when it could become null! -> checkIllegal  -> no setback or null location.
    final Location vehicleLocation = vehicle.getLocation(moveInfo.useLoc);
    final VehicleMoveData firstPastMove = data.vehicleMoves.getFirstPastMove();
    // Ensure firstPastMove is valid.
    if (!firstPastMove.valid) {
        // Determine the best location to use as past move.
        // TODO: Could also check the set backs for plausible entries, however that would lead to a violation by default. Could use an indicator.
        final Location refLoc = from == null ? vehicleLocation : from;
        MovingUtil.ensureChunksLoaded(player, refLoc, "vehicle move (no past move)", data, cc, pData);
        aux.resetVehiclePositions(vehicle, refLoc, data, cc);
        if (pData.isDebugActive(checkType)) {
            // TODO: Might warn instead.
            debug(player, "Missing past move data, set to: " + firstPastMove.from);
        }
    }
    // Determine best locations to use.
    // (Currently always use firstPastMove and vehicleLocation.)
    final Location useFrom = LocUtil.set(useLoc1, world, firstPastMove.toIsValid ? firstPastMove.to : firstPastMove.from);
    final Location useTo = vehicleLocation;
    // Initialize moveInfo.
    if (vehicleType == EntityType.PIG) {
        // TODO: Special cases by config rather.
        // TODO: Likely will fail with passable.
        moveInfo.setExtendFullWidth(0.52);
    }
    // TODO: Test yOnGround at 0.13 instead of xz-margin
    moveInfo.set(vehicle, useFrom, useTo, // TODO: Extra config.
    vehicleType == EntityType.PIG ? Math.max(0.13, cc.yOnGround) : cc.yOnGround);
    moveInfo.setExtendFullWidth(0.0);
    // Check coordinates, just in case.
    if (checkIllegal(moveInfo.from, moveInfo.to)) {
        // Likely superfluous.
        // TODO: Obviously applies under unknown conditions.
        SetBackEntry newTo = data.vehicleSetBacks.getValidSafeMediumEntry();
        if (newTo == null) {
            recoverVehicleSetBack(player, vehicle, vehicleLocation, moveInfo, data, cc);
        }
        NCPAPIProvider.getNoCheatPlusAPI().getLogManager().warning(Streams.STATUS, CheckUtils.getLogMessagePrefix(player, CheckType.MOVING_VEHICLE) + "Illegal coordinates on checkVehicleMove: from: " + from + " , to: " + to);
        setBack(player, vehicle, newTo, data, cc, pData);
        aux.returnVehicleMoveInfo(moveInfo);
        return;
    }
    // Ensure chunks are loaded.
    MovingUtil.ensureChunksLoaded(player, useFrom, useTo, firstPastMove, "vehicle move", cc, pData);
    // Initialize currentMove.
    final VehicleMoveData thisMove = data.vehicleMoves.getCurrentMove();
    thisMove.set(moveInfo.from, moveInfo.to);
    // Prepare all extra properties by default for now.
    MovingUtil.prepareFullCheck(moveInfo.from, moveInfo.to, thisMove, cc.yOnGround);
    thisMove.setExtraVehicleProperties(vehicle);
    // Call checkVehicleMove for actual checks.
    checkVehicleMove(vehicle, vehicleType, vehicleLocation, world, moveInfo, thisMove, firstPastMove, player, fake, data, cc, pData);
    // Cleanup.
    aux.returnVehicleMoveInfo(moveInfo);
}
Also used : VehicleMoveData(fr.neatmonster.nocheatplus.checks.moving.model.VehicleMoveData) SetBackEntry(fr.neatmonster.nocheatplus.checks.moving.location.setback.SetBackEntry) MovingConfig(fr.neatmonster.nocheatplus.checks.moving.MovingConfig) World(org.bukkit.World) VehicleMoveInfo(fr.neatmonster.nocheatplus.checks.moving.model.VehicleMoveInfo) Location(org.bukkit.Location) RichBoundsLocation(fr.neatmonster.nocheatplus.utilities.location.RichBoundsLocation)

Aggregations

SetBackEntry (fr.neatmonster.nocheatplus.checks.moving.location.setback.SetBackEntry)3 ViolationData (fr.neatmonster.nocheatplus.checks.ViolationData)1 MovingConfig (fr.neatmonster.nocheatplus.checks.moving.MovingConfig)1 VehicleMoveData (fr.neatmonster.nocheatplus.checks.moving.model.VehicleMoveData)1 VehicleMoveInfo (fr.neatmonster.nocheatplus.checks.moving.model.VehicleMoveInfo)1 RichBoundsLocation (fr.neatmonster.nocheatplus.utilities.location.RichBoundsLocation)1 Location (org.bukkit.Location)1 World (org.bukkit.World)1 Entity (org.bukkit.entity.Entity)1