1
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace BITKit
|
||||
@@ -77,4 +78,25 @@ namespace BITKit
|
||||
writer.Write(value);
|
||||
}
|
||||
}
|
||||
public class GuidsSupport : NetMessageReader<Guid[]>
|
||||
{
|
||||
public override Guid[] ReadBinary(BinaryReader reader)
|
||||
{
|
||||
var count = reader.ReadInt32();
|
||||
var result = new Guid[count];
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
result[i] = new Guid(reader.ReadBytes(16));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public override void WriteBinary(BinaryWriter writer, Guid[] value)
|
||||
{
|
||||
writer.Write(value.Length);
|
||||
foreach (var guid in value)
|
||||
{
|
||||
writer.Write(guid.ToByteArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -118,6 +118,12 @@ namespace BITKit.Net
|
||||
|
||||
public async UniTask<bool> Connect(string address = "127.0.0.1", ushort port = 27014)
|
||||
{
|
||||
if (IsConnecting)
|
||||
{
|
||||
BIT4Log.Warning<KcpNetClient>("正在连接中");
|
||||
return false;
|
||||
}
|
||||
|
||||
//如果address是域名,解析为Ip
|
||||
if (address.Contains("."))
|
||||
{
|
||||
@@ -128,13 +134,13 @@ namespace BITKit.Net
|
||||
BIT4Log.Log<KcpNetClient>($"解析域名:{address}");
|
||||
}
|
||||
}
|
||||
|
||||
if (address is not "127.0.0.1")
|
||||
_connectedAddress = address;
|
||||
if (port is not 27014)
|
||||
_connectedPort = port;
|
||||
|
||||
|
||||
if (IsConnecting)
|
||||
{
|
||||
BIT4Log.Warning<KcpNetClient>("正在连接中");
|
||||
return false;
|
||||
}
|
||||
IsConnecting = true;
|
||||
if (client.connected) return false;
|
||||
await BITApp.SwitchToMainThread();
|
||||
|
@@ -325,7 +325,12 @@ namespace BITKit.Net
|
||||
{
|
||||
dynamic result = methodInfo.Invoke(handle, pars)!;
|
||||
|
||||
if (methodInfo.ReturnType == typeof(void) || methodInfo.ReturnType == typeof(UniTask))
|
||||
if (methodInfo.ReturnType == typeof(void)
|
||||
||
|
||||
methodInfo.ReturnType == typeof(UniTask)
|
||||
||
|
||||
methodInfo.ReturnType == typeof(UniTask<>)
|
||||
)
|
||||
{
|
||||
await result;
|
||||
value = -1;
|
||||
|
Reference in New Issue
Block a user