diff --git a/MistoxServer/Client/MistoxClient.cs b/MistoxServer/Client/MistoxClient.cs index f2da7a6..12969da 100644 --- a/MistoxServer/Client/MistoxClient.cs +++ b/MistoxServer/Client/MistoxClient.cs @@ -6,7 +6,6 @@ using System.Net.Sockets; using System.Numerics; using System.Threading; using System.Threading.Tasks; -using MessagePack.Formatters; using Mistox.ResevedPackets; namespace Mistox.Client { @@ -37,14 +36,6 @@ namespace Mistox.Client { UserName = userName; ConnectionKey = connectionKey; - onServerConnected += () => {}; - onUserConnected += (_) => {}; - onUserJoined += (_) => {}; - onDataReceived += (_,_) => {}; - onUserLeft += (_) => {}; - onUserDisconnected += (_) => {}; - onServerDisconnected += () => {}; - // Create and connect to server on TCP Console.WriteLine( "The client is initilized and trying to connect to the server at ip : " + Server.Address ); try { @@ -148,7 +139,7 @@ namespace Mistox.Client { ///////////////////////////// // When (self) connects to the server - public event Action onServerConnected; + public event Action? onServerConnected; public void InvokeOnServerConnected(){ Alive = true; Task.Run(async () => { @@ -160,19 +151,19 @@ namespace Mistox.Client { } // When any user connects to the server (self) hasn't seen yet - public event Action onUserJoined; + public event Action? onUserJoined; public void InvokeOnUserJoined(mUDPClient User){ onUserJoined?.Invoke(User); } // When user is within range of (self) and network rendering starts - public event Action onUserConnected; + public event Action? onUserConnected; public void InvokeOnUserConnected(mUDPClient User){ onUserConnected?.Invoke(User); } // When generic data is received - public event Action onDataReceived; + public event Action? onDataReceived; public void InvokeOnReceived(dynamic DataPacket, mUDPClient? remote = null){ switch (DataPacket as object) { case HeartbeatPacket packet: @@ -193,19 +184,19 @@ namespace Mistox.Client { } // When user is no longer in range of (self) and network rendering stops - public event Action onUserDisconnected; + public event Action? onUserDisconnected; public void InvokeOnUserDisconnected(mUDPClient User){ onUserDisconnected?.Invoke(User); } // When any user disconnects from the server that isn't (self) - public event Action onUserLeft; + public event Action? onUserLeft; public void InvokeOnUserLeft(mUDPClient User){ onUserLeft?.Invoke(User); } // When (self) disconnects to the server - public event Action onServerDisconnected; + public event Action? onServerDisconnected; public void InvokeOnServerDisconnected(){ Alive = false; onServerDisconnected?.Invoke(); diff --git a/MistoxServer/Server/MistoxServer.cs b/MistoxServer/Server/MistoxServer.cs index 39da8b7..73d5e3f 100644 --- a/MistoxServer/Server/MistoxServer.cs +++ b/MistoxServer/Server/MistoxServer.cs @@ -22,9 +22,6 @@ namespace Mistox.Server { public MistoxServer(IPEndPoint ListenerAddress, string serverName) { ServerName = serverName; Listener = new ServerListener(ListenerAddress, this); - onUserConnected += (_) => {}; - onDataReceived += (_, _) => {}; - onUserDisconnected += (_) => {}; Console.WriteLine( "The Server is initilized and waiting for clients to connect at port : " + ListenerAddress.Port ); } @@ -75,13 +72,13 @@ namespace Mistox.Server { // Events ///////////////////////////// - public event Action onUserConnected; + public event Action? onUserConnected; public void InvokeUserConnected( ServerConnection user ){ Connections[user.UserName] = user; onUserConnected?.Invoke( user ); } - public event Action onDataReceived; + public event Action? onDataReceived; public void InvokeDataReceived( ServerConnection user, dynamic data ){ switch (data) { case UserAuthPacket packet when !user.IsAuthenticated: @@ -104,7 +101,7 @@ namespace Mistox.Server { } } - public event Action onUserDisconnected; + public event Action? onUserDisconnected; public void InvokeUserDisconnected( ServerConnection user ){ Connections.Remove(user.UserName, out _); onUserDisconnected?.Invoke( user );