/// <summary> /// 处理消息 /// 逻辑层需要在Update里调用这个接口,以处理接收消息 /// </summary> public void ExecuteMessages() { if (m_tcpClient == null) { return; } //UnityEngine.Profiling.Profiler.BeginSample("CMoniBehaviour > ExecuteMessages"); CSLib.Framework.CMsgBuffInfoQueue msgBuffInfoQueue = m_tcpClient.GetMsgBuffInfoQueue(m_uEchoID); while (msgBuffInfoQueue.Count > 0) { CSLib.Framework.CMessageLabel msgLabel = new CSLib.Framework.CMessageLabel(); CSLib.Framework.CMsgBuffInfo msgBuffInfo = msgBuffInfoQueue.Dequeue(); // 执行后 msgLabel.Id 才会被赋值 if (!ExecuteMessage(msgLabel, msgBuffInfo.MsgBuff, msgBuffInfo.MsgSize)) { UDLib.Utility.CDebugOut.LogError("ExecuteMessages : 消息执行错误"); } #if DEBUG CSLib.Framework.CNetMessage msgResult = (CSLib.Framework.CNetMessage)msgLabel.MsgObject; byte tmpServer = CSLib.Utility.CBitHelper.GetHighUInt8(msgResult.MsgType); byte tmpFunc = CSLib.Utility.CBitHelper.GetLowUInt8(msgResult.MsgType); m_recvStatisticsNum.AddNum(tmpServer.ToString() + " -> " + tmpFunc.ToString()); #endif } //UnityEngine.Profiling.Profiler.EndSample(); }
// private void _OnMsgTestReqSay(CSLib.Framework.CMessageLabel msgLabel, CSLib.Framework.CMessage msg) { Message.CMsgSampleReqSay reqSay = (Message.CMsgSampleReqSay)msg; Console.WriteLine("收到:" + reqSay.m_string + "{" + m_netStub.LocalIPEndPoint.ToString() + "<---" + m_netStub.PeerIPEndPoint.ToString() + "}"); Message.CMsgSampleResSay resSay = new Message.CMsgSampleResSay(); resSay.m_string = "Sever No.["; resSay.m_string += m_number.ToString(); resSay.m_string += "]"; resSay.m_bool = reqSay.m_bool; resSay.m_byte = reqSay.m_byte; resSay.m_bytes = reqSay.m_bytes; resSay.m_double = reqSay.m_double; resSay.m_float = reqSay.m_float; resSay.m_int = reqSay.m_int; resSay.m_long = reqSay.m_long; resSay.m_short = reqSay.m_short; resSay.m_uint = reqSay.m_uint; resSay.m_ulong = reqSay.m_ulong; resSay.m_ushort = reqSay.m_ushort; m_number++; CSLib.Utility.CStream streamRes = new CSLib.Utility.CStream(); resSay.Serialize(streamRes); m_netStub.SendAsync(streamRes); }
public bool ParseMsg(byte[] msgBuff, int msgSize) { CSLib.Framework.CMessageLabel msgLabel = new CSLib.Framework.CMessageLabel(); if (!m_msgExecute.ExecuteMessage(msgLabel, msgBuff, msgSize)) { Console.WriteLine("解析消息失败"); return(false); } return(true); }
/// <summary> /// 这里设置成 virtual 接口,就是给上层一个截获消息机会,方便用其他方式来处理消息 /// </summary> /// <param name="msgLabel"></param> /// <param name="msgBuff"></param> /// <param name="msgSize"></param> /// <returns></returns> virtual protected bool ExecuteMessage(CSLib.Framework.CMessageLabel msgLabel, Byte[] msgBuff, Int32 msgSize) { bool ret = m_msgExecute.ExecuteMessage(msgLabel, msgBuff, msgSize); // 处理完收到的消息,更新已收到的最大response消息号,用于作为断线重连的开始位置 if (msgLabel.ResIndex != 0) { UDLib.Utility.CDebugOut.Log("收到系统消息,更新断线重连位置 : ResIndex = " + msgLabel.ResIndex); CReconnectMgr.Instance.LatestResIndex = msgLabel.ResIndex; } return(ret); }
protected override Boolean _CbParseMsg(Byte[] msgBuff, Int32 msgSize) { CSLib.Framework.CMessageLabel msgLabel = CSLib.Framework.CMsgFactory.Instance.CreateMsg(msgBuff, msgSize); if (msgLabel == null) { return(true); } CSLib.Framework.CNetMessage theMsg = (CSLib.Framework.CNetMessage)(msgLabel.MsgObject); // 删除发送时做的消息缓存,判空应对一些不规范的返回(GM命令系统返回是空) if (theMsg != null) { m_dicDelayedMsg.DelObject(theMsg.UniqueID); } // ack 的 response不做解析和向服务器发送ack if (theMsg != null && theMsg.Func == CReconnectMgr.EFUNC_MESSAGESYSTEM) { #if DEBUG UDLib.Utility.CDebugOut.Log("收到ack消息, 从消息重发队列移除消息 > reqIndex : " + theMsg.GetReqIndex()); #endif m_cacheMessage.RemoveCacheMessageByReqIndex(msgLabel.ReqIndex); return(true); } // 根据这边的 Index 数据,发送 Ack 信息, 排除心跳为0 if (msgLabel.ResIndex != 0) { // 10 Gateway, 5 ACK系统号, 2 客户端发送给服务的消息号,在逻辑层的proto定义,底层无法获取,这里用直接用数字了 UDLib.Network.CBufMessage netMessage = new UDLib.Network.CBufMessage(10, 5, 2); netMessage.SetReqIndex(0); netMessage.SetResIndex(msgLabel.ResIndex); #if DEBUG UDLib.Utility.CDebugOut.Log("收到系统消息消息, 给服务器发送ACK确认 : " + msgLabel.ResIndex); #endif CSLib.Utility.CStream msgStream = new CSLib.Utility.CStream();; netMessage.Serialize(msgStream); SendAsync(msgStream); } base._CbParseMsg(msgBuff, msgSize); return(true); }
private void _OnMsgTestResSay(CSLib.Framework.CMessageLabel msgLabel, CSLib.Framework.CMessage msg) { Message.CMsgSampleResSay resSay = (Message.CMsgSampleResSay)msg; Console.WriteLine("收到:" + resSay.m_string + resSay.m_bool + " " + resSay.m_byte + " " + resSay.m_bytes[0] + " " + resSay.m_bytes[1] + " " + resSay.m_bytes[2] + " " + resSay.m_bytes[3] + " " + resSay.m_bytes[4] + " " + resSay.m_double + " " + resSay.m_float + " " + resSay.m_int + " " + resSay.m_long + " " + resSay.m_short + " " + resSay.m_uint + " " + resSay.m_ulong + " " + resSay.m_ushort); }
private void _OnMsgTestNtfOk(CSLib.Framework.CMessageLabel msgLabel, CSLib.Framework.CMessage msg) { ; }