Encryption Keys for headsets (#12615)
This commit is contained in:
23
Content.Shared/Radio/EncryptionKeyComponent.cs
Normal file
23
Content.Shared/Radio/EncryptionKeyComponent.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Content.Shared.Radio;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||
|
||||
namespace Content.Server.Radio.Components;
|
||||
/// <summary>
|
||||
/// This component is currently used for providing access to channels for "HeadsetComponent"s.
|
||||
/// It should be used for intercoms and other radios in future.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class EncryptionKeyComponent : Component
|
||||
{
|
||||
[DataField("channels", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<RadioChannelPrototype>))]
|
||||
public HashSet<string> Channels = new();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This variable defines what channel will be used with using ":h" (department channel prefix).
|
||||
/// Headset read DefaultChannel of first encryption key installed.
|
||||
/// </summary>
|
||||
[DataField("defaultChannel", customTypeSerializer: typeof(PrototypeIdSerializer<RadioChannelPrototype>))]
|
||||
public readonly string? DefaultChannel;
|
||||
}
|
||||
55
Content.Shared/Radio/EncryptionKeySystem.cs
Normal file
55
Content.Shared/Radio/EncryptionKeySystem.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using Content.Server.Radio.Components;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Radio;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Radio.EntitySystems;
|
||||
|
||||
public sealed class EncryptionKeySystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _protoManager = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<EncryptionKeyComponent, ExaminedEvent>(OnExamined);
|
||||
}
|
||||
|
||||
private void OnExamined(EntityUid uid, EncryptionKeyComponent component, ExaminedEvent args)
|
||||
{
|
||||
if (!args.IsInDetailsRange)
|
||||
return;
|
||||
if(component.Channels.Count > 0)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("examine-encryption-key-channels-prefix"));
|
||||
EncryptionKeySystem.GetChannelsExamine(component.Channels, args, _protoManager, "examine-headset-channel");
|
||||
if (component.DefaultChannel != null)
|
||||
{
|
||||
var proto = _protoManager.Index<RadioChannelPrototype>(component.DefaultChannel);
|
||||
args.PushMarkup(Loc.GetString("examine-encryption-key-default-channel", ("channel", component.DefaultChannel), ("color", proto.Color)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A static method for formating list of radio channels for examine events.
|
||||
/// </summary>
|
||||
/// <param name="channels">HashSet of channels in headset, encryptionkey or etc.</param>
|
||||
/// <param name="protoManager">IPrototypeManager for getting prototypes of channels with their variables.</param>
|
||||
/// <param name="channelFTLPattern">String that provide id of pattern in .ftl files to format channel with variables of it.</param>
|
||||
public static void GetChannelsExamine(HashSet<string> channels, ExaminedEvent examineEvent, IPrototypeManager protoManager, string channelFTLPattern)
|
||||
{
|
||||
foreach (var id in channels)
|
||||
{
|
||||
var proto = protoManager.Index<RadioChannelPrototype>(id);
|
||||
string keyCode = "" + proto.KeyCode;
|
||||
if (id != "Common")
|
||||
keyCode = ":" + keyCode;
|
||||
examineEvent.PushMarkup(Loc.GetString(channelFTLPattern,
|
||||
("color", proto.Color),
|
||||
("key", keyCode),
|
||||
("id", proto.LocalizedName),
|
||||
("freq", proto.Frequency)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user