Ejemplo n.º 1
0
        /// <summary>
        /// Constructs a new instance of UltimaPacketValue.
        /// </summary>
        /// <param name="obj">Ultima packet.</param>
        public UltimaPacketValue( UltimaPacket obj )
        {
            _Object = obj;
            _Definition = obj.Definition;
            _Properties = new List<UltimaPacketPropertyValue>();

            foreach ( UltimaPacketPropertyDefinition d in _Definition.Properties )
                _Properties.Add( new UltimaPacketPropertyValue( d, this ) );
        }
Ejemplo n.º 2
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;
        }