From 9339ccc0ef4f5a13ab41474d8f971cc353bfcd2b Mon Sep 17 00:00:00 2001 From: asofold Date: Wed, 26 Apr 2017 14:27:22 +0200 Subject: [PATCH] Error log the interpreted packet types (simplified). --- .../checks/net/protocollib/MovingFlying.java | 21 ++++++++++++++++--- .../checks/net/model/DataPacketFlying.java | 21 +++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/checks/net/protocollib/MovingFlying.java b/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/checks/net/protocollib/MovingFlying.java index e3adc5a1..7f3f53e8 100644 --- a/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/checks/net/protocollib/MovingFlying.java +++ b/NCPCompatProtocolLib/src/main/java/fr/neatmonster/nocheatplus/checks/net/protocollib/MovingFlying.java @@ -15,6 +15,8 @@ package fr.neatmonster.nocheatplus.checks.net.protocollib; import java.util.Arrays; +import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import org.bukkit.entity.Player; @@ -30,11 +32,13 @@ import fr.neatmonster.nocheatplus.checks.net.FlyingFrequency; import fr.neatmonster.nocheatplus.checks.net.NetConfig; import fr.neatmonster.nocheatplus.checks.net.NetData; import fr.neatmonster.nocheatplus.checks.net.model.DataPacketFlying; +import fr.neatmonster.nocheatplus.checks.net.model.DataPacketFlying.PACKET_CONTENT; import fr.neatmonster.nocheatplus.config.ConfPaths; import fr.neatmonster.nocheatplus.config.ConfigManager; import fr.neatmonster.nocheatplus.logging.Streams; import fr.neatmonster.nocheatplus.time.monotonic.Monotonic; import fr.neatmonster.nocheatplus.utilities.CheckUtils; +import fr.neatmonster.nocheatplus.utilities.StringUtil; import fr.neatmonster.nocheatplus.utilities.location.LocUtil; /** @@ -70,6 +74,8 @@ public class MovingFlying extends BaseAdapter { */ private long packetMismatch = Long.MIN_VALUE; private long packetMismatchLogFrequency = 60000; // Every minute max, good for updating :). + + private final HashSet validContent = new LinkedHashSet(); public MovingFlying(Plugin plugin) { // PacketPlayInFlying[3, legacy: 10] @@ -149,6 +155,8 @@ public class MovingFlying extends BaseAdapter { data.addFlyingQueue(packetData); // TODO: Not the optimal position, perhaps. } } + // Add as valid packet (exclude invalid coordinates etc. for now). + validContent.add(packetData.getSimplifiedContentType()); } // TODO: Counters for hasPos, hasLook, both, none. @@ -260,9 +268,16 @@ public class MovingFlying extends BaseAdapter { final long time = Monotonic.synchMillis(); if (time - packetMismatchLogFrequency > packetMismatch) { packetMismatch = time; - NCPAPIProvider.getNoCheatPlusAPI().getLogManager().warning(Streams.STATUS, - CheckUtils.getLogMessagePrefix(packetEvent.getPlayer(), checkType) - + "Incoming packet could not be interpreted. Are server and plugins up to date (NCP/ProtocolLib...)? This message is logged every " + (packetMismatchLogFrequency / 1000) + " seconds, disregarding for which player this happens."); + StringBuilder builder = new StringBuilder(512); + builder.append(CheckUtils.getLogMessagePrefix(packetEvent.getPlayer(), checkType)); + builder.append("Incoming packet could not be interpreted. Are server and plugins up to date (NCP/ProtocolLib...)? This message is logged every "); + builder.append(Long.toString(packetMismatch / 1000)); + builder.append(" seconds, disregarding for which player this happens."); + if (!validContent.isEmpty()) { + builder.append(" On other occasion, valid content was received for: "); + StringUtil.join(validContent, ", ", builder); + } + NCPAPIProvider.getNoCheatPlusAPI().getLogManager().warning(Streams.STATUS, builder.toString()); } } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/net/model/DataPacketFlying.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/net/model/DataPacketFlying.java index fde45010..655c2b65 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/net/model/DataPacketFlying.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/net/model/DataPacketFlying.java @@ -16,6 +16,22 @@ package fr.neatmonster.nocheatplus.checks.net.model; public class DataPacketFlying extends DataLocation { + /** + * Simplified packet content type. + * @author asofold + * + */ + public static enum PACKET_CONTENT { + /** Neither position nor look, only ground. */ + GROUND_ONLY, + /** Position and ground. */ + POS, + /** Look and ground. */ + LOOK, + /** Position, look and ground. */ + POS_LOOK; + } + // TODO: Use MAX_VALUE for not set doubles/floats? // TODO: Consider private + access methods. // TODO: Consider AlmostBoolean for fault tolerance ? @@ -132,4 +148,9 @@ public class DataPacketFlying extends DataLocation { this.sequence = sequence; } + public PACKET_CONTENT getSimplifiedContentType() { + return hasPos ? (hasLook ? PACKET_CONTENT.POS_LOOK : PACKET_CONTENT.POS) + : (hasLook ? PACKET_CONTENT.LOOK : PACKET_CONTENT.GROUND_ONLY); + } + }