Compare commits

..

No commits in common. "de267a9d0f358240e7aa434c5d0ee268462603cc" and "257e414c2a066b3ae3bc86eac5c405da350ba2a1" have entirely different histories.

3 changed files with 0 additions and 61 deletions

View File

@ -21,7 +21,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Apos.Shapes" Version="0.2.3" />
<PackageReference Include="LiteNetLib" Version="1.2.0" />
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.1.303" />
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.1.303" />
</ItemGroup>

View File

@ -1,21 +0,0 @@
using LiteNetLib;
namespace Game.Network;
public class NetworkClient
{
public readonly EventBasedNetListener Listener = null!;
public readonly NetManager Client = null!;
public NetworkClient()
{
Listener = new EventBasedNetListener();
Client = new NetManager(Listener);
}
public void Connect(string address, int port, string? password = null)
=> Client.Connect(address, port, password ?? string.Empty);
public void PollEvents() => Client.PollEvents();
public void Stop() => Client.Stop();
}

View File

@ -1,39 +0,0 @@
using LiteNetLib;
namespace Game.Network;
public class NetworkServer
{
public string Password { get; private set; } = string.Empty;
public int MaxConnectionCount { get; private set; } = 0;
public int Port { get; private set; } = 8888;
public readonly EventBasedNetListener Listener = null!;
public readonly NetManager Server = null!;
public NetworkServer()
{
Listener = new EventBasedNetListener();
Server = new NetManager(Listener);
Listener.ConnectionRequestEvent += request =>
{
if (Server.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;
Server.Start(port);
}
public void PollEvents() => Server.PollEvents();
public void Stop() => Server.Stop();
}