Skip to content

Commit

Permalink
Fix Ai Accessible Consoles (#1485)
Browse files Browse the repository at this point in the history
# Description

This fixes the bug where consoles that are whitelisted by AI can only be
accessed by AI. It does so by cherrypicking
space-wizards/space-station-14#32012
and space-wizards/space-station-14#31170 (which
the first cherrypick requires)
and now space-wizards/space-station-14#29094

Also fixes AI Speech/Languages issue

DO NOT SQUASH THIS, IT'S THREE PRS.
  • Loading branch information
VMSolidus authored Jan 11, 2025
2 parents fa35a3a + 0ce4d63 commit 81bab8a
Show file tree
Hide file tree
Showing 46 changed files with 624 additions and 177 deletions.
67 changes: 56 additions & 11 deletions Content.Client/Silicons/StationAi/StationAiSystem.Airlock.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,75 @@
using Content.Shared.Doors.Components;
using Content.Shared.Electrocution;
using Content.Shared.Silicons.StationAi;
using Robust.Shared.Utility;

namespace Content.Client.Silicons.StationAi;

public sealed partial class StationAiSystem
{
private readonly ResPath _aiActionsRsi = new ResPath("/Textures/Interface/Actions/actions_ai.rsi");

private void InitializeAirlock()
{
SubscribeLocalEvent<DoorBoltComponent, GetStationAiRadialEvent>(OnDoorBoltGetRadial);
SubscribeLocalEvent<AirlockComponent, GetStationAiRadialEvent>(OnEmergencyAccessGetRadial);
SubscribeLocalEvent<ElectrifiedComponent, GetStationAiRadialEvent>(OnDoorElectrifiedGetRadial);
}

private void OnDoorBoltGetRadial(Entity<DoorBoltComponent> ent, ref GetStationAiRadialEvent args)
{
args.Actions.Add(new StationAiRadial()
{
Sprite = ent.Comp.BoltsDown ?
new SpriteSpecifier.Rsi(
new ResPath("/Textures/Structures/Doors/Airlocks/Standard/basic.rsi"), "open") :
new SpriteSpecifier.Rsi(
new ResPath("/Textures/Structures/Doors/Airlocks/Standard/basic.rsi"), "closed"),
Tooltip = ent.Comp.BoltsDown ? Loc.GetString("bolt-open") : Loc.GetString("bolt-close"),
Event = new StationAiBoltEvent()
args.Actions.Add(
new StationAiRadial
{
Sprite = ent.Comp.BoltsDown
? new SpriteSpecifier.Rsi(_aiActionsRsi, "unbolt_door")
: new SpriteSpecifier.Rsi(_aiActionsRsi, "bolt_door"),
Tooltip = ent.Comp.BoltsDown
? Loc.GetString("bolt-open")
: Loc.GetString("bolt-close"),
Event = new StationAiBoltEvent
{
Bolted = !ent.Comp.BoltsDown,
}
}
);
}

private void OnEmergencyAccessGetRadial(Entity<AirlockComponent> ent, ref GetStationAiRadialEvent args)
{
args.Actions.Add(
new StationAiRadial
{
Sprite = ent.Comp.EmergencyAccess
? new SpriteSpecifier.Rsi(_aiActionsRsi, "emergency_off")
: new SpriteSpecifier.Rsi(_aiActionsRsi, "emergency_on"),
Tooltip = ent.Comp.EmergencyAccess
? Loc.GetString("emergency-access-off")
: Loc.GetString("emergency-access-on"),
Event = new StationAiEmergencyAccessEvent
{
EmergencyAccess = !ent.Comp.EmergencyAccess,
}
}
);
}

private void OnDoorElectrifiedGetRadial(Entity<ElectrifiedComponent> ent, ref GetStationAiRadialEvent args)
{
args.Actions.Add(
new StationAiRadial
{
Bolted = !ent.Comp.BoltsDown,
Sprite = ent.Comp.Enabled
? new SpriteSpecifier.Rsi(_aiActionsRsi, "door_overcharge_off")
: new SpriteSpecifier.Rsi(_aiActionsRsi, "door_overcharge_on"),
Tooltip = ent.Comp.Enabled
? Loc.GetString("electrify-door-off")
: Loc.GetString("electrify-door-on"),
Event = new StationAiElectrifiedEvent
{
Electrified = !ent.Comp.Enabled,
}
}
});
);
}
}
74 changes: 74 additions & 0 deletions Content.Server/Access/LogWireAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using Content.Server.Wires;
using Content.Shared.Access;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Emag.Components;
using Content.Shared.Wires;

namespace Content.Server.Access;

public sealed partial class LogWireAction : ComponentWireAction<AccessReaderComponent>
{
public override Color Color { get; set; } = Color.Blue;
public override string Name { get; set; } = "wire-name-log";

[DataField]
public int PulseTimeout = 30;

[DataField]
public LocId PulseLog = "log-wire-pulse-access-log";

private AccessReaderSystem _access = default!;

public override StatusLightState? GetLightState(Wire wire, AccessReaderComponent comp)
{
return comp.LoggingDisabled ? StatusLightState.Off : StatusLightState.On;
}

public override object StatusKey => AccessWireActionKey.Status;

public override void Initialize()
{
base.Initialize();

_access = EntityManager.System<AccessReaderSystem>();
}

public override bool Cut(EntityUid user, Wire wire, AccessReaderComponent comp)
{
WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
comp.LoggingDisabled = true;
EntityManager.Dirty(wire.Owner, comp);
return true;
}

public override bool Mend(EntityUid user, Wire wire, AccessReaderComponent comp)
{
comp.LoggingDisabled = false;
return true;
}

public override void Pulse(EntityUid user, Wire wire, AccessReaderComponent comp)
{
_access.LogAccess((wire.Owner, comp), Loc.GetString(PulseLog));
comp.LoggingDisabled = true;
WiresSystem.StartWireAction(wire.Owner, PulseTimeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitPulseCancel, wire));
}

public override void Update(Wire wire)
{
if (!IsPowered(wire.Owner))
WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
}

private void AwaitPulseCancel(Wire wire)
{
if (!wire.IsCut && EntityManager.TryGetComponent<AccessReaderComponent>(wire.Owner, out var comp))
comp.LoggingDisabled = false;
}

private enum PulseTimeoutKey : byte
{
Key
}
}
10 changes: 5 additions & 5 deletions Content.Server/Administration/Systems/AdminVerbSystem.Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,22 @@ private void AddTricksVerbs(GetVerbsEvent<Verb> args)
args.Verbs.Add(bolt);
}

if (TryComp<AirlockComponent>(args.Target, out var airlock))
if (TryComp<AirlockComponent>(args.Target, out var airlockComp))
{
Verb emergencyAccess = new()
{
Text = airlock.EmergencyAccess ? "Emergency Access Off" : "Emergency Access On",
Text = airlockComp.EmergencyAccess ? "Emergency Access Off" : "Emergency Access On",
Category = VerbCategory.Tricks,
Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/AdminActions/emergency_access.png")),
Act = () =>
{
_airlockSystem.ToggleEmergencyAccess(args.Target, airlock);
_airlockSystem.SetEmergencyAccess((args.Target, airlockComp), !airlockComp.EmergencyAccess);
},
Impact = LogImpact.Medium,
Message = Loc.GetString(airlock.EmergencyAccess
Message = Loc.GetString(airlockComp.EmergencyAccess
? "admin-trick-emergency-access-off-description"
: "admin-trick-emergency-access-on-description"),
Priority = (int) (airlock.EmergencyAccess ? TricksVerbPriorities.EmergencyAccessOff : TricksVerbPriorities.EmergencyAccessOn),
Priority = (int) (airlockComp.EmergencyAccess ? TricksVerbPriorities.EmergencyAccessOff : TricksVerbPriorities.EmergencyAccessOn),
};
args.Verbs.Add(emergencyAccess);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Server.Electrocution;
using Content.Shared.Electrocution;
using Content.Shared.Construction;

namespace Content.Server.Construction.Completions;
Expand Down
1 change: 0 additions & 1 deletion Content.Server/Doors/WireActions/DoorBoltWireAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Content.Server.Wires;
using Content.Shared.Doors;
using Content.Shared.Doors.Components;
using Content.Shared.Doors.Systems;
using Content.Shared.Wires;

namespace Content.Server.Doors;
Expand Down
91 changes: 0 additions & 91 deletions Content.Server/Electrocution/Components/ElectrifiedComponent.cs

This file was deleted.

11 changes: 11 additions & 0 deletions Content.Server/Electrocution/ElectrocutionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -490,4 +490,15 @@ private void PlayElectrocutionSound(EntityUid targetUid, EntityUid sourceUid, El
}
_audio.PlayPvs(electrified.ShockNoises, targetUid, AudioParams.Default.WithVolume(electrified.ShockVolume));
}

public void SetElectrifiedWireCut(Entity<ElectrifiedComponent> ent, bool value)
{
if (ent.Comp.IsWireCut == value)
{
return;
}

ent.Comp.IsWireCut = value;
Dirty(ent);
}
}
2 changes: 2 additions & 0 deletions Content.Server/Power/PowerWireAction.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Server.Electrocution;
using Content.Shared.Electrocution;
using Content.Server.Power.Components;
using Content.Server.Wires;
using Content.Shared.Emp;
Expand Down Expand Up @@ -108,6 +109,7 @@ private void SetElectrified(EntityUid used, bool setting, ElectrifiedComponent?
&& !EntityManager.TryGetComponent(used, out electrified))
return;

_electrocutionSystem.SetElectrifiedWireCut((used, electrified), setting);
electrified.Enabled = setting;
}

Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Remotes/DoorRemoteSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private void OnBeforeInteract(Entity<DoorRemoteComponent> entity, ref BeforeRang
case OperatingMode.ToggleEmergencyAccess:
if (airlockComp != null)
{
_airlock.ToggleEmergencyAccess(args.Target.Value, airlockComp);
_airlock.SetEmergencyAccess((args.Target.Value, airlockComp), !airlockComp.EmergencyAccess);
_adminLogger.Add(LogType.Action, LogImpact.Medium,
$"{ToPrettyString(args.User):player} used {ToPrettyString(args.Used)} on {ToPrettyString(args.Target.Value)} to set emergency access {(airlockComp.EmergencyAccess ? "on" : "off")}");
}
Expand Down
7 changes: 7 additions & 0 deletions Content.Shared/Access/Components/AccessReaderComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ public sealed partial class AccessReaderComponent : Component
[DataField, ViewVariables(VVAccess.ReadWrite)]
public int AccessLogLimit = 20;

/// <summary>
/// If true logging on successful access uses will be disabled.
/// Can be set by LOG wire.
/// </summary>
[DataField]
public bool LoggingDisabled;

/// <summary>
/// Whether or not emag interactions have an effect on this.
/// </summary>
Expand Down
Loading

0 comments on commit 81bab8a

Please sign in to comment.