Skip to content

Commit b73d55d

Browse files
authored
Feature packet log (#1038)
* Created the network debugger for incomming and outgoing packets * Sorted count of packets * Cleaned up code
1 parent 7457b22 commit b73d55d

14 files changed

+290
-36
lines changed

NitroxClient/ClientAutoFacRegistrar.cs

+24-16
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using NitroxClient.Communication.MultiplayerSession;
77
using NitroxClient.Communication.NetworkingLayer.LiteNetLib;
88
using NitroxClient.Communication.Packets.Processors.Abstract;
9+
using NitroxClient.Debuggers;
910
using NitroxClient.GameLogic;
1011
using NitroxClient.GameLogic.Bases;
1112
using NitroxClient.GameLogic.ChatUI;
@@ -24,6 +25,7 @@ namespace NitroxClient
2425
{
2526
public class ClientAutoFacRegistrar : IAutoFacRegistrar
2627
{
28+
private static readonly Assembly currentAssembly = Assembly.GetExecutingAssembly();
2729
private readonly IModule[] modules;
2830

2931
public ClientAutoFacRegistrar(params IModule[] modules)
@@ -46,31 +48,37 @@ public void RegisterDependencies(ContainerBuilder containerBuilder)
4648

4749
private static void RegisterCoreDependencies(ContainerBuilder containerBuilder)
4850
{
49-
containerBuilder.Register(c => new NitroxProtobufSerializer("NitroxModel.dll"));
51+
containerBuilder.RegisterAssemblyTypes(currentAssembly)
52+
.AssignableTo<BaseDebugger>()
53+
.As<BaseDebugger>()
54+
.AsSelf()
55+
.SingleInstance();
5056

57+
containerBuilder.Register(c => new NitroxProtobufSerializer($"{nameof(NitroxModel)}.dll"));
58+
5159
containerBuilder.RegisterType<UnityPreferenceStateProvider>()
52-
.As<IPreferenceStateProvider>()
53-
.SingleInstance();
60+
.As<IPreferenceStateProvider>()
61+
.SingleInstance();
5462

5563
containerBuilder.RegisterType<PlayerPreferenceManager>().SingleInstance();
5664

5765
containerBuilder.RegisterType<MultiplayerSessionManager>()
58-
.As<IMultiplayerSession>()
59-
.As<IPacketSender>()
60-
.InstancePerLifetimeScope();
66+
.As<IMultiplayerSession>()
67+
.As<IPacketSender>()
68+
.InstancePerLifetimeScope();
6169

6270
containerBuilder.RegisterType<LiteNetLibClient>()
63-
.As<IClient>()
64-
.InstancePerLifetimeScope();
71+
.As<IClient>()
72+
.InstancePerLifetimeScope();
6573

6674
containerBuilder.RegisterType<LocalPlayer>()
67-
.AsSelf() //Would like to deprecate this registration at some point and just work through an abstraction.
68-
.As<ILocalNitroxPlayer>()
69-
.InstancePerLifetimeScope();
75+
.AsSelf() //Would like to deprecate this registration at some point and just work through an abstraction.
76+
.As<ILocalNitroxPlayer>()
77+
.InstancePerLifetimeScope();
7078

7179
containerBuilder.RegisterType<SubnauticaRotationMetadataFactory>()
72-
.As<RotationMetadataFactory>()
73-
.InstancePerLifetimeScope();
80+
.As<RotationMetadataFactory>()
81+
.InstancePerLifetimeScope();
7482

7583
containerBuilder.RegisterType<PlayerManager>().InstancePerLifetimeScope();
7684
containerBuilder.RegisterType<PlayerModelManager>().InstancePerLifetimeScope();
@@ -109,15 +117,15 @@ private static void RegisterCoreDependencies(ContainerBuilder containerBuilder)
109117
private void RegisterPacketProcessors(ContainerBuilder containerBuilder)
110118
{
111119
containerBuilder
112-
.RegisterAssemblyTypes(Assembly.GetAssembly(GetType()))
120+
.RegisterAssemblyTypes(currentAssembly)
113121
.AsClosedTypesOf(typeof(ClientPacketProcessor<>))
114122
.InstancePerLifetimeScope();
115123
}
116124

117125
private void RegisterColorSwapManagers(ContainerBuilder containerBuilder)
118126
{
119127
containerBuilder
120-
.RegisterAssemblyTypes(Assembly.GetAssembly(GetType()))
128+
.RegisterAssemblyTypes(currentAssembly)
121129
.AssignableTo<IColorSwapManager>()
122130
.As<IColorSwapManager>()
123131
.InstancePerLifetimeScope();
@@ -126,7 +134,7 @@ private void RegisterColorSwapManagers(ContainerBuilder containerBuilder)
126134
private void RegisterInitialSyncProcessors(ContainerBuilder containerBuilder)
127135
{
128136
containerBuilder
129-
.RegisterAssemblyTypes(Assembly.GetAssembly(GetType()))
137+
.RegisterAssemblyTypes(currentAssembly)
130138
.AssignableTo<InitialSyncProcessor>()
131139
.As<InitialSyncProcessor>()
132140
.InstancePerLifetimeScope();

NitroxClient/Communication/MultiplayerSession/MultiplayerSessionManager.cs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using NitroxClient.Communication.Abstract;
44
using NitroxClient.Communication.MultiplayerSession.ConnectionState;
5+
using NitroxClient.Debuggers;
56
using NitroxClient.GameLogic;
67
using NitroxModel;
78
using NitroxModel.Helper;

NitroxClient/Communication/NetworkingLayer/LiteNetLib/LiteNetLibClient.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using LiteNetLib;
33
using LiteNetLib.Utils;
44
using NitroxClient.Communication.Abstract;
5+
using NitroxClient.Debuggers;
56
using NitroxClient.MonoBehaviours.Gui.InGame;
67
using NitroxModel.Core;
78
using NitroxModel.Logger;
@@ -15,14 +16,16 @@ public class LiteNetLibClient : IClient
1516
public bool IsConnected { get; private set; }
1617

1718
private readonly NetPacketProcessor netPacketProcessor = new NetPacketProcessor();
18-
private AutoResetEvent connectedEvent = new AutoResetEvent(false);
19+
private readonly AutoResetEvent connectedEvent = new AutoResetEvent(false);
1920
private readonly PacketReceiver packetReceiver;
21+
private readonly NetworkDebugger networkDebugger;
2022

2123
private NetManager client;
2224

23-
public LiteNetLibClient()
25+
public LiteNetLibClient(PacketReceiver packetReceiver, NetworkDebugger networkDebugger)
2426
{
25-
packetReceiver = NitroxServiceLocator.LocateService<PacketReceiver>();
27+
this.packetReceiver = packetReceiver;
28+
this.networkDebugger = networkDebugger;
2629
}
2730

2831
public void Start(string ipAddress, int serverPort)
@@ -50,6 +53,7 @@ public void Start(string ipAddress, int serverPort)
5053

5154
public void Send(Packet packet)
5255
{
56+
networkDebugger?.PacketSent(packet);
5357
client.SendToAll(netPacketProcessor.Write(packet.ToWrapperPacket()), NitroxDeliveryMethod.ToLiteNetLib(packet.DeliveryMethod));
5458
client.Flush();
5559
}

NitroxClient/Communication/PacketReceiver.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
using System.Collections.Generic;
2+
using NitroxClient.Debuggers;
23
using NitroxModel.Packets;
34

45
namespace NitroxClient.Communication
56
{
67
// TODO: Spinlocks don't seem to be necessary here, but I don't know for certain.
78
public class PacketReceiver
89
{
10+
private readonly NetworkDebugger networkDebugger;
911
private readonly Queue<Packet> receivedPackets;
1012

11-
public PacketReceiver()
13+
public PacketReceiver(NetworkDebugger networkDebugger = null)
1214
{
1315
receivedPackets = new Queue<Packet>();
16+
this.networkDebugger = networkDebugger;
1417
}
1518

1619
public void PacketReceived(Packet packet)
1720
{
1821
lock (receivedPackets)
1922
{
23+
networkDebugger?.PacketReceived(packet);
2024
receivedPackets.Enqueue(packet);
2125
}
2226
}

0 commit comments

Comments
 (0)