diff --git a/NebulaModel/Networking/Serialization/NetPacketProcessorExtension.cs b/NebulaModel/Networking/Serialization/NetPacketProcessorExtension.cs index f95b66736..3ba304505 100644 --- a/NebulaModel/Networking/Serialization/NetPacketProcessorExtension.cs +++ b/NebulaModel/Networking/Serialization/NetPacketProcessorExtension.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Diagnostics; using NebulaAPI.Interfaces; +using NebulaAPI.Packets; +using NebulaModel.Logger; namespace NebulaModel.Networking.Serialization; @@ -9,7 +11,7 @@ public partial class NetPacketProcessor { // Packet simulation stuff private readonly Dictionary _callbacksDebugInfo = []; - private readonly NetDataWriter _netDataWriter = new(); + private readonly NetDataWriter writer = new(); private readonly List delayedPackets = []; private readonly Queue pendingPackets = new(); @@ -24,11 +26,6 @@ public partial class NetPacketProcessor /// public bool Enable { get; set; } = true; - /// - /// - /// - private static readonly NetDataWriter writer = new(); - /// /// Adds back some functionality that nebula relied on before the update. /// This method was removed from LiteNetLib as it was not thread-safe, and is still not thread safe in below implementation. @@ -38,6 +35,14 @@ public partial class NetPacketProcessor { writer.Reset(); Write(writer, packet); + +#if DEBUG + if (!typeof(T).IsDefined(typeof(HidePacketInDebugLogsAttribute), false)) + { + Log.Debug($"Packet Sent: {packet.GetType().Name}, Size: {writer.Data.Length}"); + } +#endif + return writer.CopyData(); } @@ -64,7 +69,7 @@ private void ProcessDelayedPackets() { var now = DateTime.UtcNow; var deleteCount = 0; - + for (var i = 0; i < delayedPackets.Count; ++i) { if (now >= delayedPackets[i].DueTime) @@ -78,7 +83,7 @@ private void ProcessDelayedPackets() break; } } - + if (deleteCount > 0) { delayedPackets.RemoveRange(0, deleteCount); @@ -109,13 +114,10 @@ public void EnqueuePacketForProcessing(byte[] rawData, object userData) lock (pendingPackets) { pendingPackets.Enqueue(new PendingPacket(rawData, userData)); + Log.Info($"Received packet of size: {rawData.Length}"); } #endif } #endregion -} - -public static class NetPacketProcessorExtension -{ -} +} \ No newline at end of file