/// <summary> /// Constructs packet based on packet IDs. /// </summary> /// <param name="data">Data client sent or received.</param> /// <param name="fromClient">Determines whehter the client sent or received data.</param> /// <param name="time">Date and time packet was received.</param> /// <returns>Ultima packet.</returns> public static UltimaPacket ConstructPacket(byte[] data, bool fromClient, DateTime time) { byte id = 0; string ids = null; UltimaPacketDefinition definition = PacketTable.GetPacket(data, fromClient, ref id, ref ids); UltimaPacket packet = null; if (definition == null) { definition = DefaultDefinition; packet = new UltimaPacket(); } else { packet = definition.Constructor(); } packet.Definition = definition; packet.Data = data; packet.FromClient = fromClient; packet.DateTime = time; packet.ID = id; packet.Ids = ids; if (definition.Attribute != null) { packet.Name = definition.Attribute.Name; } else { packet.Name = "Unknown Packet"; } using (MemoryStream stream = new MemoryStream(data)) { packet.Parse(new BigEndianReader(stream)); } return(packet); }