Major overall of data
This commit is contained in:
1 parent
64dbd02874
commit
6126b8259c
12 files changed
+160
-126
No files matched your search
@@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user