diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index 570c3da3..c9b093de 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -443,7 +443,7 @@ namespace MinecraftClient.Protocol.Handlers if (packetData.Count == 0) { var rawHex = rawBytes.Length > 0 ? BitConverter.ToString(rawBytes).Replace("-", " ") : "(empty)"; - log.Warn($"[DEBUG] Empty packet after decompress: size={size}, sizeUncompressed={sizeUncompressed}, protocol={protocolVersion}, state={currentState}, rawBytes=[{rawHex}]"); + log.Debug("Empty packet after decompress: size={0}, sizeUncompressed={1}, protocol={2}, state={3}, rawBytes=[{4}]", size, sizeUncompressed, protocolVersion, currentState, rawHex); return new(-1, packetData); } @@ -4158,12 +4158,21 @@ namespace MinecraftClient.Protocol.Handlers log.PacketDebug(string.Format(Translations.debug_packet_state_change, previousState, newState)); } + private static bool IsPacketExcluded(string packetType) + { + var exclusions = Settings.Config.Logging.PacketDebugExclusions; + return exclusions.Count > 0 && exclusions.Contains(packetType, StringComparer.OrdinalIgnoreCase); + } + private void LogIncomingPacket(int packetId, int payloadLength, int frameLength, bool compressed, int uncompressedLength) { if (!log.DebugEnabled) return; var packetType = ResolveIncomingPacketType(packetId); + if (IsPacketExcluded(packetType)) + return; + var compressionInfo = compression_treshold < 0 ? Translations.debug_packet_compression_disabled : compressed @@ -4184,10 +4193,14 @@ namespace MinecraftClient.Protocol.Handlers if (!log.DebugEnabled) return; + var resolvedType = packetType ?? ResolveOutgoingPacketType(packetId); + if (IsPacketExcluded(resolvedType)) + return; + log.PacketDebug(string.Format(Translations.debug_packet_outgoing, currentState, packetId, - packetType ?? ResolveOutgoingPacketType(packetId), + resolvedType, payloadLength, compression_treshold)); } diff --git a/MinecraftClient/Resources/ConfigComments/ConfigComments.Designer.cs b/MinecraftClient/Resources/ConfigComments/ConfigComments.Designer.cs index 4a0cc7fd..cdd5d4b1 100644 --- a/MinecraftClient/Resources/ConfigComments/ConfigComments.Designer.cs +++ b/MinecraftClient/Resources/ConfigComments/ConfigComments.Designer.cs @@ -1541,6 +1541,15 @@ namespace MinecraftClient { } } + /// + /// Looks up a localized string similar to Packet types to exclude from packet debug logs, e.g. ["KeepAlive", "Ping"].. + /// + internal static string Logging_PacketDebugExclusions { + get { + return ResourceManager.GetString("Logging.PacketDebugExclusions", resourceCulture); + } + } + /// /// Looks up a localized string similar to Show error messages.. /// diff --git a/MinecraftClient/Resources/ConfigComments/ConfigComments.resx b/MinecraftClient/Resources/ConfigComments/ConfigComments.resx index 5515ae24..d1ebbcb2 100644 --- a/MinecraftClient/Resources/ConfigComments/ConfigComments.resx +++ b/MinecraftClient/Resources/ConfigComments/ConfigComments.resx @@ -629,6 +629,9 @@ Want to upgrade to a newer version? See https://github.com/MCCTeam/Minecraft-Con Show low-level packet debug logs. + + Packet types to exclude from packet debug logs, e.g. ["KeepAlive", "Ping"]. + Show error messages. diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index 06a3837c..a5ce88af 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -1080,6 +1080,9 @@ namespace MinecraftClient [TomlInlineComment("$Logging.PacketDebugMessages$")] public bool PacketDebugMessages = false; + [TomlInlineComment("$Logging.PacketDebugExclusions$")] + public List PacketDebugExclusions = new(); + [TomlInlineComment("$Logging.ChatMessages$")] public bool ChatMessages = true;