38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
|
|
using Syntriax.Engine.Core;
|
|
|
|
namespace Syntriax.Engine.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) 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) where T : class, new();
|
|
INetworkCommunicatorServer SendToAll<T>(T packet) where T : class, new();
|
|
}
|