Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Added ability to send fax to all shuttles
Browse files Browse the repository at this point in the history
  • Loading branch information
FireNameFN committed May 21, 2024
1 parent 2eda549 commit 1a9b1e2
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Content.Server.Corvax.FaxMultiaddress;

[RegisterComponent]
public sealed partial class FaxMultiaddressComponent : Component;
69 changes: 69 additions & 0 deletions Content.Server/Corvax/FaxMultiaddress/FaxMultiaddressSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems;
using Content.Server.Fax;
using Content.Server.Station.Systems;
using Content.Shared.Fax.Components;
using Content.Shared.Paper;
using Content.Shared.Shipyard.Components;

namespace Content.Server.Corvax.FaxMultiaddress;

public sealed class FaxMultiaddressSystem : EntitySystem
{
[Dependency] private readonly DeviceNetworkSystem _network = default!;
[Dependency] private readonly FaxSystem _fax = default!;

public override void Initialize()
{
SubscribeLocalEvent<StationInitializedEvent>(OnStationInitialized);
SubscribeLocalEvent<FaxMultiaddressComponent, DeviceNetworkPacketEvent>(OnDeviceNetworkPacket);
}

private void OnStationInitialized(StationInitializedEvent e)
{
Spawn("FaxMultiaddress");
}

private void OnDeviceNetworkPacket(EntityUid entity, FaxMultiaddressComponent component, DeviceNetworkPacketEvent e)
{
if (!TryComp<DeviceNetworkComponent>(entity, out var device))
return;

if (!e.Data.TryGetValue(DeviceNetworkConstants.Command, out string? command))
return;

switch (command)
{
case FaxConstants.FaxPingCommand:
_network.QueuePacket(entity, e.SenderAddress, new()
{
[DeviceNetworkConstants.Command] = FaxConstants.FaxPongCommand,
[FaxConstants.FaxNameData] = "All Shuttles"
});

break;
case FaxConstants.FaxPrintCommand:
if (!e.Data.TryGetValue(FaxConstants.FaxPaperNameData, out string? name))
return;

if (!e.Data.TryGetValue(FaxConstants.FaxPaperContentData, out string? content))
return;

e.Data.TryGetValue(FaxConstants.FaxPaperLabelData, out string? label);
e.Data.TryGetValue(FaxConstants.FaxPaperStampStateData, out string? stampState);
e.Data.TryGetValue(FaxConstants.FaxPaperStampedByData, out List<StampDisplayInfo>? stampedBy);
e.Data.TryGetValue(FaxConstants.FaxPaperPrototypeData, out string? prototype);

FaxPrintout printout = new(content, name, label, prototype, stampState, stampedBy);

var faxes = AllEntityQuery<FaxMachineComponent>();

while (faxes.MoveNext(out var fax, out var faxComponent))
if (fax != e.Sender && HasComp<ShuttleDeedComponent>(Transform(fax).GridUid))
_fax.Receive(fax, printout, device.Address, faxComponent);

break;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- type: entity
id: FaxMultiaddress
components:
- type: FaxMultiaddress
- type: DeviceNetwork
deviceNetId: Wireless
receiveFrequencyId: Fax
transmitFrequencyId: Fax

0 comments on commit 1a9b1e2

Please sign in to comment.