Search in sources :

Example 16 with ViolationData

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

the class AttackFrequency method check.

public boolean check(final Player player, final long time, final NetData data, final NetConfig cc, final IPlayerData pData) {
    // Update frequency.
    data.attackFrequencySeconds.add(time, 1f);
    double maxVL = 0.0;
    float maxLimit = 0f;
    String tags = null;
    // TODO: option to normalize the vl / stats to per second?
    // HALF
    // HALF
    float sum = data.attackFrequencySeconds.bucketScore(0);
    float limit = cc.attackFrequencyLimitSecondsHalf;
    if (sum - limit > maxVL) {
        maxVL = sum - limit;
        maxLimit = limit;
        tags = "sec_half";
    }
    // ONE (update sum).
    sum += data.attackFrequencySeconds.bucketScore(1);
    limit = cc.attackFrequencyLimitSecondsOne;
    if (sum - limit > maxVL) {
        maxVL = sum - limit;
        maxLimit = limit;
        tags = "sec_one";
    }
    // TWO (update sum).
    sum += data.attackFrequencySeconds.sliceScore(2, 4, 1f);
    limit = cc.attackFrequencyLimitSecondsTwo;
    if (sum - limit > maxVL) {
        maxVL = sum - limit;
        maxLimit = limit;
        tags = "sec_two";
    }
    // FOUR (update sum).
    sum += data.attackFrequencySeconds.sliceScore(4, 8, 1f);
    limit = cc.attackFrequencyLimitSecondsFour;
    if (sum - limit > maxVL) {
        maxVL = sum - limit;
        maxLimit = limit;
        tags = "sec_four";
    }
    // EIGHT (update sum).
    sum += data.attackFrequencySeconds.sliceScore(8, 16, 1f);
    limit = cc.attackFrequencyLimitSecondsEight;
    if (sum - limit > maxVL) {
        maxVL = sum - limit;
        maxLimit = limit;
        tags = "sec_eight";
    }
    // if (data.debug) {
    // player.sendMessage("AttackFrequency: " + data.attackFrequencySeconds.toLine());
    // }
    boolean cancel = false;
    if (maxVL > 0.0) {
        // Trigger a violation.
        final ViolationData vd = new ViolationData(this, player, maxVL, 1.0, cc.attackFrequencyActions);
        if (pData.isDebugActive(type) || vd.needsParameters()) {
            vd.setParameter(ParameterName.PACKETS, Integer.toString((int) sum));
            vd.setParameter(ParameterName.LIMIT, Integer.toString((int) maxLimit));
            vd.setParameter(ParameterName.TAGS, tags);
        }
        if (executeActions(vd).willCancel()) {
            cancel = true;
        }
        // Feed Improbable.
        TickTask.requestImprobableUpdate(player.getUniqueId(), 2f);
    }
    return cancel;
}
Also used : ViolationData(fr.neatmonster.nocheatplus.checks.ViolationData)

Example 17 with ViolationData

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

the class FastConsume method check.

private boolean check(final Player player, final ItemStack stack, final long time, final InventoryData data, final IPlayerData pData) {
    // Consistency checks...
    if (stack == null) {
        // TODO: Strict version should prevent other material (?).
        return false;
    }
    final long ref = data.instantEatInteract == 0 ? 0 : Math.max(data.instantEatInteract, data.lastClickTime);
    if (time < ref) {
        // Time ran backwards.
        data.instantEatInteract = data.lastClickTime = time;
        return false;
    }
    // Check exceptions.
    final InventoryConfig cc = pData.getGenericInstance(InventoryConfig.class);
    final Material mat = stack == null ? null : stack.getType();
    if (mat != null) {
        if (cc.fastConsumeWhitelist) {
            if (!cc.fastConsumeItems.contains(mat)) {
                return false;
            }
        } else if (cc.fastConsumeItems.contains(mat)) {
            return false;
        }
    }
    // Actually check.
    // Not interact = instant.
    final long timeSpent = ref == 0 ? 0 : (time - ref);
    final long expectedDuration = cc.fastConsumeDuration;
    boolean cancel = false;
    if (timeSpent < expectedDuration) {
        // TODO: Might have to do a specialized check for lag spikes here instead.
        final float lag = TickTask.getLag(expectedDuration, true);
        if (timeSpent * lag < expectedDuration) {
            final double difference = (expectedDuration - timeSpent * lag) / 100.0;
            data.instantEatVL += difference;
            final ViolationData vd = new ViolationData(this, player, data.instantEatVL, difference, cc.fastConsumeActions);
            vd.setParameter(ParameterName.FOOD, "" + mat);
            if (data.instantEatFood != mat) {
                vd.setParameter(ParameterName.TAGS, "inconsistent(" + data.instantEatFood + ")");
            } else {
                vd.setParameter(ParameterName.TAGS, "");
            }
            if (executeActions(vd).willCancel()) {
                cancel = true;
            }
        }
    } else {
        data.instantEatVL *= 0.6;
    }
    // Reset interaction.
    if (cancel) {
        // Fake interaction to prevent violation loops with false positives.
        final ItemStack actualStack = InventoryUtil.getFirstConsumableItemInHand(player);
        data.instantEatFood = actualStack == null ? null : actualStack.getType();
    // TODO: Allows some abuse: 1. try instantly eat (cancelled) 2. consume item directly when needed.
    } else {
        if (pData.isDebugActive(type)) {
            debug(player, "PlayerItemConsumeEvent, reset fastconsume: " + data.instantEatFood);
        }
        data.instantEatFood = null;
    }
    data.instantEatInteract = time;
    return cancel;
}
Also used : Material(org.bukkit.Material) ViolationData(fr.neatmonster.nocheatplus.checks.ViolationData) ItemStack(org.bukkit.inventory.ItemStack)

Example 18 with ViolationData

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

the class Reach method check.

/**
 * Checks a player.
 *
 * @param player
 *            the player
 * @param blockLocation
 *            the location
 * @return true, if successful
 */
public boolean check(final Player player, final Location loc, final double eyeHeight, final Block block, final BlockInteractData data, final BlockInteractConfig cc) {
    boolean cancel = false;
    final double distanceLimit = player.getGameMode() == GameMode.CREATIVE ? CREATIVE_DISTANCE : SURVIVAL_DISTANCE;
    // Distance is calculated from eye location to center of targeted block. If the player is further away from their
    // target than allowed, the difference will be assigned to "distance".
    // TODO: On failure loop through flying queue, and do set not working entries to null (!).
    final double distance = TrigUtil.distance(loc.getX(), loc.getY() + eyeHeight, loc.getZ(), 0.5 + block.getX(), 0.5 + block.getY(), 0.5 + block.getZ()) - distanceLimit;
    if (distance > 0) {
        // They failed, increment violation level.
        data.reachVL += distance;
        // Remember how much further than allowed he tried to reach for logging, if necessary.
        data.reachDistance = distance;
        // 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.reachVL, distance, cc.reachActions);
        vd.setParameter(ParameterName.REACH_DISTANCE, String.valueOf(Math.round(data.reachDistance)));
        cancel = executeActions(vd).willCancel();
    } else {
        // Player passed the check, reward them.
        data.reachVL *= 0.9D;
        data.addPassedCheck(this.type);
    }
    return cancel;
}
Also used : ViolationData(fr.neatmonster.nocheatplus.checks.ViolationData)

Example 19 with ViolationData

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

the class Visible method check.

public boolean check(final Player player, final Location loc, final double eyeHeight, final Block block, final BlockFace face, final Action action, final FlyingQueueHandle flyingHandle, final BlockInteractData data, final BlockInteractConfig cc, final IPlayerData pData) {
    // TODO: This check might make parts of interact/blockbreak/... + direction (+?) obsolete.
    // TODO: Might confine what to check for (left/right-click, target blocks depending on item in hand, container blocks).
    boolean collides;
    final int blockX = block.getX();
    final int blockY = block.getY();
    final int blockZ = block.getZ();
    final double eyeX = loc.getX();
    final double eyeY = loc.getY() + eyeHeight;
    final double eyeZ = loc.getZ();
    final boolean debug = pData.isDebugActive(type);
    tags.clear();
    if (TrigUtil.isSameBlock(blockX, blockY, blockZ, eyeX, eyeY, eyeZ)) {
        // Player is interacting with the block their head is in.
        // TODO: Should the reachable-face-check be done here too (if it is added at all)?
        collides = false;
    } else {
        // Ray-tracing.
        // Initialize.
        final BlockCache blockCache = this.wrapBlockCache.getBlockCache();
        blockCache.setAccess(loc.getWorld());
        rayTracing.setBlockCache(blockCache);
        collides = !checker.checkFlyingQueue(eyeX, eyeY, eyeZ, loc.getYaw(), loc.getPitch(), blockX, blockY, blockZ, flyingHandle, face, tags, debug, player);
        checker.cleanup();
        useLoc.setWorld(null);
        // Cleanup.
        rayTracing.cleanup();
        blockCache.cleanup();
    }
    // Actions ?
    boolean cancel = false;
    if (collides) {
        data.visibleVL += 1;
        final ViolationData vd = new ViolationData(this, player, data.visibleVL, 1, cc.visibleActions);
        // }
        if (executeActions(vd).willCancel()) {
            cancel = true;
        }
    } else {
        data.visibleVL *= 0.99;
        data.addPassedCheck(this.type);
        if (debug) {
            debug(player, "pitch=" + loc.getPitch() + ",yaw=" + loc.getYaw() + " tags=" + StringUtil.join(tags, "+"));
        }
    }
    return cancel;
}
Also used : BlockCache(fr.neatmonster.nocheatplus.utilities.map.BlockCache) WrapBlockCache(fr.neatmonster.nocheatplus.utilities.map.WrapBlockCache) ViolationData(fr.neatmonster.nocheatplus.checks.ViolationData)

Example 20 with ViolationData

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

the class AutoSign method handleViolation.

/**
 * @param player
 * @param violationTime Amount of too fast editing.
 * @param data
 * @return
 */
private boolean handleViolation(final Player player, final long violationTime, final BlockPlaceData data, final BlockPlaceConfig cc) {
    final double addedVL = 10.0 * Math.min(maxEditTime, violationTime) / maxEditTime;
    data.autoSignVL += addedVL;
    final ViolationData vd = new ViolationData(this, player, data.autoSignVL, addedVL, cc.autoSignActions);
    if (vd.needsParameters()) {
        vd.setParameter(ParameterName.TAGS, StringUtil.join(tags, "+"));
    }
    return executeActions(vd).willCancel();
}
Also used : 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