Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pai with encryption keys #1883

Merged
merged 4 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Content.Server/Radio/Components/IntrinsicRadioReceiverComponent.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using Content.Shared.Radio;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;

namespace Content.Server.Radio.Components;

/// <summary>
Expand All @@ -8,4 +11,11 @@ namespace Content.Server.Radio.Components;
[RegisterComponent]
public sealed partial class IntrinsicRadioReceiverComponent : Component
{
//SS220 PAI with encryption keys begin
/// <summary>
/// Channels that will not be deleted from <see cref="ActiveRadioComponent"/> when extracting the encryption key from the entity
/// </summary>
[DataField("channels", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<RadioChannelPrototype>))]
public HashSet<string> Channels = new();
//SS220 PAI with encryption keys end
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ public sealed partial class IntrinsicRadioTransmitterComponent : Component
{
[DataField("channels", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<RadioChannelPrototype>))]
public HashSet<string> Channels = new() { SharedChatSystem.CommonChannel };

//SS220 PAI with encryption keys begin
/// <summary>
/// Channels that an entity can use by encryption keys
/// </summary>
[ViewVariables]
public HashSet<string> EncryptionKeyChannels = new();
//SS220 PAI with encryption keys end
}
29 changes: 28 additions & 1 deletion Content.Server/Radio/EntitySystems/RadioSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,18 @@ public override void Initialize()
SubscribeLocalEvent<IntrinsicRadioReceiverComponent, RadioReceiveEvent>(OnIntrinsicReceive);
SubscribeLocalEvent<IntrinsicRadioTransmitterComponent, EntitySpokeEvent>(OnIntrinsicSpeak);

//SS220 PAI with encryption keys begin
SubscribeLocalEvent<IntrinsicRadioReceiverComponent, EncryptionChannelsChangedEvent>(OnEncryptionChannelsChangeReceiver);
SubscribeLocalEvent<IntrinsicRadioTransmitterComponent, EncryptionChannelsChangedEvent>(OnEncryptionChannelsChangeTransmitter);
//SS220 PAI with encryption keys end

_exemptQuery = GetEntityQuery<TelecomExemptComponent>();
}

private void OnIntrinsicSpeak(EntityUid uid, IntrinsicRadioTransmitterComponent component, EntitySpokeEvent args)
{
if (args.Channel != null && component.Channels.Contains(args.Channel.ID))
if (args.Channel != null && (component.Channels.Contains(args.Channel.ID) ||
component.EncryptionKeyChannels.Contains(args.Channel.ID))) //SS220 PAI with encryption keys
{
SendRadioMessage(uid, args.Message, args.Channel, uid);
args.Channel = null; // prevent duplicate messages from other listeners.
Expand Down Expand Up @@ -247,4 +253,25 @@ private bool HasActiveServer(MapId mapId, string channelId)
}
return false;
}

//SS220 PAI with encryption keys begin
private void OnEncryptionChannelsChangeTransmitter(Entity<IntrinsicRadioTransmitterComponent> entity, ref EncryptionChannelsChangedEvent args)
{
if (args.Component.Channels.Count == 0)
entity.Comp.EncryptionKeyChannels.Clear();
else
entity.Comp.EncryptionKeyChannels = new(args.Component.Channels);
}

private void OnEncryptionChannelsChangeReceiver(Entity<IntrinsicRadioReceiverComponent> entity, ref EncryptionChannelsChangedEvent args)
{
if (!TryComp<ActiveRadioComponent>(entity.Owner, out var activeRadio))
return;

HashSet<string> channels = entity.Comp.Channels;
channels.UnionWith(args.Component.Channels);

activeRadio.Channels = new(channels);
}
//SS220 PAI with encryption keys end
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ent-EncryptionKeysPersonalAI = { ent-PersonalAI }
.desc = { ent-PersonalAI.desc }
11 changes: 11 additions & 0 deletions Resources/Prototypes/Entities/Objects/Fun/pai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- type: entity
parent: BaseItem
id: PersonalAI
noSpawn: true #SS220 PAI with encryption keys
name: personal ai device
description: Your electronic pal who's fun to be with!
components:
Expand Down Expand Up @@ -99,6 +100,16 @@
- type: ActiveRadio
channels:
- Syndicate
#SS220 PAI with encryption keys begin
- type: IntrinsicRadioReceiver
channels:
- Syndicate
- type: ContainerContainer
containers:
key_slots: !type:Container
- type: EncryptionKeyHolder
keySlots: 2
#SS220 PAI with encryption keys end
- type: Appearance
- type: GenericVisualizer
visuals:
Expand Down
80 changes: 80 additions & 0 deletions Resources/Prototypes/SS220/Entities/Objects/Fun/pai.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
- type: entity
parent: BaseItem
id: EncryptionKeysPersonalAI
components:
- type: Instrument
allowPercussion: false
handheld: false
bank: 1
program: 2
- type: UserInterface
interfaces:
enum.InstrumentUiKey.Key:
type: InstrumentBoundUserInterface
requireInputValidation: false
enum.StationMapUiKey.Key:
type: StationMapBoundUserInterface
requireInputValidation: false
- type: Sprite
sprite: Objects/Fun/pai.rsi
layers:
- state: pai-base
- state: pai-off-overlay
shader: unshaded
map: ["screen"]
- type: Input
context: "human"
- type: PAI
- type: BlockMovement
- type: ToggleableGhostRole
examineTextMindPresent: pai-system-pai-installed
examineTextMindSearching: pai-system-still-searching
examineTextNoMind: pai-system-off
beginSearchingText: pai-system-searching
roleName: pai-system-role-name
roleDescription: pai-system-role-description
roleRules: ghost-role-information-familiar-rules
wipeVerbText: pai-system-wipe-device-verb-text
wipeVerbPopup: pai-system-wiped-device
stopSearchVerbText: pai-system-stop-searching-verb-text
stopSearchVerbPopup: pai-system-stopped-searching
- type: Examiner
- type: IntrinsicRadioReceiver
channels:
- Binary
- type: IntrinsicRadioTransmitter
channels:
- Binary
- type: DoAfter
- type: Actions
- type: TypingIndicator
proto: robot
- type: TTS # Corvax-TTS
voice: adventure_core
- type: Speech
speechVerb: Robotic
speechSounds: Pai
# This has to be installed because otherwise they're not "alive",
# so they can ghost and come back.
# Note that the personal AI never "dies".
- type: MobState
allowedStates:
- Alive
- type: Appearance
- type: GenericVisualizer
visuals:
enum.ToggleableGhostRoleVisuals.Status:
screen:
Off: { state: pai-off-overlay }
Searching: { state: pai-searching-overlay }
On: { state: pai-on-overlay }
- type: StationMap
- type: ContainerContainer
containers:
key_slots: !type:Container
- type: ContainerFill
containers:
key_slots:
- EncryptionKeyCommon
- type: EncryptionKeyHolder
keySlots: 2
5 changes: 4 additions & 1 deletion Resources/migration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -501,4 +501,7 @@ Wristwatch: null
HatBase: null

# 2024-09-11 SS220-upstream-merge
ClothingBeltChefFilled: null
ClothingBeltChefFilled: null

# 2024-09-17 SS220 PAI with encryption keys
PersonalAI: EncryptionKeysPersonalAI
Loading