Example #1
0
 /// <summary>
 /// Filters incoming packets if that is enabled <see cref="OnBeforeBroadcast"/>
 /// </summary>
 private void OnBeforePacketSent(EntityUid uid, DeviceListComponent component, BeforePacketSentEvent args)
 {
     if (component.HandleIncomingPackets && component.Devices.Contains(args.Sender) != component.IsAllowList)
     {
         args.Cancel();
     }
 }
Example #2
0
    /// <summary>
    /// Filters the broadcasts recipient list against the device list as either an allow or deny list depending on the components IsAllowList field
    /// </summary>
    private void OnBeforeBroadcast(EntityUid uid, DeviceListComponent component, BeforeBroadcastAttemptEvent args)
    {
        //Don't filter anything if the device list is empty
        if (component.Devices.Count == 0)
        {
            if (component.IsAllowList)
            {
                args.Cancel();
            }
            return;
        }

        HashSet <DeviceNetworkComponent> filteredRecipients = new(args.Recipients.Count);

        foreach (var recipient in args.Recipients)
        {
            if (component.Devices.Contains(recipient.Owner) == component.IsAllowList)
            {
                filteredRecipients.Add(recipient);
            }
        }

        args.ModifiedRecipients = filteredRecipients;
    }
 private void OnComponentRemoved(EntityUid uid, DeviceListComponent component, ComponentRemove args)
 {
     _uiSystem.GetUiOrNull(component.Owner, NetworkConfiguratorUiKey.Configure)?.CloseAll();
 }