Search in sources :

Example 1 with NetConfig

use of fr.neatmonster.nocheatplus.checks.net.NetConfig in project NoCheatPlus by NoCheatPlus.

the class KeepAliveAdapter method onPacketReceiving.

@Override
public void onPacketReceiving(final PacketEvent event) {
    final long time = System.currentTimeMillis();
    final Player player = event.getPlayer();
    if (player == null) {
        counters.add(ProtocolLibComponent.idNullPlayer, 1);
        event.setCancelled(true);
        return;
    }
    // Always update last received time.
    final IPlayerData pData = DataManager.getPlayerData(player);
    final NetData data = pData.getGenericInstance(NetData.class);
    data.lastKeepAliveTime = time;
    final NetConfig cc = pData.getGenericInstance(NetConfig.class);
    // TODO: Better integration with god-mode check / trigger reset ndt.
    if (frequencyCheck.isEnabled(player, pData) && frequencyCheck.check(player, time, data, cc, pData)) {
        event.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) NetData(fr.neatmonster.nocheatplus.checks.net.NetData) NetConfig(fr.neatmonster.nocheatplus.checks.net.NetConfig) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData)

Example 2 with NetConfig

use of fr.neatmonster.nocheatplus.checks.net.NetConfig in project NoCheatPlus by NoCheatPlus.

the class UseEntityAdapter method onPacketReceiving.

@Override
public void onPacketReceiving(final PacketEvent event) {
    final long time = System.currentTimeMillis();
    final Player player = event.getPlayer();
    if (player == null) {
        // TODO: Warn once?
        return;
    }
    final IPlayerData pData = DataManager.getPlayerData(player);
    final NetData data = pData.getGenericInstance(NetData.class);
    // Always set last received time.
    data.lastKeepAliveTime = time;
    // Quick return, if no checks are active.
    if (!pData.isCheckActive(CheckType.NET_ATTACKFREQUENCY, player)) {
        return;
    }
    final PacketContainer packet = event.getPacket();
    // MIGHT: use entity, use block both on packet level?
    boolean isAttack = false;
    boolean packetInterpreted = false;
    if (legacySet != null) {
        // Attempt to extract legacy information.
        final int flags = getAction_legacy(packet);
        if ((flags & INTERPRETED) != 0) {
            packetInterpreted = true;
            if ((flags & ATTACK) != 0) {
                isAttack = true;
            }
        }
    }
    if (!packetInterpreted) {
        // Handle as if latest.
        final StructureModifier<EntityUseAction> actions;
        actions = packet.getEntityUseActions();
        if (actions.size() == 1 && actions.read(0) == EntityUseAction.ATTACK) {
            isAttack = true;
            packetInterpreted = true;
        }
    }
    if (!packetInterpreted) {
        // TODO: Log warning once, if the packet could not be interpreted.
        return;
    }
    // Run checks.
    boolean cancel = false;
    // AttackFrequency
    if (isAttack) {
        final NetConfig cc = pData.getGenericInstance(NetConfig.class);
        if (attackFrequency.isEnabled(player, pData) && attackFrequency.check(player, time, data, cc, pData)) {
            cancel = true;
        }
    }
    if (cancel) {
        event.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) PacketContainer(com.comphenix.protocol.events.PacketContainer) NetData(fr.neatmonster.nocheatplus.checks.net.NetData) EntityUseAction(com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction) NetConfig(fr.neatmonster.nocheatplus.checks.net.NetConfig) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData)

Example 3 with NetConfig

use of fr.neatmonster.nocheatplus.checks.net.NetConfig in project NoCheatPlus by NoCheatPlus.

the class CatchAllAdapter method onPacketReceiving.

@Override
public void onPacketReceiving(PacketEvent event) {
    final Player player = event.getPlayer();
    if (player == null) {
        counters.add(ProtocolLibComponent.idNullPlayer, 1);
        // TODO: Is this a problem, as the server has the player so it could break a block)?
        return;
    }
    final IPlayerData pData = DataManager.getPlayerData(player);
    if (packetFrequency.isEnabled(player, pData)) {
        final NetConfig cc = pData.getGenericInstance(NetConfig.class);
        final NetData data = pData.getGenericInstance(NetData.class);
        if (packetFrequency.check(player, data, cc)) {
            event.setCancelled(true);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) NetData(fr.neatmonster.nocheatplus.checks.net.NetData) NetConfig(fr.neatmonster.nocheatplus.checks.net.NetConfig) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData)

Example 4 with NetConfig

use of fr.neatmonster.nocheatplus.checks.net.NetConfig in project NoCheatPlus by NoCheatPlus.

the class MovingFlying method onFlyingPacket.

private void onFlyingPacket(final PacketEvent event) {
    // TODO: Code review protocol plugin :p.
    final boolean primaryThread = Bukkit.isPrimaryThread();
    counters.add(idFlying, 1, primaryThread);
    if (event.isAsync() == primaryThread) {
        counters.add(ProtocolLibComponent.idInconsistentIsAsync, 1, primaryThread);
    }
    if (!primaryThread) {
        // Count all asynchronous events extra.
        counters.addSynchronized(idAsyncFlying, 1);
    // TODO: Detect game phase for the player?
    }
    final long time = System.currentTimeMillis();
    final Player player = event.getPlayer();
    if (player == null) {
        // TODO: Need config?
        counters.add(ProtocolLibComponent.idNullPlayer, 1, primaryThread);
        event.setCancelled(true);
        return;
    }
    final IPlayerData pData = DataManager.getPlayerData(player);
    // Always update last received time.
    final NetData data = pData.getGenericInstance(NetData.class);
    // Update without much of a contract.
    data.lastKeepAliveTime = time;
    // TODO: Leniency options too (packet order inversion). -> current: flyingQueue is fetched.
    final IWorldData worldData = pData.getCurrentWorldDataSafe();
    if (!worldData.isCheckActive(CheckType.NET_FLYINGFREQUENCY)) {
        return;
    }
    final NetConfig cc = pData.getGenericInstance(NetConfig.class);
    boolean cancel = false;
    // Interpret the packet content.
    final DataPacketFlying packetData = interpretPacket(event, time);
    // Early return tests, if the packet can be interpreted.
    boolean skipFlyingFrequency = false;
    if (packetData != null) {
        // Prevent processing packets with obviously malicious content.
        if (isInvalidContent(packetData)) {
            // TODO: extra actions: log and kick (cancel state is not evaluated)
            event.setCancelled(true);
            if (pData.isDebugActive(this.checkType)) {
                debug(player, "Incoming packet, cancel due to malicious content: " + packetData.toString());
            }
            return;
        }
        switch(data.teleportQueue.processAck(packetData)) {
            case WAITING:
                {
                    if (pData.isDebugActive(this.checkType)) {
                        debug(player, "Incoming packet, still waiting for ACK on outgoing position.");
                    }
                    if (confirmTeleportType != null && cc.supersededFlyingCancelWaiting) {
                        // Don't add to the flying queue for now (assumed invalid).
                        final AckReference ackReference = data.teleportQueue.getLastAckReference();
                        if (ackReference.lastOutgoingId != Integer.MIN_VALUE && ackReference.lastOutgoingId != ackReference.maxConfirmedId) {
                            // Still waiting for a 'confirm teleport' packet. More or less safe to cancel this out.
                            /*
                             * TODO: The actual issue with this, apart from
                             * potential freezing, also concerns gameplay experience
                             * in case of minor set backs, which also could be
                             * caused by the server, e.g. with 'moved wrongly' or
                             * setting players outside of blocks. In this case the
                             * moves sent before teleport ack would still be valid
                             * after the teleport, because distances are small. The
                             * actual solution should still be to a) not have false
                             * positives b) somehow get rid all the
                             * position-correction teleporting the server does, for
                             * the cases a plugin can handle.
                             */
                            // TODO: Timeout -> either skip cancel or schedule a set back (to last valid pos or other).
                            // TODO: Config?
                            cancel = true;
                        }
                    }
                    break;
                }
            case ACK:
                {
                    // Skip processing ACK packets, no cancel.
                    skipFlyingFrequency = true;
                    if (pData.isDebugActive(this.checkType)) {
                        debug(player, "Incoming packet, interpret as ACK for outgoing position.");
                    }
                }
            default:
                {
                    // Continue.
                    // TODO: Not the optimal position, perhaps.
                    data.addFlyingQueue(packetData);
                }
        }
        // Add as valid packet (exclude invalid coordinates etc. for now).
        validContent.add(packetData.getSimplifiedContentType());
    }
    // TODO: Consider using the NetStatic check.
    if (!cancel && !skipFlyingFrequency && !pData.hasBypass(CheckType.NET_FLYINGFREQUENCY, player) && flyingFrequency.check(player, packetData, time, data, cc, pData)) {
        cancel = true;
    }
    // Process cancel and debug log.
    if (cancel) {
        event.setCancelled(true);
    }
    if (pData.isDebugActive(this.checkType)) {
        debug(player, (packetData == null ? "(Incompatible data)" : packetData.toString()) + (event.isCancelled() ? " CANCEL" : ""));
    }
}
Also used : Player(org.bukkit.entity.Player) NetData(fr.neatmonster.nocheatplus.checks.net.NetData) NetConfig(fr.neatmonster.nocheatplus.checks.net.NetConfig) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) AckReference(fr.neatmonster.nocheatplus.checks.net.model.TeleportQueue.AckReference) IWorldData(fr.neatmonster.nocheatplus.worlds.IWorldData) DataPacketFlying(fr.neatmonster.nocheatplus.checks.net.model.DataPacketFlying)

Example 5 with NetConfig

use of fr.neatmonster.nocheatplus.checks.net.NetConfig in project NoCheatPlus by NoCheatPlus.

the class SoundDistance method onPacketSending.

@Override
public void onPacketSending(final PacketEvent event) {
    final PacketContainer packetContainer = event.getPacket();
    // Compare sound effect name.
    if (!isSoundMonitored(packetContainer)) {
        return;
    }
    final Player player = event.getPlayer();
    final IPlayerData pData = DataManager.getPlayerData(player);
    if (!pData.isCheckActive(CheckType.NET_SOUNDDISTANCE, player)) {
        return;
    }
    // Compare distance of player to the weather location.
    final Location loc = player.getLocation(useLoc);
    final StructureModifier<Integer> ints = packetContainer.getIntegers();
    final double dSq = TrigUtil.distanceSquared(ints.read(0) / 8, ints.read(2) / 8, loc.getX(), loc.getZ());
    // if (data.debug) {
    // debug(player, "SoundDistance(" + soundName + "): " + StringUtil.fdec1.format(Math.sqrt(dSq)));
    // }
    final NetConfig cc = pData.getGenericInstance(NetConfig.class);
    if (dSq > cc.soundDistanceSq) {
        event.setCancelled(true);
        counters.add(idSoundEffectCancel, 1);
    }
    useLoc.setWorld(null);
}
Also used : PacketContainer(com.comphenix.protocol.events.PacketContainer) Player(org.bukkit.entity.Player) NetConfig(fr.neatmonster.nocheatplus.checks.net.NetConfig) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) Location(org.bukkit.Location)

Aggregations

NetConfig (fr.neatmonster.nocheatplus.checks.net.NetConfig)5 IPlayerData (fr.neatmonster.nocheatplus.players.IPlayerData)5 Player (org.bukkit.entity.Player)5 NetData (fr.neatmonster.nocheatplus.checks.net.NetData)4 PacketContainer (com.comphenix.protocol.events.PacketContainer)2 EntityUseAction (com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction)1 DataPacketFlying (fr.neatmonster.nocheatplus.checks.net.model.DataPacketFlying)1 AckReference (fr.neatmonster.nocheatplus.checks.net.model.TeleportQueue.AckReference)1 IWorldData (fr.neatmonster.nocheatplus.worlds.IWorldData)1 Location (org.bukkit.Location)1