feat: client & server packet listener interfaces added
This commit is contained in:
@@ -8,7 +8,7 @@ public class LiteNetLibClient : LiteNetLibCommunicatorBase, INetworkCommunicator
|
||||
|
||||
public INetworkCommunicatorClient Connect(string address, int port, string? password = null)
|
||||
{
|
||||
if (!IsInUniverse)
|
||||
if (!UniverseObject.IsInUniverse)
|
||||
throw new($"{nameof(LiteNetLibClient)} must be in an universe to connect");
|
||||
|
||||
Manager.Start();
|
||||
|
@@ -10,7 +10,7 @@ using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.Network;
|
||||
|
||||
public abstract class LiteNetLibCommunicatorBase : UniverseObject, INetworkCommunicator
|
||||
public abstract class LiteNetLibCommunicatorBase : Behaviour, INetworkCommunicator
|
||||
{
|
||||
protected readonly NetPacketProcessor netPacketProcessor = new();
|
||||
|
||||
@@ -25,12 +25,12 @@ public abstract class LiteNetLibCommunicatorBase : UniverseObject, INetworkCommu
|
||||
return this;
|
||||
}
|
||||
|
||||
protected override void OnEnteringUniverse(IUniverse universe)
|
||||
protected override void OnEnteredUniverse(IUniverse universe)
|
||||
{
|
||||
universe.OnPreUpdate += PollEvents;
|
||||
}
|
||||
|
||||
protected override void OnExitingUniverse(IUniverse universe)
|
||||
protected override void OnExitedUniverse(IUniverse universe)
|
||||
{
|
||||
universe.OnPreUpdate -= PollEvents;
|
||||
|
||||
@@ -82,13 +82,11 @@ public abstract class LiteNetLibCommunicatorBase : UniverseObject, INetworkCommu
|
||||
{
|
||||
if (!packetType.IsClass)
|
||||
{
|
||||
Console.WriteLine($"Registering Nested: {packetType.FullName}");
|
||||
MethodInfo genericRegisterNestedTypeMethod = registerNestedTypeMethod.MakeGenericMethod(packetType);
|
||||
genericRegisterNestedTypeMethod.Invoke(netPacketProcessor, []);
|
||||
continue;
|
||||
}
|
||||
|
||||
Console.WriteLine($"Registering Reusable: {packetType.FullName}");
|
||||
MethodInfo genericOnPacketArrivedMethod = onPacketArrivedMethod.MakeGenericMethod(packetType);
|
||||
|
||||
Type delegateType = typeof(Action<,>).MakeGenericType(packetType, typeof(NetPeer));
|
||||
@@ -131,7 +129,6 @@ public abstract class LiteNetLibCommunicatorBase : UniverseObject, INetworkCommu
|
||||
public INetworkCommunicator SubscribeToPackets<T>(Action<T, string> callback)
|
||||
{
|
||||
Type type = typeof(T);
|
||||
Console.WriteLine($"Subscribing to: {type.FullName} on {GetType().Name}");
|
||||
if (!listeners.TryGetValue(type, out List<Delegate>? delegates))
|
||||
{
|
||||
delegates = [];
|
||||
@@ -145,7 +142,6 @@ public abstract class LiteNetLibCommunicatorBase : UniverseObject, INetworkCommu
|
||||
public INetworkCommunicator UnsubscribeFromPackets<T>(Action<T, string> callback)
|
||||
{
|
||||
Type type = typeof(T);
|
||||
Console.WriteLine($"Unsubscribing from: {type.FullName} on {GetType().Name}");
|
||||
if (!listeners.TryGetValue(type, out List<Delegate>? delegates))
|
||||
return this;
|
||||
|
||||
|
@@ -30,7 +30,7 @@ public class LiteNetLibServer : LiteNetLibCommunicatorBase, INetworkCommunicator
|
||||
|
||||
public INetworkCommunicatorServer Start(int port, int maxConnectionCount, string? password = null)
|
||||
{
|
||||
if (!IsInUniverse)
|
||||
if (!UniverseObject.IsInUniverse)
|
||||
throw new($"{nameof(LiteNetLibServer)} must be in an universe to start");
|
||||
|
||||
Password = password ?? string.Empty;
|
||||
|
Reference in New Issue
Block a user