/// <summary> /// 接收消息回调函数 /// </summary> private void OnHandleHotfixMsg(INetworkPackage pack) { DefaultNetworkPackage package = pack as DefaultNetworkPackage; Type msgType = _types.GetValueByKey(package.MsgID); HotfixLogger.Log($"Handle hotfix net message : {msgType}"); object instance = Activator.CreateInstance(msgType); var message = ProtobufHelper.Decode(instance, package.BodyBytes); HotfixLogger.Log(message.ToString()); }
public static object Process(BufferReader reader) { byte tmpFirst = 0, tmpSecond = 0; reader.Read(ref tmpFirst).Read(ref tmpSecond); ushort tmpOpcode = tmpFirst; tmpOpcode <<= 8; tmpOpcode |= tmpSecond; Type tmpType = sCommandOpcode2TypeDict.GetValueByKey(tmpOpcode); if (null == tmpType) { Logger.LogErrorFormat("找不到相应的协议包. first:{0} second:{1}", tmpFirst, tmpSecond); return(null); } object tmpCommand = null; try { tmpCommand = Deserialize(reader, tmpType); } catch (Exception ex) { Logger.LogErrorFormat("协议反序列化异常. type:[0] 异常信息:{1}", tmpType, ex.Message); } if (null != tmpCommand) { List <MethodInfo> tmpMethodInfoList = null; if (sOpcode2MethodInfosDict.TryGetValue(tmpOpcode, out tmpMethodInfoList)) { sParameterObjs[0] = tmpCommand; for (int i = 0, max = tmpMethodInfoList.Count; i < max; ++i) { MethodInfo tmpMethodInfo = tmpMethodInfoList[i]; tmpMethodInfoList[i].Invoke(null, sParameterObjs); } } } return(tmpCommand); }
/// <summary> /// 接收消息回调函数 /// </summary> private void OnHandleHotfixMsg(NetReceivePackage package) { Type msgType = _msgTypes.GetValueByKey(package.Type); object instance = Activator.CreateInstance(msgType); var message = ProtobufHelper.Decode(instance, package.ProtoBodyData); Debug.Log($"Handle net message : {package.Type}"); // TODO 可以在这里分发消息到逻辑层 R2C_Login loginMsg = message as R2C_Login; if (loginMsg != null) { Debug.Log($"R2C_Login = {loginMsg.Address}"); Debug.Log($"R2C_Login = {loginMsg.Key}"); } }