29 lines
789 B
C#
29 lines
789 B
C#
namespace Pong.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);
|
|
}
|
|
}
|