Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Reousa committed Dec 22, 2023
1 parent 6c5d18a commit 934810c
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions NebulaModel/Networking/Serialization/NetPacketProcessorExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
using System.Collections.Generic;
using System.Diagnostics;
using NebulaAPI.Interfaces;
using NebulaAPI.Packets;
using NebulaModel.Logger;

namespace NebulaModel.Networking.Serialization;

public partial class NetPacketProcessor
{
// Packet simulation stuff
private readonly Dictionary<ulong, Type> _callbacksDebugInfo = [];
private readonly NetDataWriter _netDataWriter = new();
private readonly NetDataWriter writer = new();
private readonly List<DelayedPacket> delayedPackets = [];
private readonly Queue<PendingPacket> pendingPackets = new();

Expand All @@ -24,11 +26,6 @@ public partial class NetPacketProcessor
/// </summary>
public bool Enable { get; set; } = true;

/// <summary>
///
/// </summary>
private static readonly NetDataWriter writer = new();

/// <summary>
/// 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.
Expand All @@ -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();
}

Expand All @@ -64,7 +69,7 @@ private void ProcessDelayedPackets()
{
var now = DateTime.UtcNow;
var deleteCount = 0;

Check warning on line 72 in NebulaModel/Networking/Serialization/NetPacketProcessorExtension.cs

View workflow job for this annotation

GitHub Actions / build (Debug)

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check warning on line 72 in NebulaModel/Networking/Serialization/NetPacketProcessorExtension.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
for (var i = 0; i < delayedPackets.Count; ++i)
{
if (now >= delayedPackets[i].DueTime)
Expand All @@ -78,7 +83,7 @@ private void ProcessDelayedPackets()
break;
}
}

Check warning on line 86 in NebulaModel/Networking/Serialization/NetPacketProcessorExtension.cs

View workflow job for this annotation

GitHub Actions / build (Debug)

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check warning on line 86 in NebulaModel/Networking/Serialization/NetPacketProcessorExtension.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
if (deleteCount > 0)
{
delayedPackets.RemoveRange(0, deleteCount);
Expand Down Expand Up @@ -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
{
}
}

0 comments on commit 934810c

Please sign in to comment.