2024-07-18 23:07:05 +03:00
|
|
|
using LiteNetLib.Utils;
|
|
|
|
|
2024-07-15 17:00:04 +03:00
|
|
|
using Syntriax.Engine.Network.Abstract;
|
|
|
|
|
|
|
|
namespace Syntriax.Engine.Network;
|
|
|
|
|
|
|
|
public class NetworkClient : NetworkBase, INetworkCommunicatorClient
|
|
|
|
{
|
2024-07-18 23:07:05 +03:00
|
|
|
private readonly NetDataWriter netDataWriter = new();
|
|
|
|
|
2024-07-15 17:00:04 +03:00
|
|
|
public void Connect(string address, int port, string? password = null)
|
|
|
|
{
|
|
|
|
Manager.Start();
|
|
|
|
Manager.Connect(address, port, password ?? string.Empty);
|
|
|
|
}
|
2024-07-18 23:07:05 +03:00
|
|
|
|
|
|
|
public override void Send<T>(NetworkPacket<T> packet)
|
|
|
|
{
|
|
|
|
netDataWriter.Reset();
|
|
|
|
netPacketProcessor.Write(netDataWriter, packet);
|
|
|
|
Manager.FirstPeer.Send(netDataWriter, LiteNetLib.DeliveryMethod.ReliableOrdered);
|
|
|
|
}
|
2024-07-15 17:00:04 +03:00
|
|
|
}
|