diff --git a/AxibugEmuOnline.Client/Assets/Plugins/AxiNSApi/AxiNSIO.cs b/AxibugEmuOnline.Client/Assets/Plugins/AxiNSApi/AxiNSIO.cs index 933682de..82afdf39 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/AxiNSApi/AxiNSIO.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/AxiNSApi/AxiNSIO.cs @@ -2,10 +2,7 @@ using nn.fs; #endif -using nn.fs; using System.Collections.Generic; -using System.Linq; -using System.Text.RegularExpressions; public class AxiNSIO { diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiIO/AxiIO.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiIO/AxiIO.cs index a902398c..c621882a 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiIO/AxiIO.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/AxiIO/AxiIO.cs @@ -1,5 +1,4 @@ -using Sony.Vita.Dialog; -using System.Collections.Generic; +using System.Collections.Generic; namespace AxiIO { diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/SaveSlotManager/SavCloudApi.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/SaveSlotManager/SavCloudApi.cs index 49c63643..484c7c38 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/SaveSlotManager/SavCloudApi.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/SaveSlotManager/SavCloudApi.cs @@ -70,7 +70,7 @@ namespace AxibugEmuOnline.Client SavDataIdx = SavDataIdx }; App.log.Info($"SendDelGameSavList"); - App.network.SendToServer((int)CommandID.CmdGamesavGetGameSavList, ProtoBufHelper.Serizlize(req)); + App.network.SendToServer((int)CommandID.CmdGamesavDelGameSav, ProtoBufHelper.Serizlize(req)); } void RecvDelGameSavList(byte[] reqData) @@ -105,7 +105,7 @@ namespace AxibugEmuOnline.Client App.log.Info($"上传即时存档数据 原数据大小:{RawData.Length},压缩后;{compressRawData.Length}"); App.log.Info($"上传截图 原数据大小:{SavImgData.Length},压缩后;{compressImgData.Length}"); - App.network.SendToServer((int)CommandID.CmdGamesavGetGameSavList, ProtoBufHelper.Serizlize(req)); + App.network.SendToServer((int)CommandID.CmdGamesavUploadGameSav, ProtoBufHelper.Serizlize(req)); } void RecvUpLoadGameSav(byte[] reqData) diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/MonoCom/TickLoop.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/MonoCom/TickLoop.cs index 7b6b51da..858e1ad7 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/MonoCom/TickLoop.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/MonoCom/TickLoop.cs @@ -46,7 +46,7 @@ namespace AxibugEmuOnline.Client float LastLoopTime_15s; private void Update() { - NetMsg.Instance.DequeueNesMsg(); + NetMsg.Instance.NextNetEvent(); LoopAction_tick?.Invoke(); diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Network/NetMsg.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Network/NetMsg.cs index 307561e1..a8f5c314 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Network/NetMsg.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Network/NetMsg.cs @@ -1,4 +1,5 @@ using AxibugEmuOnline.Client.ClientCore; +using AxibugEmuOnline.Client.Event; using AxibugProtobuf; using System; using System.Collections.Generic; @@ -15,11 +16,15 @@ namespace AxibugEmuOnline.Client.Network private Dictionary> netEventDic = new Dictionary>(128); private Queue> queueNetMsg = new Queue>(); + public static object lockQueueNetMsg = new object(); + + private Queue queueEventFromNet = new Queue(); + public static object lockQueueEventFromNet = new object(); + private NetMsg() { } - public static object lockQueueObj = new object(); #region RegisterMsgEvent @@ -59,13 +64,56 @@ namespace AxibugEmuOnline.Client.Network netEventDic[cmd].Remove(callback); if (netEventDic[cmd].Count == 0) netEventDic.Remove(cmd); } - } + } #endregion - - #region PostEvent - public void EnqueueNesMsg(int cmd, int ERRCODE, byte[] arg) + + + public void NextNetEvent() { - lock (lockQueueObj) + DequeueNesMsg(); + DequeueEventFromNet(); + } + + #region PostEventFromNet + + public void EnqueueEventFromNet(Action act) + { + lock (lockQueueEventFromNet) + { + queueEventFromNet.Enqueue(act); + } + } + + public void DequeueEventFromNet() + { + lock (lockQueueEventFromNet) + { + while (queueEventFromNet.Count > 0) + { + var msgData = queueEventFromNet.Dequeue(); + PostNetEventFromNet(msgData); + } + } + } + + void PostNetEventFromNet(Action act) + { + try + { + act?.Invoke(); + } + catch(Exception ex) + { + App.log.Error(ex.ToString()); + } + } + #endregion + + #region PostNetMsg + + public void EnqueueNetMsg(int cmd, int ERRCODE, byte[] arg) + { + lock (lockQueueNetMsg) { queueNetMsg.Enqueue(new ValueTuple(cmd, ERRCODE, arg)); } @@ -73,7 +121,7 @@ namespace AxibugEmuOnline.Client.Network public void DequeueNesMsg() { - lock (lockQueueObj) + lock (lockQueueNetMsg) { while (queueNetMsg.Count > 0) { diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Network/NetworkHelper.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Network/NetworkHelper.cs index 9ea8343d..6c60c36f 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Network/NetworkHelper.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Network/NetworkHelper.cs @@ -15,11 +15,11 @@ namespace AxibugEmuOnline.Client.Network { public NetworkHelper() { + OnConnected += NetworkConnected; //指定接收服务器数据事件 OnReceiveData += GetDataCallBack; //断开连接 OnClose += OnConnectClose; - OnConnected += NetworkConnected; //网络库调试信息输出事件,用于打印网络内容 OnLogOut += NetworkDeBugLog; } @@ -39,7 +39,17 @@ namespace AxibugEmuOnline.Client.Network /// const int ReConnectTryTime = 1000; - public void NetworkConnected(bool IsConnect) + void NetworkConnected(bool IsConnect) + { + NetMsg.Instance.EnqueueEventFromNet(() => NetworkConnected_Delegate(IsConnect)); + } + + void OnConnectClose() + { + NetMsg.Instance.EnqueueEventFromNet(() => OnConnectClose_Delegate()); + } + + void NetworkConnected_Delegate(bool IsConnect) { NetworkDeBugLog($"NetworkConnected:{IsConnect}"); if (IsConnect) @@ -63,7 +73,7 @@ namespace AxibugEmuOnline.Client.Network } } - public void NetworkDeBugLog(string str) + void NetworkDeBugLog(string str) { //用于Unity内的输出 //Debug.Log("NetCoreDebug >> "+str); @@ -76,7 +86,7 @@ namespace AxibugEmuOnline.Client.Network /// 协议ID /// 错误编号 /// 业务数据 - public void GetDataCallBack(int CMDID, int ERRCODE, byte[] data) + void GetDataCallBack(int CMDID, int ERRCODE, byte[] data) { //NetworkDeBugLog("收到消息 CMDID =>" + CMDID + " ERRCODE =>" + ERRCODE + " 数据长度=>" + data.Length); try @@ -86,7 +96,7 @@ namespace AxibugEmuOnline.Client.Network if (CMDID <= (int)CommandID.CmdPong) NetMsg.Instance.PostNetMsgEvent(CMDID, ERRCODE, data); else//加入队列,主线程来取 - NetMsg.Instance.EnqueueNesMsg(CMDID, ERRCODE, data); + NetMsg.Instance.EnqueueNetMsg(CMDID, ERRCODE, data); } catch (Exception ex) { @@ -97,7 +107,7 @@ namespace AxibugEmuOnline.Client.Network /// /// 关闭连接 /// - public void OnConnectClose() + void OnConnectClose_Delegate() { NetworkDeBugLog("OnConnectClose"); Eventer.Instance.PostEvent(EEvent.OnLossLoginState);