Null check instead of initilizing empty work

This commit is contained in:
derek.holloway committed 2026-08-10 07:26:18 -07:00
1 parent c8a0aef289
commit d7581fbdeb
2 files changed
+10 -22

No files matched your search

+7 -16
View File
@@ -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<mUDPClient> onUserJoined;
public event Action<mUDPClient>? onUserJoined;
public void InvokeOnUserJoined(mUDPClient User){
onUserJoined?.Invoke(User);
}
// When user is within range of (self) and network rendering starts
public event Action<mUDPClient> onUserConnected;
public event Action<mUDPClient>? onUserConnected;
public void InvokeOnUserConnected(mUDPClient User){
onUserConnected?.Invoke(User);
}
// When generic data is received
public event Action<mUDPClient?, dynamic> onDataReceived;
public event Action<mUDPClient?, dynamic>? 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<mUDPClient> onUserDisconnected;
public event Action<mUDPClient>? onUserDisconnected;
public void InvokeOnUserDisconnected(mUDPClient User){
onUserDisconnected?.Invoke(User);
}
// When any user disconnects from the server that isn't (self)
public event Action<mUDPClient> onUserLeft;
public event Action<mUDPClient>? 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();