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

Commit

Permalink
Merge pull request #203 from FireNameFN/FaxMultiaddress
Browse files Browse the repository at this point in the history
Ability to send fax to all shuttles
  • Loading branch information
Vonsant authored May 22, 2024
2 parents 90fbc63 + 7f3175d commit d744d82
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.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

0 comments on commit d744d82

Please sign in to comment.