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

+35 -32
View File
@@ -1,46 +1,43 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using MistoxServer.Client;
using Mistox.Client;
namespace MistoxServer {
public class ClientInterface : IMistoxServer {
namespace Mistox {
public class ClientInterface {
mTCPClient SlowUpdate;
mUDPClient FastUpdate;
IPEndPoint mPEndPoint;
public static MistoxServerClient ServerClientInstance;
public static mTCPClient serverConnection;
public static ConcurrentDictionary<string, UDPEndpoint> clientConnections;
public event EventHandler onConnected;
public event EventHandler onSlowReceive;
public event EventHandler onFastReceive;
public event EventHandler onDisconnected;
public event EventHandler onUserConnected;
public event EventHandler onReceive;
public event EventHandler onUserDisconnected;
public ClientInterface( string IpOrHostName, int Port ) {
ServerClientInstance = new MistoxServerClient() {
Port = Port
};
// Get Server IP
IPHostEntry host = Dns.GetHostEntry( IpOrHostName );
IPEndPoint ServerDenstination = new IPEndPoint(0, 0);
foreach( IPAddress entry in host.AddressList ) {
if ( entry.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork ) {
mPEndPoint = new IPEndPoint( entry, Port );
ServerDenstination = new IPEndPoint( entry, Port );
}
}
Console.WriteLine( "The client is initilized and trying to connect to the server at ip : " + mPEndPoint.Address );
// Make a UDP connection to the server
try {
FastUpdate = new mUDPClient( mPEndPoint );
FastUpdate.onReceived += (object o, EventArgs e) => { onFastReceive?.Invoke( o, e ); };
} catch( Exception e ) {
Console.WriteLine( "An error has occured with the connection to the server. Error { " );
Console.WriteLine( e.ToString() );
Console.WriteLine( "}" );
}
Console.WriteLine( "The client is initilized and trying to connect to the server at ip : " + ServerDenstination.Address );
// Make a TCP connection to the server
try {
SlowUpdate = new mTCPClient( mPEndPoint );
SlowUpdate.onConnected += ( object o, EventArgs e ) => { onConnected?.Invoke( o, e ); };
SlowUpdate.onReceived += ( object o, EventArgs e ) => { onSlowReceive?.Invoke( o, e ); };
SlowUpdate.onDisconnected += ( object o, EventArgs e ) => { onDisconnected?.Invoke( o, e ); };
serverConnection = new mTCPClient( ServerDenstination );
serverConnection.on +=
serverConnection.onReceive += ( object o, EventArgs e ) => { onReceive?.Invoke( o, e ); };
serverConnection.onDisconnected += ( object o, EventArgs e ) => { onUserDisconnected?.Invoke( o, e ); };
} catch( Exception e ) {
Console.WriteLine( "An error has occured with the connection to the server. Error { " );
Console.WriteLine( e.ToString() );
@@ -48,12 +45,18 @@ namespace MistoxServer {
}
}
public async Task Send<Packet>(Packet data, SendType speed) {
if (SendType.SlowUpdate == speed) {
await SlowUpdate.Send( data );
} else {
await FastUpdate.Send( data, mPEndPoint );
public async Task SendAllClients<Packet>(Packet data) {
foreach(KeyValuePair<string, UDPEndpoint> cur in clientConnections){
await cur.Value.Connection.Send( data, cur.Value.Destination );
}
}
public async Task SendClient<Packet>(string UserName, Packet data) {
await clientConnections[UserName].Connection.Send( data, clientConnections[UserName].Destination );
}
public async Task SendServer<Packet>(Packet data) {
await serverConnection.Send( data );
}
}
}
+2 -2
View File
@@ -4,12 +4,12 @@ using System.Net;
namespace Mistox {
public class mServer {
public static ServerInterface newServer(int port, string serverName) {
public static ServerInterface newServer( string serverName, int port ) {
DataPacket.BuildNetworkPacketList();
return new ServerInterface(port, serverName);
}
public static ClientInterface newClient(string ServerIPOrHostName, int Port) {
public static ClientInterface newClient( string ServerIPOrHostName, int Port ) {
DataPacket.BuildNetworkPacketList();
int index = 0;
IPAddress[] remoteAddress = Dns.GetHostAddresses(ServerIPOrHostName);
+13 -9
View File
@@ -8,7 +8,9 @@ using Mistox.Server;
namespace Mistox {
public class ServerInterface {
MistoxServer ServerInstance;
public static MistoxServer ServerInstance; // Server Data
public static ServerListener Listener; // Server Listener
public static ConcurrentDictionary<string, TcpClientConnection> Connections; // Server Connections
public event EventHandler onUserConnected;
public event EventHandler onReceive;
@@ -21,27 +23,29 @@ namespace Mistox {
ServerName = serverName,
BindAddress = IPAddress.Any,
Port = port,
MaxClients = 10,
Connections = new ConcurrentDictionary<string, TcpClientConnection>()
MaxClients = 10
};
Connections = new ConcurrentDictionary<string, TcpClientConnection>();
// Setup the event handlers
ServerInstance.onUserConnected += onUserConnected;
ServerInstance.onReceived += onReceive;
ServerInstance.onUserDisconnected += onUserDisconnected;
// Start listening for connections and wire up the server
ServerInstance.serverListener = new ServerListener( ServerInstance );
ServerInstance.serverListener.onConnected += onUserConnected;
ServerInstance.serverListener.onReceive += onReceive;
ServerInstance.serverListener.onDisconnected += onUserDisconnected;
Listener = new ServerListener();
Console.WriteLine( "The Server is initilized and waiting for clients to connect at port : " + port );
}
public async Task SendAllClients<Packet>(Packet data) {
foreach( KeyValuePair<string, TcpClientConnection> cur in ServerInstance.Connections ) {
foreach( KeyValuePair<string, TcpClientConnection> cur in Connections ) {
await cur.Value.Connection.Send(data);
}
}
public async Task SendClient<Packet>(string UserName, Packet data) {
await ServerInstance.Connections[UserName].Connection.Send( data );
await Connections[UserName].Connection.Send( data );
}
}
}