public static void Broadcast(ref RawNetworkMessage msg) { if (LogUtil.ShowDebug != null && LogUtil.ShowError != null) { LogUtil.ShowError("[网络消息中心][接收]" + msg.ToString()); } NetworkMessageCentralHub.Instance.DeliverMessage(ref msg); }
public virtual void DeliverMessage(ref RawNetworkMessage msg) { //msg.TimeStamp = DateTimeUtil.NowMillisecond; List <NetworkMessageHandler> tmpList; if (messageHandlerTable.TryGetValue(msg.Identity, out tmpList)) { if (tmpList.Count > 0) { // 因为不允许相同消息使用不同结构体,所以随便取一个Handler里面的消息类型做反序列化即可 Type msgType = tmpList[0].messageType; INetworkMessage msgInstance = (INetworkMessage)Activator.CreateInstance(msgType); ReflectionUtil.Deserialize(msgInstance, new BitConverterEx(msg.Content, 0, true), false); for (int i = 0; i < tmpList.Count; ++i) { Invoke(tmpList[i], msgInstance); } } } //else //{ // LogUtil.ShowWarning(string.Format("网络消息[{0}-{1}]没有模块处理", msg.ClassID, msg.FunctionID)); //} }