private void EditButton_Click(object sender, RoutedEventArgs e) { try { FrameworkElement element = sender as FrameworkElement; if (element == null) { return; } UltimaPacketFilterEntry entry = element.Tag as UltimaPacketFilterEntry; if (entry == null) { return; } FilterPropertiesEditor editor = new FilterPropertiesEditor(); editor.Entry = entry; editor.ShowDialog(); } catch (Exception ex) { Trace.WriteLine(ex); } }
/// <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) { UltimaPacketFilterEntry entry = d as UltimaPacketFilterEntry; if (entry != null) { entry.UpdateIsChecked(); } }
private static void Properties_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e) { UltimaPacketFilterEntry entry = d as UltimaPacketFilterEntry; if (entry != null && entry.Owner != null) { entry.Owner.OnChange(); } }
/// <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; } }
private void UpdateEntry() { UltimaPacketFilterEntry entry = Entry; if (entry == null) { DataContext = null; Filters.DataContext = null; return; } DataContext = entry; // Clone filter properties Properties = new List <UltimaPacketFilterProperty>(); if (entry.Properties != null) { foreach (UltimaPacketFilterProperty property in entry.Properties) { Properties.Add(property.Clone()); } } Filters.ItemsSource = null; Filters.ItemsSource = Properties; if (Properties.Count > 0) { Filters.SelectedIndex = 0; } // Get available properties List <UltimaPacketPropertyDefinition> availableProperties = new List <UltimaPacketPropertyDefinition>(); foreach (UltimaPacketPropertyDefinition definition in Entry.Definition.Properties) { if (UltimaPacketFilterParser.GetTypeOperations(definition) != null) { availableProperties.Add(definition); } } Definition.ItemsSource = availableProperties; }
/// <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); }
/// <summary> /// Constructs a new instance of UltimaPacketFilterProperty. /// </summary> /// <param name="parent">Property parent.</param> public UltimaPacketFilterProperty(UltimaPacketFilterEntry parent) { _Parent = parent; }