Update
This commit is contained in:
ALEXTANG
2023-07-13 21:13:29 +08:00
parent 72b7149aa1
commit 1382db8c61
2 changed files with 24 additions and 0 deletions

View File

@@ -19,6 +19,21 @@ namespace TEngine.Core.Network
private static readonly Dictionary<long, Session> Sessions = new ();
public readonly Dictionary<long, FTask<IResponse>> RequestCallback = new();
#if TENGINE_UNITY
public delegate void CsMsgDelegate(IResponse msg);
public readonly Dictionary<uint, CsMsgDelegate> MsgHandles = new Dictionary<uint, CsMsgDelegate>();
public void RegisterMsgHandler(uint protocolCode,CsMsgDelegate ctx)
{
if (MsgHandles.ContainsKey(protocolCode))
{
return;
}
MsgHandles.Add(protocolCode,ctx);
}
#endif
public static void Create(ANetworkMessageScheduler networkMessageScheduler, ANetworkChannel channel)
{
#if TENGINE_DEVELOP

View File

@@ -1,5 +1,6 @@
using System;
using System.IO;
using Codice.Client.GameUI.Explorer;
using TEngine.Core;
#pragma warning disable CS8600
@@ -55,6 +56,14 @@ namespace TEngine.Core.Network
// 服务器之间发送消息因为走的是MessageHelper、所以接收消息的回调也应该放到MessageHelper里处理
MessageHelper.ResponseHandler(packInfo.RpcId, aResponse);
#else
#if TENGINE_UNITY
if (session.MsgHandles.TryGetValue(packInfo.ProtocolCode,out var msgDelegate))
{
msgDelegate.Invoke(aResponse);
return;
}
#endif
// 这个一般是客户端Session.Call发送时使用的、目前这个逻辑只有Unity客户端时使用
if (!session.RequestCallback.TryGetValue(packInfo.RpcId, out var action))