feat: added networking system
This commit is contained in:
12
Engine.Systems/Network/Abstract/IConnection.cs
Normal file
12
Engine.Systems/Network/Abstract/IConnection.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace Syntriax.Engine.Systems.Network;
|
||||
|
||||
public interface IConnection
|
||||
{
|
||||
string Id { get; }
|
||||
|
||||
float Ping { get; }
|
||||
float RoundTrip { get; }
|
||||
|
||||
int PingMs { get; }
|
||||
int RoundTripMs { get; }
|
||||
}
|
6
Engine.Systems/Network/Abstract/IEntityNetworkPacket.cs
Normal file
6
Engine.Systems/Network/Abstract/IEntityNetworkPacket.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Syntriax.Engine.Systems.Network;
|
||||
|
||||
public interface IEntityNetworkPacket : INetworkPacket
|
||||
{
|
||||
string EntityId { get; }
|
||||
}
|
37
Engine.Systems/Network/Abstract/INetworkCommunicator.cs
Normal file
37
Engine.Systems/Network/Abstract/INetworkCommunicator.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.Systems.Network;
|
||||
|
||||
public interface INetworkCommunicator
|
||||
{
|
||||
Event<INetworkCommunicator, IConnection> OnConnectionEstablished { get; }
|
||||
Event<INetworkCommunicator, IConnection> OnConnectionAbolished { get; }
|
||||
|
||||
IReadOnlyDictionary<string, IConnection> Connections { get; }
|
||||
|
||||
INetworkCommunicator Stop();
|
||||
|
||||
INetworkCommunicator SubscribeToPackets<T>(Event<IConnection, T>.EventHandler callback);
|
||||
INetworkCommunicator UnsubscribeFromPackets<T>(Event<IConnection, T>.EventHandler callback);
|
||||
}
|
||||
|
||||
public interface INetworkCommunicatorClient : INetworkCommunicator
|
||||
{
|
||||
INetworkCommunicatorClient Connect(string address, int port, string? password = null);
|
||||
|
||||
INetworkCommunicatorClient SendToServer<T>(T packet, PacketDelivery packetDelivery = PacketDelivery.ReliableInOrder) where T : class, new();
|
||||
}
|
||||
|
||||
public interface INetworkCommunicatorServer : INetworkCommunicator
|
||||
{
|
||||
string Password { get; }
|
||||
int MaxConnectionCount { get; }
|
||||
int Port { get; }
|
||||
|
||||
INetworkCommunicatorServer Start(int port, int maxConnectionCount, string? password = null);
|
||||
|
||||
INetworkCommunicatorServer SendToClient<T>(IConnection connection, T packet, PacketDelivery packetDelivery = PacketDelivery.ReliableInOrder) where T : class, new();
|
||||
INetworkCommunicatorServer SendToAll<T>(T packet, PacketDelivery packetDelivery = PacketDelivery.ReliableInOrder) where T : class, new();
|
||||
}
|
5
Engine.Systems/Network/Abstract/INetworkEntity.cs
Normal file
5
Engine.Systems/Network/Abstract/INetworkEntity.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.Systems.Network;
|
||||
|
||||
public interface INetworkEntity : IEntity;
|
11
Engine.Systems/Network/Abstract/INetworkManager.cs
Normal file
11
Engine.Systems/Network/Abstract/INetworkManager.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.Systems.Network;
|
||||
|
||||
public interface INetworkManager
|
||||
{
|
||||
IReadOnlyDictionary<string, INetworkEntity> NetworkEntities { get; }
|
||||
IBehaviourCollector<INetworkEntity> NetworkEntityCollector { get; }
|
||||
}
|
3
Engine.Systems/Network/Abstract/INetworkPacket.cs
Normal file
3
Engine.Systems/Network/Abstract/INetworkPacket.cs
Normal file
@@ -0,0 +1,3 @@
|
||||
namespace Syntriax.Engine.Systems.Network;
|
||||
|
||||
public interface INetworkPacket;
|
6
Engine.Systems/Network/Abstract/IPacketListenerClient.cs
Normal file
6
Engine.Systems/Network/Abstract/IPacketListenerClient.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Syntriax.Engine.Systems.Network;
|
||||
|
||||
public interface IPacketListenerClient<T> : INetworkEntity
|
||||
{
|
||||
void OnClientPacketArrived(IConnection sender, T packet);
|
||||
}
|
6
Engine.Systems/Network/Abstract/IPacketListenerServer.cs
Normal file
6
Engine.Systems/Network/Abstract/IPacketListenerServer.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Syntriax.Engine.Systems.Network;
|
||||
|
||||
public interface IPacketListenerServer<T> : INetworkEntity
|
||||
{
|
||||
void OnServerPacketArrived(IConnection sender, T packet);
|
||||
}
|
9
Engine.Systems/Network/Abstract/PacketDelivery.cs
Normal file
9
Engine.Systems/Network/Abstract/PacketDelivery.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Syntriax.Engine.Systems.Network;
|
||||
|
||||
public enum PacketDelivery
|
||||
{
|
||||
ReliableInOrder,
|
||||
ReliableOutOfOrder,
|
||||
UnreliableInOrder,
|
||||
UnreliableOutOfOrder,
|
||||
};
|
Reference in New Issue
Block a user