Tons of minor fixes
This commit is contained in:
1 parent
873a6fa455
commit
37a6b5d59b
12 files changed
+219
-147
No files matched your search
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Mistox.Client;
|
||||
@@ -15,7 +14,7 @@ namespace Mistox {
|
||||
public event Action<mUDPClient> onUserDisconnected;
|
||||
public event Action onServerDisconnected;
|
||||
|
||||
public ClientInterface( string IpOrHostName, int Port ) {
|
||||
public ClientInterface( string UserName, string ConnectionKey, string IpOrHostName, int Port ) {
|
||||
|
||||
// Get Server IP
|
||||
IPHostEntry host = Dns.GetHostEntry( IpOrHostName );
|
||||
@@ -27,7 +26,7 @@ namespace Mistox {
|
||||
}
|
||||
|
||||
// Start and wire up the Mistox server client
|
||||
serverInstance = new MistoxClient( ServerDenstination );
|
||||
serverInstance = new MistoxClient( UserName, ConnectionKey, ServerDenstination );
|
||||
serverInstance.onServerConnected += onServerConnected;
|
||||
serverInstance.onUserConnected += (mUDPClient endpoint) => { onUserConnected?.Invoke(endpoint); };
|
||||
serverInstance.onDataReceived += (dynamic data) => { onDataReceived?.Invoke(data); };
|
||||
@@ -36,15 +35,15 @@ namespace Mistox {
|
||||
}
|
||||
|
||||
public async Task SendAllClients<Packet>(Packet data) {
|
||||
foreach( KeyValuePair<UInt128, mUDPClient> cur in serverInstance.clientConnections ){
|
||||
await cur.Value.Send( data );
|
||||
foreach( mUDPClient cur in serverInstance.clientConnections.Values ){
|
||||
await cur.Send( data );
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SendClient<Packet>(string UserName, Packet data) {
|
||||
foreach( KeyValuePair<UInt128, mUDPClient> cur in serverInstance.clientConnections) {
|
||||
if (cur.Value.UserName.ToLower() == UserName.ToLower()) {
|
||||
await cur.Value.Send( data );
|
||||
foreach( mUDPClient cur in serverInstance.clientConnections.Values ) {
|
||||
if (cur.UserName.ToLower() == UserName.ToLower()) {
|
||||
await cur.Send( data );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Mistox {
|
||||
return new ServerInterface(port, serverName);
|
||||
}
|
||||
|
||||
public static ClientInterface newClient( string ServerIPOrHostName, int Port ) {
|
||||
public static ClientInterface newClient( string UserName, string ServerIPOrHostName, int Port, string ConnectionKey = "" ) {
|
||||
NetworkPacketDictionary.BuildNetworkPacketList();
|
||||
int index = 0;
|
||||
IPAddress[] remoteAddress = Dns.GetHostAddresses(ServerIPOrHostName);
|
||||
@@ -21,7 +21,7 @@ namespace Mistox {
|
||||
}
|
||||
string ipAddress = remoteAddress[index].ToString();
|
||||
if ( remoteAddress.Length > 0) {
|
||||
return new ClientInterface(ipAddress, Port);
|
||||
return new ClientInterface(UserName, ConnectionKey, ipAddress, Port);
|
||||
} else {
|
||||
Console.WriteLine("The server at " + ServerIPOrHostName + " doesn't exit or cannot be found");
|
||||
return null;
|
||||
|
||||
Reference in new issue
Block a user