Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature packet log #1038

Merged
merged 5 commits into from
Apr 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions NitroxClient/ClientAutoFacRegistrar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using NitroxClient.Communication.MultiplayerSession;
using NitroxClient.Communication.NetworkingLayer.LiteNetLib;
using NitroxClient.Communication.Packets.Processors.Abstract;
using NitroxClient.Debuggers;
using NitroxClient.GameLogic;
using NitroxClient.GameLogic.Bases;
using NitroxClient.GameLogic.ChatUI;
Expand All @@ -24,6 +25,7 @@ namespace NitroxClient
{
public class ClientAutoFacRegistrar : IAutoFacRegistrar
{
private static readonly Assembly currentAssembly = Assembly.GetExecutingAssembly();
private readonly IModule[] modules;

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

private static void RegisterCoreDependencies(ContainerBuilder containerBuilder)
{
containerBuilder.Register(c => new NitroxProtobufSerializer("NitroxModel.dll"));
containerBuilder.RegisterAssemblyTypes(currentAssembly)
.AssignableTo<BaseDebugger>()
.As<BaseDebugger>()
.AsSelf()
.SingleInstance();

containerBuilder.Register(c => new NitroxProtobufSerializer($"{nameof(NitroxModel)}.dll"));

containerBuilder.RegisterType<UnityPreferenceStateProvider>()
.As<IPreferenceStateProvider>()
.SingleInstance();
.As<IPreferenceStateProvider>()
.SingleInstance();

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

containerBuilder.RegisterType<MultiplayerSessionManager>()
.As<IMultiplayerSession>()
.As<IPacketSender>()
.InstancePerLifetimeScope();
.As<IMultiplayerSession>()
.As<IPacketSender>()
.InstancePerLifetimeScope();

containerBuilder.RegisterType<LiteNetLibClient>()
.As<IClient>()
.InstancePerLifetimeScope();
.As<IClient>()
.InstancePerLifetimeScope();

containerBuilder.RegisterType<LocalPlayer>()
.AsSelf() //Would like to deprecate this registration at some point and just work through an abstraction.
.As<ILocalNitroxPlayer>()
.InstancePerLifetimeScope();
.AsSelf() //Would like to deprecate this registration at some point and just work through an abstraction.
.As<ILocalNitroxPlayer>()
.InstancePerLifetimeScope();

containerBuilder.RegisterType<SubnauticaRotationMetadataFactory>()
.As<RotationMetadataFactory>()
.InstancePerLifetimeScope();
.As<RotationMetadataFactory>()
.InstancePerLifetimeScope();

containerBuilder.RegisterType<PlayerManager>().InstancePerLifetimeScope();
containerBuilder.RegisterType<PlayerModelManager>().InstancePerLifetimeScope();
Expand Down Expand Up @@ -109,15 +117,15 @@ private static void RegisterCoreDependencies(ContainerBuilder containerBuilder)
private void RegisterPacketProcessors(ContainerBuilder containerBuilder)
{
containerBuilder
.RegisterAssemblyTypes(Assembly.GetAssembly(GetType()))
.RegisterAssemblyTypes(currentAssembly)
.AsClosedTypesOf(typeof(ClientPacketProcessor<>))
.InstancePerLifetimeScope();
}

private void RegisterColorSwapManagers(ContainerBuilder containerBuilder)
{
containerBuilder
.RegisterAssemblyTypes(Assembly.GetAssembly(GetType()))
.RegisterAssemblyTypes(currentAssembly)
.AssignableTo<IColorSwapManager>()
.As<IColorSwapManager>()
.InstancePerLifetimeScope();
Expand All @@ -126,7 +134,7 @@ private void RegisterColorSwapManagers(ContainerBuilder containerBuilder)
private void RegisterInitialSyncProcessors(ContainerBuilder containerBuilder)
{
containerBuilder
.RegisterAssemblyTypes(Assembly.GetAssembly(GetType()))
.RegisterAssemblyTypes(currentAssembly)
.AssignableTo<InitialSyncProcessor>()
.As<InitialSyncProcessor>()
.InstancePerLifetimeScope();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using NitroxClient.Communication.Abstract;
using NitroxClient.Communication.MultiplayerSession.ConnectionState;
using NitroxClient.Debuggers;
using NitroxClient.GameLogic;
using NitroxModel;
using NitroxModel.Helper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using LiteNetLib;
using LiteNetLib.Utils;
using NitroxClient.Communication.Abstract;
using NitroxClient.Debuggers;
using NitroxClient.MonoBehaviours.Gui.InGame;
using NitroxModel.Core;
using NitroxModel.Logger;
Expand All @@ -15,14 +16,16 @@ public class LiteNetLibClient : IClient
public bool IsConnected { get; private set; }

private readonly NetPacketProcessor netPacketProcessor = new NetPacketProcessor();
private AutoResetEvent connectedEvent = new AutoResetEvent(false);
private readonly AutoResetEvent connectedEvent = new AutoResetEvent(false);
private readonly PacketReceiver packetReceiver;
private readonly NetworkDebugger networkDebugger;

private NetManager client;

public LiteNetLibClient()
public LiteNetLibClient(PacketReceiver packetReceiver, NetworkDebugger networkDebugger)
{
packetReceiver = NitroxServiceLocator.LocateService<PacketReceiver>();
this.packetReceiver = packetReceiver;
this.networkDebugger = networkDebugger;
}

public void Start(string ipAddress, int serverPort)
Expand Down Expand Up @@ -50,6 +53,7 @@ public void Start(string ipAddress, int serverPort)

public void Send(Packet packet)
{
networkDebugger?.PacketSent(packet);
client.SendToAll(netPacketProcessor.Write(packet.ToWrapperPacket()), NitroxDeliveryMethod.ToLiteNetLib(packet.DeliveryMethod));
client.Flush();
}
Expand Down
6 changes: 5 additions & 1 deletion NitroxClient/Communication/PacketReceiver.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
using System.Collections.Generic;
using NitroxClient.Debuggers;
using NitroxModel.Packets;

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

public PacketReceiver()
public PacketReceiver(NetworkDebugger networkDebugger = null)
{
receivedPackets = new Queue<Packet>();
this.networkDebugger = networkDebugger;
}

public void PacketReceived(Packet packet)
{
lock (receivedPackets)
{
networkDebugger?.PacketReceived(packet);
receivedPackets.Enqueue(packet);
}
}
Expand Down
Loading