2024-02-02 12:27:34 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2024-02-01 23:38:35 +03:00
|
|
|
using LiteNetLib;
|
|
|
|
|
2024-02-02 12:27:34 +03:00
|
|
|
using Syntriax.Engine.Core;
|
|
|
|
using Syntriax.Engine.Core.Abstract;
|
|
|
|
|
2024-02-02 12:04:53 +03:00
|
|
|
namespace Pong.Network;
|
2024-02-01 23:38:35 +03:00
|
|
|
|
2024-02-02 12:27:34 +03:00
|
|
|
public class NetworkClient : BehaviourOverride, INetworkClient
|
2024-02-01 23:38:35 +03:00
|
|
|
{
|
2024-02-02 12:27:34 +03:00
|
|
|
public EventBasedNetListener Listener { get; private set; } = null!;
|
|
|
|
public NetManager Manager { get; private set; } = null!;
|
2024-02-01 23:38:35 +03:00
|
|
|
|
|
|
|
public NetworkClient()
|
|
|
|
{
|
2024-02-02 12:27:34 +03:00
|
|
|
Priority = 10;
|
|
|
|
|
2024-02-01 23:38:35 +03:00
|
|
|
Listener = new EventBasedNetListener();
|
2024-02-02 12:27:34 +03:00
|
|
|
Manager = new NetManager(Listener);
|
2024-02-01 23:38:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Connect(string address, int port, string? password = null)
|
2024-02-02 12:27:34 +03:00
|
|
|
{
|
|
|
|
Manager.Start();
|
|
|
|
Manager.Connect(address, port, password ?? string.Empty);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void PollEvents() => Manager.PollEvents();
|
|
|
|
public void Stop() => Manager.Stop();
|
2024-02-01 23:38:35 +03:00
|
|
|
|
2024-02-02 12:27:34 +03:00
|
|
|
protected override void OnUpdate() => PollEvents();
|
|
|
|
protected override void OnFinalize() => Stop();
|
2024-02-01 23:38:35 +03:00
|
|
|
}
|