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);
}
}
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);
}
}
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());
}
}
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);
}
}
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);
}
}
}
Aggregations