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

Ability to send fax to all shuttles #203

Merged
merged 2 commits into from
May 22, 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
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.Shared.Fax.Components;
using Content.Shared.GameTicking;
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<RoundStartedEvent>(OnRoundStarted);
SubscribeLocalEvent<FaxMultiaddressComponent, DeviceNetworkPacketEvent>(OnDeviceNetworkPacket);
}

private void OnRoundStarted(RoundStartedEvent 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
Loading