Cleanup unnessisary interface classes

This commit is contained in:
derek.holloway committed 2026-08-03 13:25:28 -07:00
1 parent b83887cb2a
commit 46efb5bd65
8 files changed
+58 -117

No files matched your search

+16 -3
View File
@@ -1,14 +1,15 @@
using System;
using System.Collections.Concurrent;
using System.Net;
using System.Threading.Tasks;
namespace Mistox.Server {
public class ServerEntity {
public class MistoxServer {
// Class Definitions
public string ServerName { get; set; } = ""; // The name of the server
public string ServerName { get; private set; } = ""; // The name of the server
public int MaxClients { get; set; } = 10; // The max players per server
public float ConnectionRange { get; set; } = 40; // InGame distance for valid conections
public int ConnectionTimeoutSeconds { get; set; } = 10; // If no reply in time kill the connection
@@ -17,9 +18,11 @@ namespace Mistox.Server {
private readonly ServerListener Listener; // The Connection Listener singleton
public ServerEntity(IPEndPoint ListenerAddress) {
public MistoxServer(IPEndPoint ListenerAddress, string serverName) {
Listener = new ServerListener(ListenerAddress, this);
Connections = new ConcurrentDictionary<string, ServerConnection>();
ServerName = serverName;
Console.WriteLine( "The Server is initilized and waiting for clients to connect at port : " + ListenerAddress.Port );
}
// Functions
@@ -38,6 +41,16 @@ namespace Mistox.Server {
public void InvokeUserDisconnected( ServerConnection user ){
onUserDisconnected?.Invoke( user );
}
public async Task SendAllClients<Packet>(Packet data) {
foreach( ServerConnection cur in Connections.Values ) {
await cur.Send(data);
}
}
public async Task SendClient<Packet>(string UserName, Packet data) {
await Connections[UserName].Send( data );
}
}
}
+3 -3
View File
@@ -13,20 +13,20 @@ namespace Mistox.Server {
public Vector3 Position { get; set; } // The ingame position of the player
public bool Connected { get; set; } = true; // Is the connection valid
private readonly ServerEntity _parent;
private readonly MistoxServer _parent;
private readonly TcpClient _client;
private readonly IPEndPoint _remoteAddress;
private readonly SemaphoreSlim _sendLock = new SemaphoreSlim(1, 1);
private readonly CancellationTokenSource _cts = new();
public ServerConnection( TcpClient tcpClient, ServerEntity parent, IPEndPoint remote ) {
public ServerConnection( TcpClient tcpClient, MistoxServer parent, IPEndPoint remote ) {
_parent = parent;
_remoteAddress = remote;
_client = tcpClient;
_client.NoDelay = true;
_client.ReceiveTimeout = _parent.ConnectionTimeoutSeconds * 1000;
ServerInterface.ServerInstance.InvokeUserConnected( this );
_parent.InvokeUserConnected( this );
// Start the receive thread
Task.Run(ReceiveThread);
}
+2 -2
View File
@@ -8,11 +8,11 @@ using System.Threading.Tasks;
namespace Mistox.Server {
public class ServerListener : IDisposable {
private readonly ServerEntity _parent;
private readonly MistoxServer _parent;
private readonly IPEndPoint _bindAddress;
private readonly TcpListener _Listener;
public ServerListener(IPEndPoint listenerAddress, ServerEntity parent) {
public ServerListener(IPEndPoint listenerAddress, MistoxServer parent) {
_bindAddress = listenerAddress;
_parent = parent;