33 lines
909 B
C#
33 lines
909 B
C#
using System.Diagnostics;
|
|
using System.Threading.Tasks;
|
|
using Syntriax.Engine.Network.Abstract;
|
|
|
|
namespace Syntriax.Engine.Network;
|
|
|
|
public class NetworkServer : NetworkBase, INetworkCommunicatorServer
|
|
{
|
|
public string Password { get; private set; } = string.Empty;
|
|
public int MaxConnectionCount { get; private set; } = 0;
|
|
public int Port { get; private set; } = 8888;
|
|
|
|
public NetworkServer() : base()
|
|
{
|
|
Listener.ConnectionRequestEvent += request =>
|
|
{
|
|
if (Manager.ConnectedPeersCount < MaxConnectionCount)
|
|
request.AcceptIfKey(Password);
|
|
else
|
|
request.Reject();
|
|
};
|
|
}
|
|
|
|
public void Start(int port, int maxConnectionCount, string? password = null)
|
|
{
|
|
Password = password ?? string.Empty;
|
|
MaxConnectionCount = maxConnectionCount;
|
|
Port = port;
|
|
|
|
Manager.Start(port);
|
|
}
|
|
}
|