Search in sources :

Example 6 with ViolationData

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

the class Speed method check.

/**
 * Checks a player.
 *
 * @param player
 *            the player
 * @param now
 * @return true, if successful
 */
public boolean check(final Player player, final long now, final FightData data, final FightConfig cc, final IPlayerData pData) {
    final boolean lag = pData.getCurrentWorldData().shouldAdjustToLag(type);
    boolean cancel = false;
    // Add to frequency.
    data.speedBuckets.add(now, 1f);
    // Medium term (normalized to one second), account for server side lag.
    final long fullTime = cc.speedBucketDur * cc.speedBuckets;
    final float fullLag = lag ? TickTask.getLag(fullTime, true) : 1f;
    final float total = data.speedBuckets.score(cc.speedBucketFactor) * 1000f / (fullLag * fullTime);
    // Short term.
    final int tick = TickTask.getTick();
    if (tick < data.speedShortTermTick) {
        // Tick task got reset.
        data.speedShortTermTick = tick;
        data.speedShortTermCount = 1;
    } else if (tick - data.speedShortTermTick < cc.speedShortTermTicks) {
        // Account for server side lag.
        if (!lag || TickTask.getLag(50L * (tick - data.speedShortTermTick), true) < 1.5f) {
            // Within range, add.
            data.speedShortTermCount++;
        } else {
            // Too much lag, reset.
            data.speedShortTermTick = tick;
            data.speedShortTermCount = 1;
        }
    } else {
        data.speedShortTermTick = tick;
        data.speedShortTermCount = 1;
    }
    final float shortTerm = (float) data.speedShortTermCount * 1000f / (50f * cc.speedShortTermTicks);
    final float max = Math.max(shortTerm, total);
    // Too many attacks?
    if (max > cc.speedLimit) {
        // If there was lag, don't count it towards violation level.
        data.speedVL += max - cc.speedLimit;
        // 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.speedVL, max - cc.speedLimit, cc.speedActions);
        vd.setParameter(ParameterName.LIMIT, String.valueOf(Math.round(cc.speedLimit)));
        cancel = executeActions(vd).willCancel();
    } else
        data.speedVL *= 0.96;
    return cancel;
}
Also used : ViolationData(fr.neatmonster.nocheatplus.checks.ViolationData)

Example 7 with ViolationData

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

the class Improbable method checkImprobable.

private boolean checkImprobable(final Player player, final float weight, final long now, final String tags, final IPlayerData pData) {
    if (!pData.isCheckActive(type, player)) {
        return false;
    }
    final CombinedData data = pData.getGenericInstance(CombinedData.class);
    final CombinedConfig cc = pData.getGenericInstance(CombinedConfig.class);
    data.improbableCount.add(now, weight);
    final float shortTerm = data.improbableCount.bucketScore(0);
    double violation = 0;
    boolean violated = false;
    if (shortTerm * 0.8f > cc.improbableLevel / 20.0) {
        final float lag = pData.getCurrentWorldData().shouldAdjustToLag(type) ? TickTask.getLag(data.improbableCount.bucketDuration(), true) : 1f;
        if (shortTerm / lag > cc.improbableLevel / 20.0) {
            violation += shortTerm * 2d / lag;
            violated = true;
        }
    }
    final double full = data.improbableCount.score(1.0f);
    if (full > cc.improbableLevel) {
        final float lag = pData.getCurrentWorldData().shouldAdjustToLag(type) ? TickTask.getLag(data.improbableCount.bucketDuration() * data.improbableCount.numberOfBuckets(), true) : 1f;
        if (full / lag > cc.improbableLevel) {
            violation += full / lag;
            violated = true;
        }
    }
    boolean cancel = false;
    if (violated) {
        // Execute actions
        data.improbableVL += violation / 10.0;
        final ViolationData vd = new ViolationData(this, player, data.improbableVL, violation, cc.improbableActions);
        if (tags != null && !tags.isEmpty())
            vd.setParameter(ParameterName.TAGS, tags);
        cancel = executeActions(vd).willCancel();
    } else
        data.improbableVL *= 0.95;
    return cancel;
}
Also used : ViolationData(fr.neatmonster.nocheatplus.checks.ViolationData)

Example 8 with ViolationData

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

the class MorePackets method check.

/**
 * Check for speeding by sending too many packets. We assume 22 packets per
 * second to be legitimate, while 20 would be ideal. See
 * PlayerData.morePacketsFreq for the monitored amount of time and the
 * resolution. See NetStatic for the actual check code.
 *
 * @param player
 * @param from
 * @param to
 * @param allowSetSetBack
 *            If to allow setting the set back location.
 * @param data
 * @param cc
 * @return
 */
public Location check(final Player player, final PlayerLocation from, final PlayerLocation to, final boolean allowSetSetBack, final MovingData data, final MovingConfig cc, final IPlayerData pData) {
    // Take time once, first:
    final long time = System.currentTimeMillis();
    final boolean debug = pData.isDebugActive(type);
    // Ensure we have a set back location.
    if (allowSetSetBack && !data.hasMorePacketsSetBack()) {
        // TODO: Check if other set back is appropriate or if to set/reset on other events.
        if (data.hasSetBack()) {
            data.setMorePacketsSetBackFromSurvivalfly();
        } else {
            data.setMorePacketsSetBack(from);
        }
    }
    // Check for a violation of the set limits.
    tags.clear();
    final double violation = NetStatic.morePacketsCheck(data.morePacketsFreq, time, 1f, cc.morePacketsEPSMax, cc.morePacketsEPSIdeal, data.morePacketsBurstFreq, cc.morePacketsBurstPackets, cc.morePacketsBurstDirect, cc.morePacketsBurstEPM, tags);
    // Process violation result.
    if (violation > 0.0) {
        // Increment violation level.
        // TODO: Accumulate somehow [e.g. always += 1, decrease with continuous moving without violation]?
        data.morePacketsVL = violation;
        // Violation handling.
        final ViolationData vd = new ViolationData(this, player, data.morePacketsVL, violation, cc.morePacketsActions);
        if (debug || vd.needsParameters()) {
            vd.setParameter(ParameterName.PACKETS, Integer.toString(new Double(violation).intValue()));
            vd.setParameter(ParameterName.TAGS, StringUtil.join(tags, "+"));
        }
        if (executeActions(vd).willCancel()) {
            // TODO
            return data.hasMorePacketsSetBack() ? data.getMorePacketsSetBack() : data.getSetBack(to);
        }
    } else if (allowSetSetBack && data.getMorePacketsSetBackAge() > cc.morePacketsSetBackAge) {
        // Update the set back location. (CHANGED to only update, if not a violation.)
        // (Might update whenever newTo == null)
        data.setMorePacketsSetBack(from);
        if (debug) {
            debug(player, "Update set back (morepackets) to from.");
        }
    }
    // No set back.
    return null;
}
Also used : ViolationData(fr.neatmonster.nocheatplus.checks.ViolationData)

Example 9 with ViolationData

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

the class Against method check.

public boolean check(final Player player, final Block block, final Material placedMat, final Block blockAgainst, final boolean isInteractBlock, final BlockPlaceData data, final BlockPlaceConfig cc, final IPlayerData pData) {
    boolean violation = false;
    // TODO: Make more precise (workarounds like WATER_LILY, general points, such as action?).
    // Workaround for signs on cactus and similar.
    // TODO: pass as argument.
    final BlockInteractData bdata = pData.getGenericInstance(BlockInteractData.class);
    final Material againstType = blockAgainst.getType();
    if (bdata.isConsumedCheck(this.type) && !bdata.isPassedCheck(this.type)) {
        // TODO: Awareness of repeated violation probably is to be implemented below somewhere.
        violation = true;
        if (pData.isDebugActive(type)) {
            debug(player, "Cancel due to block having been consumed by this check.");
        }
    } else if (BlockProperties.isAir(againstType)) {
        // Attempt to workaround blocks like cactus.
        final Material matAgainst = bdata.getLastType();
        if (isInteractBlock && !BlockProperties.isAir(matAgainst) && !BlockProperties.isLiquid(matAgainst)) {
        // Block was placed against something (e.g. cactus), allow it.
        } else if (!pData.hasPermission(Permissions.BLOCKPLACE_AGAINST_AIR, player)) {
            violation = true;
        }
    } else if (BlockProperties.isLiquid(againstType)) {
        // TODO: F_PLACE_AGAINST_WATER|LIQUID...
        if ((placedMat != Material.WATER_LILY || !BlockProperties.isLiquid(block.getRelative(BlockFace.DOWN).getType())) && !pData.hasPermission(Permissions.BLOCKPLACE_AGAINST_LIQUIDS, player)) {
            violation = true;
        }
    }
    // Handle violation and return.
    bdata.addConsumedCheck(this.type);
    if (violation) {
        data.againstVL += 1.0;
        final ViolationData vd = new ViolationData(this, player, data.againstVL, 1, cc.againstActions);
        vd.setParameter(ParameterName.BLOCK_TYPE, placedMat.toString());
        return executeActions(vd).willCancel();
    } else {
        // Assume one false positive every 100 blocks.
        data.againstVL *= 0.99;
        bdata.addPassedCheck(this.type);
        return false;
    }
}
Also used : BlockInteractData(fr.neatmonster.nocheatplus.checks.blockinteract.BlockInteractData) Material(org.bukkit.Material) ViolationData(fr.neatmonster.nocheatplus.checks.ViolationData)

Example 10 with ViolationData

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

the class FastBreak method check.

/**
 * Checks a player for fastbreak. This is NOT for creative mode.
 *
 * @param player
 *            the player
 * @param block
 *            the block
 * @param isInstaBreak
 * @param data
 * @param cc
 * @param elaspedTime
 * @return true, if successful
 */
public boolean check(final Player player, final Block block, final AlmostBoolean isInstaBreak, final BlockBreakConfig cc, final BlockBreakData data, final IPlayerData pData) {
    final long now = System.currentTimeMillis();
    boolean cancel = false;
    // Determine expected breaking time by block type.
    final Material blockType = block.getType();
    final long expectedBreakingTime = Math.max(0, Math.round((double) BlockProperties.getBreakingDuration(blockType, player) * (double) cc.fastBreakModSurvival / 100D));
    final long elapsedTime;
    // TODO: Should it be breakingTime instead of 0 for inconsistencies?
    if (cc.fastBreakStrict) {
        // Counting interact...break.
        elapsedTime = (data.fastBreakBreakTime > data.fastBreakfirstDamage) ? 0 : now - data.fastBreakfirstDamage;
    } else {
        // Counting break...break.
        elapsedTime = (data.fastBreakBreakTime > now) ? 0 : now - data.fastBreakBreakTime;
    }
    // Check if the time used time is lower than expected.
    if (isInstaBreak.decideOptimistically()) {
    // Ignore those for now.
    // TODO: Find out why this was commented out long ago a) did not fix mcMMO b) exploits.
    // TODO: Maybe adjust time to min(time, SOMETHING) for MAYBE/YES.
    } else if (elapsedTime < 0) {
    // Ignore it. TODO: ?
    } else if (elapsedTime + cc.fastBreakDelay < expectedBreakingTime) {
        // lag or cheat or Minecraft.
        // Count in server side lag, if desired.
        final float lag = pData.getCurrentWorldDataSafe().shouldAdjustToLag(type) ? TickTask.getLag(expectedBreakingTime, true) : 1f;
        final long missingTime = expectedBreakingTime - (long) (lag * elapsedTime);
        if (missingTime > 0) {
            // Add as penalty
            data.fastBreakPenalties.add(now, (float) missingTime);
            // Only raise a violation, if the total penalty score exceeds the contention duration (for lag, delay).
            if (data.fastBreakPenalties.score(cc.fastBreakBucketFactor) > cc.fastBreakGrace) {
                // TODO: maybe add one absolute penalty time for big amounts to stop breaking until then
                final double vlAdded = (double) missingTime / 1000.0;
                data.fastBreakVL += vlAdded;
                final ViolationData vd = new ViolationData(this, player, data.fastBreakVL, vlAdded, cc.fastBreakActions);
                if (vd.needsParameters()) {
                    vd.setParameter(ParameterName.BLOCK_TYPE, blockType.toString());
                }
                cancel = executeActions(vd).willCancel();
            }
        // else: still within contention limits.
        }
    } else if (expectedBreakingTime > cc.fastBreakDelay) {
        // Fast breaking does not decrease violation level.
        data.fastBreakVL *= 0.9D;
    }
    // TODO: Rework to use (then hopefully completed) BlockBreakKey.
    if (pData.isDebugActive(type)) {
        tailDebugStats(player, isInstaBreak, blockType, elapsedTime, expectedBreakingTime, data, pData);
    } else {
        data.stats = null;
    }
    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