private void InitializePacket(uint opcode, PacketType packetType, DataStream ds) { if (OnPacketReceive != null) { OnPacketReceive(this, new PacketReceiveEventArgs(new PacketIdentifier(opcode, packetType), ds)); ds.Reset(); } Type type = null; if (packetType == PacketType.ServerPacket) { type = PacketsRegistry.GetPacket(opcode); } if (packetType == PacketType.ServerContainer) { type = PacketsRegistry.GetContainer(opcode); } if (type == null) { return; } GamePacket packet; try { packet = DataStreamSerializer.Deserialize(ds, type) as GamePacket; } catch { return; } packet.HandleData(Data); packetHandler.Handle(packet); }
public void Send(GamePacket packet) { if (Connection.IsWork) { Type type = packet.GetType(); object[] attributes = type.GetCustomAttributes(typeof(PacketIdentifier), false); if (attributes.Length == 0) { throw new Exception("Unknown type"); } PacketIdentifier packetId = attributes[0] as PacketIdentifier; if (packetId.PacketType == PacketType.Unknown) { throw new Exception("Unknown pack"); } packet.HandleData(Data); DataStream packetStream = new DataStream(); if (packetId.PacketType != PacketType.ClientContainer ) { packetStream.IsSwaped = true; } DataStreamSerializer.Serialize(packet, packetStream); Send(packetId.PacketId, packetStream.GetBytes(), packetId.PacketType); } }