feat: added networking system

This commit is contained in:
2025-08-05 19:27:27 +03:00
parent 3452194941
commit 6631cae7b0
10 changed files with 427 additions and 0 deletions

View 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; }
}

View File

@@ -0,0 +1,6 @@
namespace Syntriax.Engine.Systems.Network;
public interface IEntityNetworkPacket : INetworkPacket
{
string EntityId { get; }
}

View 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();
}

View File

@@ -0,0 +1,5 @@
using Syntriax.Engine.Core;
namespace Syntriax.Engine.Systems.Network;
public interface INetworkEntity : IEntity;

View 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; }
}

View File

@@ -0,0 +1,3 @@
namespace Syntriax.Engine.Systems.Network;
public interface INetworkPacket;

View File

@@ -0,0 +1,6 @@
namespace Syntriax.Engine.Systems.Network;
public interface IPacketListenerClient<T> : INetworkEntity
{
void OnClientPacketArrived(IConnection sender, T packet);
}

View File

@@ -0,0 +1,6 @@
namespace Syntriax.Engine.Systems.Network;
public interface IPacketListenerServer<T> : INetworkEntity
{
void OnServerPacketArrived(IConnection sender, T packet);
}

View File

@@ -0,0 +1,9 @@
namespace Syntriax.Engine.Systems.Network;
public enum PacketDelivery
{
ReliableInOrder,
ReliableOutOfOrder,
UnreliableInOrder,
UnreliableOutOfOrder,
};