Esempio n. 1
0
        /// <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);
        }