Engine-Pong/Game/Network/NetworkServer.cs

31 lines
841 B
C#
Raw Normal View History

using Syntriax.Engine.Network.Abstract;
namespace Syntriax.Engine.Network;
2024-02-01 23:38:39 +03:00
2024-02-02 12:42:59 +03:00
public class NetworkServer : NetworkBase, INetworkServer
2024-02-01 23:38:39 +03:00
{
public string Password { get; private set; } = string.Empty;
public int MaxConnectionCount { get; private set; } = 0;
public int Port { get; private set; } = 8888;
2024-02-02 12:42:59 +03:00
public NetworkServer() : base()
2024-02-01 23:38:39 +03:00
{
Listener.ConnectionRequestEvent += request =>
{
if (Manager.ConnectedPeersCount < MaxConnectionCount)
2024-02-01 23:38:39 +03:00
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);
2024-02-01 23:38:39 +03:00
}
}