Major overall of data

This commit is contained in:
derek.holloway committed 2026-07-02 21:48:43 -07:00
1 parent 64dbd02874
commit 6126b8259c
12 files changed
+160 -126

No files matched your search

@@ -0,0 +1,24 @@
using System;
namespace Mistox.Client {
public class MistoxServerClient {
public string ServerName { get; set; } = ""; // The Name of the server
public bool Alive { get; set; } = true; // Is the server running
public int Port { get; set; } = 9126; // What Port to bind on
public event EventHandler onUserConnected;
public void InvokeOnUserConnected(UDPEndpoint ConnectedUser){
onUserConnected?.Invoke(ConnectedUser, new EventArgs());
}
public event EventHandler onReceived;
public void InvokeOnReceived(dynamic DataPacket){
onReceived?.Invoke(DataPacket, new EventArgs());
}
public event EventHandler onUserDisconnected;
public void InvokeOnUserDisconnected(UDPEndpoint DisconnectedUser){
onUserDisconnected?.Invoke(DisconnectedUser, new EventArgs());
}
}
}
@@ -0,0 +1,10 @@
using System.Net;
namespace Mistox.Client {
public class UDPEndpoint {
public string UserName { get; set; } = ""; // The Players UserName
public bool Alive { get; set; } = true; // Is the connection alive
public IPEndPoint Destination { get; set; } // The IP destination for the connection
public mUDPClient Connection { get; set; } // The UDP Client Object
}
}
+11 -19
View File
@@ -6,23 +6,16 @@ using System.Threading.Tasks;
//IP Range Updater
namespace MistoxServer.Client {
namespace Mistox.Client {
public class mTCPClient : IDisposable {
TcpClient Server;
public event EventHandler onConnected;
public event EventHandler onReceived;
public event EventHandler onDisconnected;
public bool Alive;
bool notified = false;
public mTCPClient( IPEndPoint ServerAddress ) {
Server = new TcpClient( AddressFamily.InterNetwork );
Server.NoDelay = true;
Server.Connect( ServerAddress );
Alive = true;
ClientInterface.ServerClientInstance.Alive = true;
Thread RThread = new Thread(async () => { await ReceiveThread(); });
RThread.Start();
}
@@ -30,29 +23,28 @@ namespace MistoxServer.Client {
async Task ReceiveThread() {
using( NetworkStream ns = Server.GetStream() ) {
try {
while( Alive ) {
if( Server.Connected && !notified ) {
while( ClientInterface.ServerClientInstance.Alive ) {
if( Server.Connected ) {
Console.WriteLine( "Connected to server" );
onConnected?.Invoke( new object(), new EventArgs() );
notified = true;
ClientInterface.ServerClientInstance.onConnected.Invoke( new object(), new EventArgs() );
} else if( !Server.Connected ) {
Console.WriteLine( "Disconnected from server" );
onDisconnected?.Invoke( new object(), new EventArgs() );
Alive = false;
ClientInterface.ServerClientInstance.onDisconnected?.Invoke( new object(), new EventArgs() );
ClientInterface.ServerClientInstance.Alive = false;
}
byte[] StreamData = new byte[1024];
int bytesRead = await ns.ReadAsync(StreamData, 0, StreamData.Length);
if( bytesRead > 0 ) {
dynamic data = mSerialize.tReceive( StreamData.Sub( 0, bytesRead ) );
if( data != null ) {
onReceived?.Invoke( data, new EventArgs() );
ClientInterface.ServerClientInstance.onReceive?.Invoke( data, new EventArgs() );
}
}
}
} catch( Exception ) {
Console.WriteLine( "You have disconnected from the server" );
onDisconnected?.Invoke( new object(), new EventArgs() );
Alive = false;
ClientInterface.ServerClientInstance.onDisconnected?.Invoke( new object(), new EventArgs() );
ClientInterface.ServerClientInstance.Alive = false;
}
}
}
@@ -63,7 +55,7 @@ namespace MistoxServer.Client {
}
public void Dispose() {
Alive = false;
ClientInterface.ServerClientInstance.Alive = false;
Server.Close();
Server = null;
}
+2 -6
View File
@@ -6,16 +6,12 @@ using System.Threading.Tasks;
// Network Sync
namespace MistoxServer.Client {
namespace Mistox.Client {
public class mUDPClient : IDisposable {
public event EventHandler onReceived;
Socket udpClient;
bool Alive;
int Port;
public mUDPClient( IPEndPoint ServerAddress ) {
public mUDPClient( IPEndPoint ServerAddress, string ConnectionID ) {
udpClient = new Socket( AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp );
udpClient.SetSocketOption( SocketOptionLevel.IP, SocketOptionName.ReuseAddress, true );
udpClient.SetSocketOption( SocketOptionLevel.IP, SocketOptionName.IpTimeToLive, 128 );