public override bool Initialize(Int32 _stream_id, NetPacket _packet) { m_stream_id = _stream_id; m_packet = _packet; if (_packet.Data == null) { m_message = new TyMessage(); } else { m_message = SerializerHelper.Deserializer <TyMessage>(_packet.Data); } return(true); }
public override bool Initialize(Int32 _stream_id, NetPacket _packet) { m_stream_id = _stream_id; m_packet_type = _packet.PacketType; if (_packet.Data == null) { m_message = new TyMessage(); } else { m_message = SerializerHelper.Deserializer <TyMessage>(_packet.Data); } Utility.Log.Info("收到消息{0}", m_message.ToString()); return(true); }
/// <summary> /// /// </summary> /// <param name="_stream_id"></param> /// <param name="_packet"></param> private void _onPacketArrived(Int32 _stream_id, NetPacket _packet) { try { Int32 packet_id = 0; MessageBase msg = null; switch (_packet.PacketType) { case PacketType.Connected: //packet_id = ConnectMsg.MyMessageId; packet_id = Helper.GenerateInt32(ConnectMsg.Type, ConnectMsg.Dir, ConnectMsg.MessageId); break; case PacketType.Disconnected: //packet_id = DisconnectMsg.MyMessageId; packet_id = Helper.GenerateInt32(DisconnectMsg.Type, DisconnectMsg.Dir, DisconnectMsg.MessageId); break; case PacketType.Message: msg = SerializerHelper.Deserializer <MessageBase>(_packet.Data); packet_id = Helper.GenerateInt32(msg.MsgType, msg.MsgDirection, msg.MsgId); break; case PacketType.Error: throw new Exception("Got error packet"); default: throw new ArgumentOutOfRangeException(); } NetPacketEvent packet_event = _createEvent(packet_id); if (null == packet_event) { Utility.Log.Warning("Received a packet dir={0} type={1} id={2} that isn't register with any handler.", msg.MsgDirection, msg.MsgType, msg.MsgId); return; } if (!packet_event.Initialize(_stream_id, _packet)) { Utility.Log.Error("Failed to initialize packet {0}.", packet_id); return; } GameApp.Instance.PushEvent(packet_event); } catch (Exception e) { Log.Error("[NetPacketEvent]Failed to process the arrived packet: {0}", e.Message); } }