Ejemplo n.º 1
0
        /// <summary>
        /// Checks if packet is displayed in packet list.
        /// </summary>
        /// <param name="packet">Packet to check.</param>
        /// <returns>True if visible, false otherwise.</returns>
        public bool IsDisplayed(UltimaPacket packet)
        {
            UltimaPacketFilterTable  table      = Table;
            UltimaPacketFilterTable  childTable = null;
            IUltimaPacketFilterEntry item       = null;
            int i = 0;

            do
            {
                item       = table[packet.Data[i++]];
                childTable = item as UltimaPacketFilterTable;

                if (childTable != null)
                {
                    if (!childTable.IsChecked)
                    {
                        return(false);
                    }

                    table = childTable;
                }
            }while (childTable != null);

            UltimaPacketFilterEntry entry = item as UltimaPacketFilterEntry;

            if (entry != null)
            {
                return(entry.IsVisible && entry.IsChecked && entry.IsDisplayed(packet));
            }

            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructs a new instance of UltimaPacketFilterTable.
        /// </summary>
        /// <param name="definition">Table definition.</param>
        /// <param name="owner">Owner.</param>
        /// <param name="parent">Table parent.</param>
        /// <param name="index">Table index.</param>
        public UltimaPacketFilterTable(UltimaPacketTable definition, UltimaPacketFilter owner = null, UltimaPacketFilterTable parent = null, int index = -1)
        {
            _Definition = definition;
            _Owner      = owner;
            _Parent     = parent;
            Index       = index;

            if (parent == null)
            {
                IsVisible = true;
            }

            // Initialize children
            IsBusy = true;

            if (definition != null)
            {
                _Children = new IUltimaPacketFilterEntry[definition.Length];

                for (int i = 0; i < definition.Length; i++)
                {
                    object item = definition[i];

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

                        if (entry != null)
                        {
                            if (entry.FromServer != null)
                            {
                                _Children[i] = new UltimaPacketFilterEntry(entry.FromServer, owner, this, i);
                            }
                            else if (entry.FromClient != null)
                            {
                                _Children[i] = new UltimaPacketFilterEntry(entry.FromClient, owner, this, i);
                            }
                            else
                            {
                                _Children[i] = new UltimaPacketFilterEntry(null, owner, this, i);
                            }
                        }
                        else
                        {
                            _Children[i] = new UltimaPacketFilterTable((UltimaPacketTable)item, owner, this, i);
                        }
                    }
                    else
                    {
                        _Children[i] = new UltimaPacketFilterEntry(null, owner, this, i);
                    }
                }
            }
            else
            {
                _Children = new IUltimaPacketFilterEntry[Byte.MaxValue + 1];
            }

            IsBusy = false;
        }
Ejemplo n.º 3
0
        private static void IsChecked_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            UltimaPacketFilterTable table = d as UltimaPacketFilterTable;

            if (table != null && !table.IsBusy)
            {
                table.UpdateIsChecked();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes filter structure.
        /// </summary>
        public void Initialize()
        {
            UltimaPacketTable table = UltimaPacket.PacketTable;

            if (table == null)
            {
                throw new SpyException("Y U NO initialize packet definitions");
            }

            Table = new UltimaPacketFilterTable(table, this);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Constructs a new instance of UltimaPacketFilterEntry.
        /// </summary>
        /// <param name="owner">Owner.</param>
        /// <param name="parent">Entry parent.</param>
        /// <param name="index">Entry index.</param>
        /// <param name="definition">Packet definition.</param>
        public UltimaPacketFilterEntry(UltimaPacketDefinition definition, UltimaPacketFilter owner, UltimaPacketFilterTable parent, int index)
        {
            _Definition = definition;
            _Owner      = owner;
            _Parent     = parent;
            Index       = index;

            if (definition != null)
            {
                IsVisible = true;
                IsChecked = true;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Loads entry from stream.
        /// </summary>
        /// <param name="reeader">Reader to read from.</param>
        public void Load(BinaryReader reader)
        {
            try
            {
                // Supress changed event
                _IsBusy = true;

                // Read
                if (_Parent == null)
                {
                    reader.ReadBoolean();
                }

                IsVisible = reader.ReadBoolean();
                IsChecked = reader.ReadBoolean();

                foreach (IUltimaPacketFilterEntry o in _Children)
                {
                    bool type = reader.ReadBoolean();

                    if (type)
                    {
                        UltimaPacketFilterTable table = o as UltimaPacketFilterTable;

                        if (table == null)
                        {
                            table = new UltimaPacketFilterTable(null, null, null, -1);                               // Dummy
                        }
                        table.Load(reader);
                    }
                    else
                    {
                        UltimaPacketFilterEntry entry = o as UltimaPacketFilterEntry;

                        if (entry == null)
                        {
                            entry = new UltimaPacketFilterEntry(null, null, null, -1);                               // Dummy
                        }
                        entry.Load(reader);
                    }
                }
            }
            finally
            {
                _IsBusy = false;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Constructs a new instance of UltimaPacketFilterTable.
        /// </summary>
        /// <param name="definition">Table definition.</param>
        /// <param name="owner">Owner.</param>
        /// <param name="parent">Table parent.</param>
        /// <param name="index">Table index.</param>
        public UltimaPacketFilterTable( UltimaPacketTable definition, UltimaPacketFilter owner = null, UltimaPacketFilterTable parent = null, int index = - 1 )
        {
            _Definition = definition;
            _Owner = owner;
            _Parent = parent;
            Index = index;

            if ( parent == null )
                IsVisible = true;

            // Initialize children
            IsBusy = true;

            if ( definition != null )
            {
                _Children = new IUltimaPacketFilterEntry[ definition.Length ];

                for ( int i = 0; i < definition.Length; i++ )
                {
                    object item = definition[ i ];

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

                        if ( entry != null )
                        {
                            if ( entry.FromServer != null )
                                _Children[ i ] = new UltimaPacketFilterEntry( entry.FromServer, owner, this, i );
                            else if ( entry.FromClient != null )
                                _Children[ i ] = new UltimaPacketFilterEntry( entry.FromClient, owner, this, i );
                            else
                                _Children[ i ] = new UltimaPacketFilterEntry( null, owner, this, i );
                        }
                        else
                            _Children[ i ] = new UltimaPacketFilterTable( (UltimaPacketTable) item, owner, this, i );
                    }
                    else
                        _Children[ i ] = new UltimaPacketFilterEntry( null, owner, this, i );
                }
            }
            else
                _Children = new IUltimaPacketFilterEntry[ Byte.MaxValue + 1 ];

            IsBusy = false;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Checks if packet is displayed in packet list.
        /// </summary>
        /// <param name="packet">Packet to check.</param>
        /// <returns>True if visible, false otherwise.</returns>
        public bool IsDisplayed(UltimaPacket packet)
        {
            UltimaPacketFilterTable  table      = Table;
            UltimaPacketFilterTable  childTable = null;
            IUltimaPacketFilterEntry item       = null;
            int i = 0;


            //the filter is now correctly filtering the subcommands but this is the best way to find cmd.subcmd[.subsubcmd]
            string[] sids = packet.Ids.Split('.');
            byte[]   ids  = new byte[sids.Length];
            foreach (string s in sids)
            {
                ids[i++] = Convert.ToByte(s.Substring(0, 2), 16);
            }

            i = 0;
            do
            {
                item       = table[ids[i++]];
                childTable = item as UltimaPacketFilterTable;

                if (childTable != null)
                {
                    if (childTable.IsChecked)
                    {
                        return(true);
                    }

                    table = childTable;
                }
            }while (childTable != null && i < ids.Length);

            UltimaPacketFilterEntry entry = item as UltimaPacketFilterEntry;

            if (entry != null)
            {
                return(entry.IsVisible && entry.IsChecked && entry.IsDisplayed(packet));
            }

            return(false);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Loads entry from stream.
        /// </summary>
        /// <param name="reeader">Reader to read from.</param>
        public void Load( BinaryReader reader )
        {
            try
            {
                // Supress changed event
                _IsBusy = true;

                // Read
                if ( _Parent == null )
                    reader.ReadBoolean();

                IsVisible = reader.ReadBoolean();
                IsChecked = reader.ReadBoolean();

                foreach ( IUltimaPacketFilterEntry o in _Children )
                {
                    bool type = reader.ReadBoolean();

                    if ( type )
                    {
                        UltimaPacketFilterTable table = o as UltimaPacketFilterTable;

                        if ( table == null )
                            table = new UltimaPacketFilterTable( null, null, null, -1 ); // Dummy

                        table.Load( reader );
                    }
                    else
                    {
                        UltimaPacketFilterEntry entry = o as UltimaPacketFilterEntry;

                        if ( entry == null )
                            entry = new UltimaPacketFilterEntry( null, null, null, -1 ); // Dummy

                        entry.Load( reader );
                    }
                }
            }
            finally
            {
                _IsBusy = false;
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Initializes filter structure.
        /// </summary>
        public void Initialize()
        {
            UltimaPacketTable table = UltimaPacket.PacketTable;

            if ( table == null )
                throw new SpyException( "Y U NO initialize packet definitions" );

            Table = new UltimaPacketFilterTable( table, this );
        }