Example #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);
        }
        /// <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;
        }
        private static void IsChecked_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            UltimaPacketFilterTable table = d as UltimaPacketFilterTable;

            if (table != null && !table.IsBusy)
            {
                table.UpdateIsChecked();
            }
        }
Example #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);
        }
Example #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;
            }
        }
        /// <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;
            }
        }
Example #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;
        }
Example #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);
        }
Example #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;
            }
        }
Example #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 );
        }