Search in sources :

Example 1 with AlmostBoolean

use of fr.neatmonster.nocheatplus.compat.AlmostBoolean in project NoCheatPlus by NoCheatPlus.

the class MovingFlying method processConfirmTeleport.

private void processConfirmTeleport(final PacketEvent event) {
    final PacketContainer packet = event.getPacket();
    final StructureModifier<Integer> integers = packet.getIntegers();
    if (integers.size() != 1) {
        noConfirmTeleportPacket();
        return;
    }
    // TODO: Cross check legacy types (if they even had an integer).
    Integer teleportId = integers.read(0);
    if (teleportId == null) {
        // TODO: Not sure ...
        return;
    }
    final Player player = event.getPlayer();
    final IPlayerData pData = DataManager.getPlayerData(player);
    final NetData data = pData.getGenericInstance(NetData.class);
    final AlmostBoolean matched = data.teleportQueue.processAck(teleportId);
    if (matched.decideOptimistically()) {
        ActionFrequency.subtract(System.currentTimeMillis(), 1, data.flyingFrequencyAll);
    }
    if (pData.isDebugActive(this.checkType)) {
        // TODO: FlyingFrequency / NET_MOVING? + check others who depend
        debug(player, "Confirm teleport packet" + (matched.decideOptimistically() ? (" (matched=" + matched + ")") : "") + ": " + teleportId);
    }
}
Also used : PacketContainer(com.comphenix.protocol.events.PacketContainer) Player(org.bukkit.entity.Player) AlmostBoolean(fr.neatmonster.nocheatplus.compat.AlmostBoolean) NetData(fr.neatmonster.nocheatplus.checks.net.NetData) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData)

Example 2 with AlmostBoolean

use of fr.neatmonster.nocheatplus.compat.AlmostBoolean in project NoCheatPlus by NoCheatPlus.

the class BaseCheckNode method update.

/**
 * Update towards the given rawConfiguration instance.
 *
 * @param rawConfiguration
 * @param forceUpdateChildren
 * @param access
 */
protected void update(final ConfigFile rawConfiguration, final boolean forceUpdateChildren, final IConfigFlagAccess<N> access) {
    @SuppressWarnings("unchecked") final N // TODO
    thisNode = (N) this;
    final AlmostBooleanWithOverride configActivation = access.getConfigState(thisNode);
    // First attempt to override by config.
    if (rawConfiguration != null) {
        if (configActivation.allowsOverrideBy(OverrideType.SPECIFIC)) {
            // TODO: SPECIFIC for inherited !?
            final String configPath = access.getConfigPath(thisNode);
            final AlmostBoolean setValue;
            if (configPath == null) {
                setValue = AlmostBoolean.MAYBE;
            } else {
                // TODO: Contract? Either config is null, or path must exist.
                setValue = rawConfiguration.getAlmostBoolean(configPath, AlmostBoolean.MAYBE);
            }
            configActivation.setValue(setValue, configOverrideType);
        }
    }
    // TODO: else -> set to MAYBE ?
    final boolean oldState = access.getState(thisNode);
    // Update in-place.
    update(false, access);
    final boolean changed = oldState ^ access.getState(thisNode);
    if (forceUpdateChildren) {
        // Update children with configuration (forced).
        for (final N node : this.getChildren()) {
            node.update(rawConfiguration, forceUpdateChildren, access);
        }
    } else if (changed) {
        // Update children just for the changed parent.
        for (final N node : this.getChildren()) {
            // Only update, if the state depends on the parent.
            if (access.getConfigState(node).getValue() == AlmostBoolean.MAYBE) {
                node.update(false, access);
            }
        }
    }
}
Also used : AlmostBoolean(fr.neatmonster.nocheatplus.compat.AlmostBoolean) AlmostBooleanWithOverride(fr.neatmonster.nocheatplus.components.config.value.AlmostBooleanWithOverride)

Example 3 with AlmostBoolean

use of fr.neatmonster.nocheatplus.compat.AlmostBoolean in project NoCheatPlus by NoCheatPlus.

the class BaseCheckNode method update.

/**
 * Update in place according to tree state.
 *
 * @param forceUpdateChildren
 * @param access
 */
protected void update(final boolean forceUpdateChildren, final IConfigFlagAccess<N> access) {
    @SuppressWarnings("unchecked") final N // TODO
    thisNode = (N) this;
    final boolean previousActive = access.getState(thisNode);
    final AlmostBooleanWithOverride configActivation = access.getConfigState(thisNode);
    AlmostBoolean newActive = configActivation.getValue();
    if (newActive != AlmostBoolean.MAYBE) {
        access.setState(thisNode, newActive.decide());
    } else {
        // Fetch from parent.
        if (newActive == AlmostBoolean.MAYBE) {
            N parent = getParent();
            if (parent == null) {
                access.setState(thisNode, access.getMissingParentState());
            } else {
                // Assume top-down updating always.
                access.setState(thisNode, access.getState(parent));
            }
        } else {
            access.setState(thisNode, newActive.decide());
        }
    }
    // Update on changes, or if forced.
    if (forceUpdateChildren || previousActive != access.getState(thisNode)) {
        // Update children.
        for (final N node : this.getChildren()) {
            // Only update, if the state depends on the parent.
            if (forceUpdateChildren || access.getConfigState(node).getValue() == AlmostBoolean.MAYBE) {
                node.update(forceUpdateChildren, access);
            }
        }
    }
}
Also used : AlmostBoolean(fr.neatmonster.nocheatplus.compat.AlmostBoolean) AlmostBooleanWithOverride(fr.neatmonster.nocheatplus.components.config.value.AlmostBooleanWithOverride)

Example 4 with AlmostBoolean

use of fr.neatmonster.nocheatplus.compat.AlmostBoolean in project NoCheatPlus by NoCheatPlus.

the class PlayerData method hasPermission.

@Override
public boolean hasPermission(final RegisteredPermission registeredPermission, final Player player) {
    // Check cache and policy.
    PermissionNode node = permissions.get(registeredPermission.getId());
    if (node == null) {
        node = getOrCreatePermissionNode(registeredPermission);
    }
    final FetchingPolicy fetchingPolicy = node.getFetchingPolicy();
    switch(fetchingPolicy) {
        case TRUE:
            return true;
        case FALSE:
            return false;
        default:
    }
    final AlmostBoolean lastState = node.getLastState();
    if (lastState != AlmostBoolean.MAYBE) {
        switch(fetchingPolicy) {
            case ONCE:
                return lastState.decide();
            case INTERVAL:
                if (System.currentTimeMillis() - node.getLastFetch() < node.getFetchInterval()) {
                    return lastState.decide();
                }
            // TODO: ALWAYS: Could still use cache within a check context.
            default:
                // Must fetch.
                break;
        }
    }
    // Permission not cached or needs to be updated with the PlayerTask.
    final AlmostBoolean fRes = fetchPermission(registeredPermission, player);
    if (fRes == AlmostBoolean.MAYBE) {
        // TODO: Slight risk on left-over meant-temporary permissions.
        return lastState.decide();
    } else {
        node.setState(fRes, System.currentTimeMillis());
        return fRes.decide();
    }
}
Also used : AlmostBoolean(fr.neatmonster.nocheatplus.compat.AlmostBoolean) FetchingPolicy(fr.neatmonster.nocheatplus.permissions.PermissionPolicy.FetchingPolicy) PermissionNode(fr.neatmonster.nocheatplus.permissions.PermissionNode)

Example 5 with AlmostBoolean

use of fr.neatmonster.nocheatplus.compat.AlmostBoolean in project NoCheatPlus by NoCheatPlus.

the class TeleportQueue method processAck.

/**
 * Process ack on receiving a 'confirm teleport' packet.
 *
 * @param teleportId
 * @return YES, if this teleport id is explicitly matched (not necessarily
 *         the latest one), MAYBE if it's a unique id smaller than than
 *         maxConfirmedId. NO, if it's not a valid ack - it could be some
 *         other special condition, like Integer overflow, or timeout.
 */
public AlmostBoolean processAck(final int teleportId) {
    /*
         * Return values are subject to change, e.g.: (ACK_LATEST_POS),
         * ACK_LATEST_ID, ACK_OUTDATED_POS, ACK_OUTDATED_ID, UNKNOWN
         */
    if (teleportId == Integer.MIN_VALUE) {
        // Could consider to return MAYBE for not knowing, needs elaborating on context and use cases.
        return AlmostBoolean.NO;
    }
    lock.lock();
    if (teleportId == lastAckReference.lastOutgoingId) {
        lastAckReference.maxConfirmedId = teleportId;
        // Abort here for efficiency.
        expectIncoming.clear();
        lock.unlock();
        return AlmostBoolean.YES;
    }
    AlmostBoolean ackState = AlmostBoolean.NO;
    final Iterator<CountableLocation> it = expectIncoming.iterator();
    while (it.hasNext()) {
        final CountableLocation ref = it.next();
        // No expiration checks here.
        if (ref.teleportId == teleportId) {
            // Remove all preceding older entries and this one.
            while (ref != expectIncoming.getFirst()) {
                expectIncoming.removeFirst();
            }
            expectIncoming.removeFirst();
            // The count doesn't count anymore.
            ref.count = 0;
            ackState = AlmostBoolean.YES;
            break;
        }
    }
    // Update lastAckReference only if within the safe area.
    if (teleportId < lastAckReference.lastOutgoingId && teleportId > lastAckReference.maxConfirmedId) {
        // Allow update.
        lastAckReference.maxConfirmedId = teleportId;
        if (ackState == AlmostBoolean.NO) {
            // Adjust to maybe, as long as the id is increasing within unique range.
            ackState = AlmostBoolean.MAYBE;
        }
    } else {
        lastAckReference.maxConfirmedId = Integer.MIN_VALUE;
    }
    lock.unlock();
    return ackState;
}
Also used : AlmostBoolean(fr.neatmonster.nocheatplus.compat.AlmostBoolean)

Aggregations

AlmostBoolean (fr.neatmonster.nocheatplus.compat.AlmostBoolean)5 AlmostBooleanWithOverride (fr.neatmonster.nocheatplus.components.config.value.AlmostBooleanWithOverride)2 PacketContainer (com.comphenix.protocol.events.PacketContainer)1 NetData (fr.neatmonster.nocheatplus.checks.net.NetData)1 PermissionNode (fr.neatmonster.nocheatplus.permissions.PermissionNode)1 FetchingPolicy (fr.neatmonster.nocheatplus.permissions.PermissionPolicy.FetchingPolicy)1 IPlayerData (fr.neatmonster.nocheatplus.players.IPlayerData)1 Player (org.bukkit.entity.Player)1