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

APC Abuse Fix #526

Merged
merged 11 commits into from
Nov 7, 2023
7 changes: 7 additions & 0 deletions Content.Server/Emp/EmpSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Content.Shared.Emp;
using Content.Shared.Examine;
using Robust.Shared.Map;
using static Content.Server.Shuttles.Systems.ShuttleConsoleSystem;
using static Content.Server.Shuttles.Systems.ThrusterSystem;

namespace Content.Server.Emp;
Expand All @@ -29,6 +30,7 @@ public override void Initialize()
SubscribeLocalEvent<EmpDisabledComponent, ApcToggleMainBreakerAttemptEvent>(OnApcToggleMainBreaker);
SubscribeLocalEvent<EmpDisabledComponent, SurveillanceCameraSetActiveAttemptEvent>(OnCameraSetActive);
SubscribeLocalEvent<EmpDisabledComponent, ThrusterToggleAttemptEvent>(OnThrusterToggle);
SubscribeLocalEvent<EmpDisabledComponent, ShuttleToggleAttemptEvent>(OnShuttleConsoleToggle);
}

/// <summary>
Expand Down Expand Up @@ -147,6 +149,11 @@ private void OnThrusterToggle(EntityUid uid, EmpDisabledComponent component, ref
{
args.Cancelled = true;
}

private void OnShuttleConsoleToggle(EntityUid uid, EmpDisabledComponent component, ref ShuttleToggleAttemptEvent args)
{
args.Cancelled = true;
}
}

/// <summary>
Expand Down
16 changes: 15 additions & 1 deletion Content.Server/Power/EntitySystems/ApcSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Timing;
using Content.Shared.Tools.Components;
using Content.Shared.Emp;

namespace Content.Server.Power.EntitySystems;

Expand All @@ -36,6 +38,7 @@ public override void Initialize()
SubscribeLocalEvent<ApcComponent, GotEmaggedEvent>(OnEmagged);

SubscribeLocalEvent<ApcComponent, EmpPulseEvent>(OnEmpPulse);
SubscribeLocalEvent<ApcComponent, ToolUseAttemptEvent>(OnToolUseAttempt);
}

public override void Update(float deltaTime)
Expand Down Expand Up @@ -117,7 +120,7 @@ private void OnEmagged(EntityUid uid, ApcComponent comp, ref GotEmaggedEvent arg
}

public void UpdateApcState(EntityUid uid,
ApcComponent? apc=null,
ApcComponent? apc = null,
PowerNetworkBatteryComponent? battery = null)
{
if (!Resolve(uid, ref apc, ref battery, false))
Expand Down Expand Up @@ -189,6 +192,7 @@ private ApcExternalPowerState CalcExtPowerState(EntityUid uid, PowerState.Batter

return ApcExternalPowerState.Good;
}

private void OnEmpPulse(EntityUid uid, ApcComponent component, ref EmpPulseEvent args)
{
if (component.MainBreakerEnabled)
Expand All @@ -198,6 +202,16 @@ private void OnEmpPulse(EntityUid uid, ApcComponent component, ref EmpPulseEvent
ApcToggleBreaker(uid, component);
}
}

private void OnToolUseAttempt(EntityUid uid, ApcComponent component, ToolUseAttemptEvent args)
{
if (!HasComp<EmpDisabledComponent>(uid))
return;

// prevent reconstruct exploit to skip cooldowns
if (!component.MainBreakerEnabled)
args.Cancel();
}
Cheackraze marked this conversation as resolved.
Show resolved Hide resolved
}

[ByRefEvent]
Expand Down
16 changes: 16 additions & 0 deletions Content.Server/Shuttles/Components/ShuttleConsoleComponent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Numerics;
using Content.Shared.Shuttles.Components;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;

namespace Content.Server.Shuttles.Components
{
Expand All @@ -14,5 +15,20 @@ public sealed partial class ShuttleConsoleComponent : SharedShuttleConsoleCompon
/// </summary>
[DataField("zoom")]
public Vector2 Zoom = new(1.5f, 1.5f);

/// <summary>
/// For EMP to allow keeping the shuttle off
/// </summary>
[DataField("enabled")]
public bool MainBreakerEnabled = true;

/// <summary>
/// While disabled by EMP
/// </summary>
[DataField("timeoutFromEmp", customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan TimeoutFromEmp = TimeSpan.Zero;

[DataField("disableDuration"), ViewVariables(VVAccess.ReadWrite)]
public float DisableDuration = 60f;
}
}
42 changes: 42 additions & 0 deletions Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
using Robust.Shared.Physics.Components;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using Content.Server.Emp;
using Content.Shared.Tools.Components;
using Content.Shared.Emp;

namespace Content.Server.Shuttles.Systems;

Expand Down Expand Up @@ -59,6 +62,9 @@ public override void Initialize()

SubscribeLocalEvent<FTLDestinationComponent, ComponentStartup>(OnFtlDestStartup);
SubscribeLocalEvent<FTLDestinationComponent, ComponentShutdown>(OnFtlDestShutdown);

SubscribeLocalEvent<ShuttleConsoleComponent, EmpPulseEvent>(OnEmpPulse);
SubscribeLocalEvent<ShuttleConsoleComponent, ToolUseAttemptEvent>(OnToolUseAttempt);
}

private void OnFtlDestStartup(EntityUid uid, FTLDestinationComponent component, ComponentStartup args)
Expand Down Expand Up @@ -369,6 +375,22 @@ public override void Update(float frameTime)
{
RemovePilot(uid, comp);
}

/// <summary>
/// This makes the Shuttle Console kick pilots like its removed, to make sure EMP in effect.
/// </summary>
var disabled = EntityQueryEnumerator<EmpDisabledComponent, ShuttleConsoleComponent>();
while (disabled.MoveNext(out var uid, out _, out var comp))
{
if (comp.TimeoutFromEmp <= _timing.CurTime)
{
ClearPilots(comp);
comp.TimeoutFromEmp += TimeSpan.FromSeconds(0.1);
comp.MainBreakerEnabled = false;
}
else
comp.MainBreakerEnabled = true;
}
}

/// <summary>
Expand Down Expand Up @@ -462,4 +484,24 @@ public void ClearPilots(ShuttleConsoleComponent component)
RemovePilot(pilot, pilotComponent);
}
}

private void OnEmpPulse(EntityUid uid, ShuttleConsoleComponent component, ref EmpPulseEvent args)
{
args.Affected = true;
args.Disabled = true;
component.TimeoutFromEmp = _timing.CurTime;
}

private void OnToolUseAttempt(EntityUid uid, ShuttleConsoleComponent component, ToolUseAttemptEvent args)
{
if (!HasComp<EmpDisabledComponent>(uid))
return;

// prevent reconstruct exploit to skip cooldowns
if (!component.MainBreakerEnabled)
args.Cancel();
}
dvir001 marked this conversation as resolved.
Show resolved Hide resolved

[ByRefEvent]
public record struct ShuttleToggleAttemptEvent(bool Cancelled);
}
Loading