Ejemplo n.º 1
0
        /// <summary>
        /// Checks all types in executing assmebly and registers packets.
        /// </summary>
        public static void RegisterPackets()
        {
            // Load tables
            LoadTables("Data\\PacketTables.xml");

            // Load packets
            Type[] types = Assembly.GetExecutingAssembly().GetTypes();

            foreach (Type type in types)
            {
                UltimaPacketAttribute[] attrs = (UltimaPacketAttribute[])type.GetCustomAttributes(typeof(UltimaPacketAttribute), false);

                if (attrs.Length == 1)
                {
                    UltimaPacketAttribute ultimaPacket = attrs[0];

                    if (ultimaPacket.Ids == null || ultimaPacket.Ids.Length == 0)
                    {
                        throw new SpyException("Packet {0} must have at least one ID", type);
                    }

                    _PacketTable.RegisterPacket(type, ultimaPacket, 0);
                }
                else if (attrs.Length > 1)
                {
                    throw new SpyException("Class {0} has too many UltimaPacket attributes", type);
                }
            }

            _DefaultDefinition = new UltimaPacketDefinition(typeof(UltimaPacket), null);
        }
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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Checks all types in executing assmebly and registers packets.
        /// </summary>
        public static void RegisterPackets()
        {
            // Load tables
            LoadTables( "Data\\PacketTables.xml" );

            // Load packets
            Type[] types = Assembly.GetExecutingAssembly().GetTypes();

            foreach ( Type type in types )
            {
                UltimaPacketAttribute[] attrs = (UltimaPacketAttribute[]) type.GetCustomAttributes( typeof( UltimaPacketAttribute ), false );

                if ( attrs.Length == 1 )
                {
                    UltimaPacketAttribute ultimaPacket = attrs[ 0 ];

                    if ( ultimaPacket.Ids == null || ultimaPacket.Ids.Length == 0 )
                        throw new SpyException( "Packet {0} must have at least one ID", type );

                    _PacketTable.RegisterPacket( type, ultimaPacket, 0 );
                }
                else if ( attrs.Length > 1 )
                {
                    throw new SpyException( "Class {0} has too many UltimaPacket attributes", type );
                }
            }

            _DefaultDefinition = new UltimaPacketDefinition( typeof( UltimaPacket ), null );
        }