diff --git a/Content.Server/Corvax/FaxMultiaddress/FaxMultiaddressComponent.cs b/Content.Server/Corvax/FaxMultiaddress/FaxMultiaddressComponent.cs new file mode 100644 index 00000000000..9afd5b919db --- /dev/null +++ b/Content.Server/Corvax/FaxMultiaddress/FaxMultiaddressComponent.cs @@ -0,0 +1,4 @@ +namespace Content.Server.Corvax.FaxMultiaddress; + +[RegisterComponent] +public sealed partial class FaxMultiaddressComponent : Component; diff --git a/Content.Server/Corvax/FaxMultiaddress/FaxMultiaddressSystem.cs b/Content.Server/Corvax/FaxMultiaddress/FaxMultiaddressSystem.cs new file mode 100644 index 00000000000..04aabdec421 --- /dev/null +++ b/Content.Server/Corvax/FaxMultiaddress/FaxMultiaddressSystem.cs @@ -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(OnRoundStarted); + SubscribeLocalEvent(OnDeviceNetworkPacket); + } + + private void OnRoundStarted(RoundStartedEvent e) + { + Spawn("FaxMultiaddress"); + } + + private void OnDeviceNetworkPacket(EntityUid entity, FaxMultiaddressComponent component, DeviceNetworkPacketEvent e) + { + if (!TryComp(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? stampedBy); + e.Data.TryGetValue(FaxConstants.FaxPaperPrototypeData, out string? prototype); + + FaxPrintout printout = new(content, name, label, prototype, stampState, stampedBy); + + var faxes = AllEntityQuery(); + + while (faxes.MoveNext(out var fax, out var faxComponent)) + if (fax != e.Sender && HasComp(Transform(fax).GridUid)) + _fax.Receive(fax, printout, device.Address, faxComponent); + + break; + } + } +} diff --git a/Resources/Prototypes/CorvaxFrontier/Entities/fax_multiaddress.yml b/Resources/Prototypes/CorvaxFrontier/Entities/fax_multiaddress.yml new file mode 100644 index 00000000000..4a843c139ed --- /dev/null +++ b/Resources/Prototypes/CorvaxFrontier/Entities/fax_multiaddress.yml @@ -0,0 +1,8 @@ +- type: entity + id: FaxMultiaddress + components: + - type: FaxMultiaddress + - type: DeviceNetwork + deviceNetId: Wireless + receiveFrequencyId: Fax + transmitFrequencyId: Fax