/// <summary> /// Adds or removes port from this rule area /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void udpWhiteListInputOut_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { string input = udpWhiteListInputOut.Text; udpWhiteListInputOut.Text = ""; int port = 0; if (int.TryParse(input, out port)) { BasicFirewall.Rule found = null; foreach (BasicFirewall.Rule r in rules) { if (r.transport == Protocol.UDP) { if (r.Set == BasicFirewall.PacketStatus.ALLOWED && (r.Port == port || r.Port == -1) && (r.Direction & 0x2) == 0x2) { found = r; udpWhiteListPortOut.Items.Remove(port); break; } } } if (found != null) { rules.Remove(found); } else { rules.Insert(0, new BasicFirewall.Rule(BasicFirewall.PacketStatus.ALLOWED, port, Protocol.UDP, false, false, null, 0x2)); udpWhiteListPortOut.Items.Add(port); } } } }
/// <summary> /// Adds or removes port from this rule area /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void udpDoNotNotifyInputOut_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { string input = udpDoNotNotifyInputOut.Text; udpDoNotNotifyInputOut.Text = ""; int port = 0; if (int.TryParse(input, out port)) { BasicFirewall.Rule found = null; BasicFirewall.Rule lastTCP = null; foreach (BasicFirewall.Rule r in rules) { if (r.transport == Protocol.UDP && (r.Direction & 0x2) == 0x2) { if (r.Port == port) { found = r; r.Notify = false; udpDoNotNotifyOut.Items.Remove(port); } else if (r.doNotNotifyOutgoing.Contains(port)) { r.doNotNotifyOutgoing.Remove(port); udpDoNotNotifyOut.Items.Remove(port); found = r; } lastTCP = r; } } if (found == null) { lastTCP.doNotNotifyOutgoing.Add(port); udpDoNotNotifyOut.Items.Add(port); } } } }