This commit is contained in:
CortexCore 2024-07-29 14:37:00 +08:00
parent 18d888dfce
commit d044175e77
3 changed files with 23 additions and 9 deletions

View File

@ -137,7 +137,7 @@ namespace BITKit
} }
public static void Write(BinaryWriter writer, object value) public static void Write(BinaryWriter writer, object value)
{ {
if (value is IEnumerable enumerable and not string) if (value is not string && value is IList enumerable)
{ {
try try
{ {

View File

@ -26,6 +26,7 @@ namespace BITKit.Net
public event Action OnConnectedFailed; public event Action OnConnectedFailed;
public bool IsConnected => _isConnected; public bool IsConnected => _isConnected;
public bool IsConnecting { get; private set; } public bool IsConnecting { get; private set; }
public double RpcTimeOut { get; set; } = 5;
public bool AutoReconnect { get; set; } = true; public bool AutoReconnect { get; set; } = true;
public float2 Traffic { get; set; } public float2 Traffic { get; set; }
public bool ManualTick { get; set; } public bool ManualTick { get; set; }
@ -199,7 +200,7 @@ namespace BITKit.Net
switch (type) switch (type)
{ {
case NetCommandType.Message: case NetCommandType.Message:
BIT4Log.Log<KcpClient>($"已收到消息:{reader.ReadString()}"); BIT4Log.Log<KcpNetClient>($"已收到消息:{reader.ReadString()}");
break; break;
case NetCommandType.AllClientCommand: case NetCommandType.AllClientCommand:
case NetCommandType.Command: case NetCommandType.Command:
@ -386,14 +387,14 @@ namespace BITKit.Net
{ {
BIT4Log.Warning<KcpClient>($"未找到对应的Rpc方法:{rpcName}"); BIT4Log.Warning<KcpNetClient>($"未找到对应的Rpc方法:{rpcName}");
} }
} }
break; break;
default: default:
BIT4Log.Log<KcpClient>($"未知消息类型:{type},字节:{(byte)type}"); BIT4Log.Log<KcpNetClient>($"未知消息类型:{type},字节:{(byte)type}");
if (bytes.Array != null) if (bytes.Array != null)
BIT4Log.Log<KcpClient>( BIT4Log.Log<KcpNetClient>(
$"已收到:({Id}, {BitConverter.ToString(bytes.Array, bytes.Offset, bytes.Count)} @ {channel})"); $"已收到:({Id}, {BitConverter.ToString(bytes.Array, bytes.Offset, bytes.Count)} @ {channel})");
break; break;
} }
@ -414,7 +415,7 @@ namespace BITKit.Net
} }
private void OnError(ErrorCode errorCode, string message) private void OnError(ErrorCode errorCode, string message)
{ {
BIT4Log.Log<KCPNetServer>($"{client.remoteEndPoint}异常:{errorCode},{message}"); BIT4Log.Log<KcpNetClient>($"{client.remoteEndPoint}异常:{errorCode},{message}");
} }
public void ServerCommand<T>(T command = default) public void ServerCommand<T>(T command = default)
@ -476,7 +477,7 @@ namespace BITKit.Net
while (true) while (true)
{ {
if ((_now - startTime).TotalSeconds > 5) if ((_now - startTime).TotalSeconds > RpcTimeOut)
{ {
await BITApp.SwitchToMainThread(); await BITApp.SwitchToMainThread();
if (string.IsNullOrEmpty(path)) if (string.IsNullOrEmpty(path))
@ -505,6 +506,8 @@ namespace BITKit.Net
} }
} }
public UniTask<T> GetFromClient<T>(int id,string path, params object[] pars) public UniTask<T> GetFromClient<T>(int id,string path, params object[] pars)
{ {
throw new NotImplementedException(); throw new NotImplementedException();

View File

@ -356,9 +356,20 @@ namespace BITKit.Net
} }
returnWriter.Write(true); returnWriter.Write(true);
if (value is not null) if (value is not null)
{
try
{ {
BITBinary.Write(returnWriter, value); BITBinary.Write(returnWriter, value);
} }
catch (NullReferenceException e)
{
throw;
}
catch (Exception e)
{
throw;
}
}
} }
else else
{ {