Gate empty-packet log under debug, add packet exclusion list

- Change empty packet log from log.Warn to log.Debug so it only
  shows when DebugMessages is enabled
- Add PacketDebugExclusions config (List<string>) to suppress
  specific packet types like KeepAlive, Ping from packet debug output
- Check exclusion in both LogIncomingPacket and LogOutgoingPacket
- Add ConfigComments resource entry for the new setting
This commit is contained in:
Anon 2026-06-11 22:03:36 +02:00
parent 28e845d1ca
commit 98dfde6cc2
4 changed files with 30 additions and 2 deletions

View file

@ -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));
}

View file

@ -1541,6 +1541,15 @@ namespace MinecraftClient {
}
}
/// <summary>
/// Looks up a localized string similar to Packet types to exclude from packet debug logs, e.g. [&quot;KeepAlive&quot;, &quot;Ping&quot;]..
/// </summary>
internal static string Logging_PacketDebugExclusions {
get {
return ResourceManager.GetString("Logging.PacketDebugExclusions", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Show error messages..
/// </summary>

View file

@ -629,6 +629,9 @@ Want to upgrade to a newer version? See https://github.com/MCCTeam/Minecraft-Con
<data name="Logging.PacketDebugMessages" xml:space="preserve">
<value>Show low-level packet debug logs.</value>
</data>
<data name="Logging.PacketDebugExclusions" xml:space="preserve">
<value>Packet types to exclude from packet debug logs, e.g. ["KeepAlive", "Ping"].</value>
</data>
<data name="Logging.ErrorMessages" xml:space="preserve">
<value>Show error messages.</value>
</data>

View file

@ -1080,6 +1080,9 @@ namespace MinecraftClient
[TomlInlineComment("$Logging.PacketDebugMessages$")]
public bool PacketDebugMessages = false;
[TomlInlineComment("$Logging.PacketDebugExclusions$")]
public List<string> PacketDebugExclusions = new();
[TomlInlineComment("$Logging.ChatMessages$")]
public bool ChatMessages = true;