feat: engine data type packers

This commit is contained in:
2025-05-16 21:34:35 +03:00
parent 6591326b70
commit 03082ab43b
18 changed files with 361 additions and 9 deletions

View File

@@ -0,0 +1,28 @@
using LiteNetLib.Utils;
namespace Syntriax.Engine.Network;
public class LiteNetLibClient : LiteNetLibCommunicatorBase, INetworkCommunicatorClient
{
private readonly NetDataWriter netDataWriter = new();
public INetworkCommunicatorClient Connect(string address, int port, string? password = null)
{
if (!IsInUniverse)
throw new($"{nameof(LiteNetLibClient)} must be in an universe to connect");
Manager.Start();
Manager.Connect(address, port, password ?? string.Empty);
return this;
}
public INetworkCommunicatorClient SendToServer<T>(T packet) where T : class, new()
{
netDataWriter.Reset();
netPacketProcessor.Write(netDataWriter, packet);
Manager.FirstPeer.Send(netDataWriter, LiteNetLib.DeliveryMethod.ReliableOrdered);
return this;
}
}