Rework client to be non static
This commit is contained in:
1 parent
6f910e969a
commit
b439805f3e
7 files changed
+107
-108
No files matched your search
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Net;
|
||||
|
||||
namespace Mistox.Client {
|
||||
|
||||
public class MistoxClient {
|
||||
|
||||
public string ServerName { get; set; } = ""; // The Name of the server
|
||||
public bool Alive { get; set; } = true; // Is the server running
|
||||
public mTCPClient ServerConnection;
|
||||
public ConcurrentDictionary<string, mUDPClient> clientConnections;
|
||||
|
||||
public MistoxClient(IPEndPoint Server) {
|
||||
Console.WriteLine( "The client is initilized and trying to connect to the server at ip : " + Server.Address );
|
||||
try {
|
||||
ServerConnection = new mTCPClient( this, Server );
|
||||
Console.WriteLine( "Connected to the server sucessfully" );
|
||||
} catch( Exception e ) {
|
||||
Console.WriteLine( "An error has occured with the connection to the server. Error { " );
|
||||
Console.WriteLine( e.ToString() );
|
||||
Console.WriteLine( "}" );
|
||||
}
|
||||
Alive = true;
|
||||
}
|
||||
|
||||
public event Action onServerConnected;
|
||||
public void InvokeOnServerConnected(){
|
||||
Alive = true;
|
||||
onServerConnected?.Invoke();
|
||||
}
|
||||
|
||||
public event Action<mUDPClient> onUserConnected;
|
||||
public void InvokeOnUserConnected(mUDPClient ConnectedUser){
|
||||
onUserConnected?.Invoke(ConnectedUser);
|
||||
}
|
||||
|
||||
public event Action<dynamic> onDataReceived;
|
||||
public void InvokeOnReceived(dynamic DataPacket){
|
||||
onDataReceived?.Invoke(DataPacket);
|
||||
}
|
||||
|
||||
public event Action<mUDPClient> onUserDisconnected;
|
||||
public void InvokeOnUserDisconnected(mUDPClient DisconnectedUser){
|
||||
onUserDisconnected?.Invoke(DisconnectedUser);
|
||||
}
|
||||
|
||||
public event Action onServerDisconnected;
|
||||
public void InvokeOnServerDisconnected(){
|
||||
Alive = false;
|
||||
onServerDisconnected?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user