From c8a0aef289922d219a4c9ae45f888a2d43691307 Mon Sep 17 00:00:00 2001 From: "derek.holloway" Date: Fri, 7 Aug 2026 13:20:32 -0700 Subject: [PATCH] Get CLI to a base state --- CLI/ClientExample.cs | 14 ++++++++++++-- MistoxServer/Client/MistoxClient.cs | 27 ++++++++++++++++----------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/CLI/ClientExample.cs b/CLI/ClientExample.cs index b112646..afd1548 100644 --- a/CLI/ClientExample.cs +++ b/CLI/ClientExample.cs @@ -12,7 +12,11 @@ class clientExample { } void onClientConnected(mUDPClient user) { - Console.WriteLine("User connected with username: " + user.UserName); + Console.WriteLine("User connected to server with username: " + user.UserName); + } + + void onClientJoined(mUDPClient user) { + Console.WriteLine("User is now in range of you and UDP connections started with user : " + user.UserName); } void onReceive(mUDPClient? user, dynamic data) { @@ -29,8 +33,12 @@ class clientExample { } } + void onClientLeft(mUDPClient user) { + Console.WriteLine("User is no longer in range of you and UDP connections ended with user : " + user.UserName); + } + void onClientDisconnected(mUDPClient user) { - Console.WriteLine("User disconnected with username: " + user.UserName); + Console.WriteLine("User disconnected from server with username: " + user.UserName); } void onServerDisconnected() { @@ -42,7 +50,9 @@ class clientExample { if (clientObject == null) return; clientObject.onServerConnected += onServerConnected; clientObject.onUserConnected += onClientConnected; + clientObject.onUserJoined += onClientJoined; clientObject.onDataReceived += onReceive; + clientObject.onUserLeft += onClientLeft; clientObject.onUserDisconnected += onClientDisconnected; clientObject.onServerDisconnected += onServerDisconnected; } diff --git a/MistoxServer/Client/MistoxClient.cs b/MistoxServer/Client/MistoxClient.cs index 3a0fc35..f2da7a6 100644 --- a/MistoxServer/Client/MistoxClient.cs +++ b/MistoxServer/Client/MistoxClient.cs @@ -6,6 +6,7 @@ using System.Net.Sockets; using System.Numerics; using System.Threading; using System.Threading.Tasks; +using MessagePack.Formatters; using Mistox.ResevedPackets; namespace Mistox.Client { @@ -95,13 +96,17 @@ namespace Mistox.Client { if (!clientConnections.ContainsKey(remoteHost)) { mUDPClient newConnection = new mUDPClient(this, remoteHost); clientConnections[remoteHost] = newConnection; + InvokeOnUserJoined(newConnection); } } // Remove users that left foreach (IPEndPoint key in clientConnections.Keys) { if (!activeIps.Contains(key.Address)) { - clientConnections.TryRemove(key, out _); + mUDPClient? user; + clientConnections.TryRemove(key, out user); + if (user == null) return; + InvokeOnUserLeft(user); } } @@ -155,15 +160,15 @@ namespace Mistox.Client { } // When any user connects to the server (self) hasn't seen yet - public event Action onUserJoined; - public void InvokeOnUserJoined(string UserName){ - onUserJoined?.Invoke(UserName); + 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 void InvokeOnUserConnected(mUDPClient ConnectedUser){ - onUserConnected?.Invoke(ConnectedUser); + public void InvokeOnUserConnected(mUDPClient User){ + onUserConnected?.Invoke(User); } // When generic data is received @@ -189,14 +194,14 @@ namespace Mistox.Client { // When user is no longer in range of (self) and network rendering stops public event Action onUserDisconnected; - public void InvokeOnUserDisconnected(mUDPClient DisconnectedUser){ - onUserDisconnected?.Invoke(DisconnectedUser); + public void InvokeOnUserDisconnected(mUDPClient User){ + onUserDisconnected?.Invoke(User); } // When any user disconnects from the server that isn't (self) - public event Action onUserLeft; - public void InvokeOnUserLeft(string UserName){ - onUserLeft?.Invoke(UserName); + public event Action onUserLeft; + public void InvokeOnUserLeft(mUDPClient User){ + onUserLeft?.Invoke(User); } // When (self) disconnects to the server