31 lines
841 B
C#
31 lines
841 B
C#
using Syntriax.Engine.Network.Abstract;
|
|
|
|
namespace Syntriax.Engine.Network;
|
|
|
|
public class NetworkServer : NetworkBase, INetworkServer
|
|
{
|
|
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);
|
|
}
|
|
}
|