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,6 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Mistox.Client {
|
||||
@@ -7,38 +8,31 @@ namespace Mistox.Client {
|
||||
|
||||
public string UserName { get; set; } = ""; // The remote players UserName
|
||||
public bool Alive { get; set; } = true; // Is the connection alive
|
||||
public IPEndPoint IPAddress { get; set; } // The remote IP Address
|
||||
public IPEndPoint _remoteHost { get; set; } // The remote IP Address
|
||||
|
||||
IPEndPoint _remoteHost;
|
||||
MistoxClient _parent;
|
||||
private readonly SemaphoreSlim _sendLock = new SemaphoreSlim(1, 1);
|
||||
private readonly MistoxClient _parent;
|
||||
|
||||
public mUDPClient( MistoxClient parent, IPAddress RemoteIP, int Port ) {
|
||||
public mUDPClient( MistoxClient parent, IPEndPoint remoteHost ) {
|
||||
_parent = parent;
|
||||
_remoteHost = new IPEndPoint( RemoteIP, Port );
|
||||
_remoteHost = remoteHost;
|
||||
_parent.Alive = true;
|
||||
}
|
||||
|
||||
public async Task Send<T>( T Data ) {
|
||||
byte[] byteData = DataPacket.Serialize( Data );
|
||||
await _parent.ClientSocket.SendAsync( byteData, byteData.Length, _remoteHost );
|
||||
}
|
||||
|
||||
public static UInt128 GetConnectionKey(IPAddress ipAddress) {
|
||||
byte[] bytes = ipAddress.GetAddressBytes();
|
||||
if (bytes.Length == 4) {
|
||||
bytes = ipAddress.MapToIPv6().GetAddressBytes();
|
||||
await _sendLock.WaitAsync();
|
||||
try {
|
||||
await _parent.ClientSocket.SendAsync( byteData, byteData.Length, _remoteHost );
|
||||
} finally {
|
||||
_sendLock.Release();
|
||||
}
|
||||
return BitConverter.ToUInt128(bytes, 0);
|
||||
}
|
||||
|
||||
public UInt128 GetConnectionKey() {
|
||||
return GetConnectionKey( IPAddress.Address );
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
_parent.Alive = false;
|
||||
_parent.ClientSocket.Close();
|
||||
_parent.ClientSocket = null;
|
||||
_parent.ClientSocket.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user