Search in sources :

Example 1 with NetData

use of fr.neatmonster.nocheatplus.checks.net.NetData 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 NetData

use of fr.neatmonster.nocheatplus.checks.net.NetData 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 3 with NetData

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

the class ProtocolLibComponent method onPlayerRespawn.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false)
public void onPlayerRespawn(final PlayerRespawnEvent event) {
    if (!registeredPacketAdapters.isEmpty()) {
        final Player player = event.getPlayer();
        final NetData data = DataManager.getGenericInstance(player, NetData.class);
        data.onJoin(player);
        final Location loc = event.getRespawnLocation();
        data.teleportQueue.onTeleportEvent(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
    }
}
Also used : Player(org.bukkit.entity.Player) NetData(fr.neatmonster.nocheatplus.checks.net.NetData) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 4 with NetData

use of fr.neatmonster.nocheatplus.checks.net.NetData 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 5 with NetData

use of fr.neatmonster.nocheatplus.checks.net.NetData 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)

Aggregations

NetData (fr.neatmonster.nocheatplus.checks.net.NetData)7 Player (org.bukkit.entity.Player)7 IPlayerData (fr.neatmonster.nocheatplus.players.IPlayerData)6 NetConfig (fr.neatmonster.nocheatplus.checks.net.NetConfig)4 PacketContainer (com.comphenix.protocol.events.PacketContainer)2 Location (org.bukkit.Location)2 EventHandler (org.bukkit.event.EventHandler)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 AlmostBoolean (fr.neatmonster.nocheatplus.compat.AlmostBoolean)1 IWorldData (fr.neatmonster.nocheatplus.worlds.IWorldData)1