示例#1
0
        /// <summary>
        /// Tries to register packet by UltimaPacketAttribute.
        /// </summary>
        /// <param name="packetType">Type to register.</param>
        /// <param name="packetIds">Packet IDs.</param>
        /// <param name="index">Current packet ID index.</param>
        public void RegisterPacket(Type packetType, UltimaPacketAttribute packet, int index)
        {
            byte   id   = packet.Ids[index];
            object item = _Table[id];

            if (packet.Ids.Length - 1 == index)
            {
                UltimaPacketTableEntry entry = item as UltimaPacketTableEntry;

                if (item is UltimaPacketTable)
                {
                    throw new SpyException("Packet '{0}' is missing one or more IDs", packetType);
                }

                if (entry == null)
                {
                    entry = new UltimaPacketTableEntry();
                }

                if (packet.Direction == UltimaPacketDirection.FromClient)
                {
                    if (entry.FromClient != null)
                    {
                        throw new SpyException("Packet from client with ID '{0}' already exists", id);
                    }

                    entry.FromClient = new UltimaPacketDefinition(packetType, packet);
                }
                else if (packet.Direction == UltimaPacketDirection.FromServer)
                {
                    if (entry.FromServer != null)
                    {
                        throw new SpyException("Packet from server with ID '{0}' already exists", id);
                    }

                    entry.FromServer = new UltimaPacketDefinition(packetType, packet);
                }
                else if (packet.Direction == UltimaPacketDirection.FromBoth)
                {
                    if (entry.FromClient != null)
                    {
                        throw new SpyException("Packet from client with ID '{0}' already exists", id);
                    }
                    else if (entry.FromServer != null)
                    {
                        throw new SpyException("Packet from server with ID '{0}' already exists", id);
                    }

                    entry.FromClient = new UltimaPacketDefinition(packetType, packet);
                    entry.FromServer = entry.FromClient;
                }

                _Table[id] = entry;
            }
            else if (item is UltimaPacketTable)
            {
                UltimaPacketTable table = (UltimaPacketTable)item;
                table.RegisterPacket(packetType, packet, index + 1);
            }
            else
            {
                throw new SpyException("Table for Packet '{0}' not defined", packetType);
            }
        }
示例#2
0
        /// <summary>
        /// Tries to register packet by UltimaPacketAttribute.
        /// </summary>
        /// <param name="packetType">Type to register.</param>
        /// <param name="packetIds">Packet IDs.</param>
        /// <param name="index">Current packet ID index.</param>
        public void RegisterPacket( Type packetType, UltimaPacketAttribute packet, int index )
        {
            byte id = packet.Ids[ index ];
            object item = _Table[ id ];

            if ( packet.Ids.Length - 1 == index )
            {
                UltimaPacketTableEntry entry = item as UltimaPacketTableEntry;

                if ( item is UltimaPacketTable )
                    throw new SpyException( "Packet '{0}' is missing one or more IDs", packetType );

                if ( entry == null )
                    entry = new UltimaPacketTableEntry();

                if ( packet.Direction == UltimaPacketDirection.FromClient )
                {
                    if ( entry.FromClient != null )
                        throw new SpyException( "Packet from client with ID '{0}' already exists", id );

                    entry.FromClient = new UltimaPacketDefinition( packetType, packet );
                }
                else if ( packet.Direction == UltimaPacketDirection.FromServer )
                {
                    if ( entry.FromServer != null )
                        throw new SpyException( "Packet from server with ID '{0}' already exists", id );

                    entry.FromServer = new UltimaPacketDefinition( packetType, packet );
                }
                else if ( packet.Direction == UltimaPacketDirection.FromBoth )
                {
                    if ( entry.FromClient != null )
                        throw new SpyException( "Packet from client with ID '{0}' already exists", id );
                    else if ( entry.FromServer != null )
                        throw new SpyException( "Packet from server with ID '{0}' already exists", id );

                    entry.FromClient = new UltimaPacketDefinition( packetType, packet );
                    entry.FromServer = entry.FromClient;
                }

                _Table[ id ] = entry;
            }
            else if ( item is UltimaPacketTable )
            {
                UltimaPacketTable table = (UltimaPacketTable) item;
                table.RegisterPacket( packetType, packet, index + 1 );
            }
            else
                throw new SpyException( "Table for Packet '{0}' not defined", packetType );
        }
示例#3
0
        /// <summary>
        /// Gets packet info based on packet header.
        /// </summary>
        /// <param name="data">Packet data.</param>
        /// <param name="fromClient">Packet direction.</param>
        /// <param name="id">Last packet id.</param>
        /// <param name="ids">All packet ids.</param>
        /// <returns>Packet definition if exists, null otherwise.</returns>
        public UltimaPacketDefinition GetPacket(byte[] data, bool fromClient, ref byte id, ref string ids)
        {
            UltimaPacketTable table = this;
            int offset = 0;

            while (table != null)
            {
                id = data[offset];
                object item = table[id];

                if (ids == null)
                {
                    ids = id.ToString("X2");
                }
                else
                {
                    ids = ids + "." + id.ToString("X2");
                }

                if (item != null)
                {
                    UltimaPacketTableEntry entry = item as UltimaPacketTableEntry;

                    if (entry != null && (
                            (fromClient && entry.FromClient != null) ||
                            (!fromClient && entry.FromServer != null)))
                    {
                        // Found packet definition

                        if (fromClient)
                        {
                            return(entry.FromClient);
                        }
                        else
                        {
                            return(entry.FromServer);
                        }
                    }
                    else if (entry == null)
                    {
                        // Need to look in mordor
                        offset += (((UltimaPacketTable)item).Word ? 2 : 1);
                        table   = (UltimaPacketTable)item;
                        offset += table.Offset;
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    //// Unknown packet, subcommands may appear even if the packet doesnt have any
                    //if ( ids == null )
                    //    ids = id.ToString( "X2" );
                    //else
                    //    ids = ids + "." + id.ToString( "X2" );

                    return(null);
                }
            }

            // Panic at the disco
            return(null);
        }