Skip to content

Commit

Permalink
Sending PDA messages is map based
Browse files Browse the repository at this point in the history
  • Loading branch information
Vonsant authored Jan 3, 2025
1 parent 88dfe67 commit 7bc1bf2
Showing 1 changed file with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Content.Shared._CorvaxNext.NanoChat;
using Content.Shared.PDA;
using Content.Shared.Radio.Components;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;

Expand Down Expand Up @@ -257,7 +258,7 @@ private void HandleSendMessage(Entity<NanoChatCartridgeComponent> cartridge,

// Log message attempt
var recipientsText = recipients.Count > 0
? string.Join(", ", recipients.Select(r => ToPrettyString(r)))
? string.Join(", ", recipients.Select((Entity<NanoChatCardComponent> r) => ToPrettyString(r)))
: $"#{msg.RecipientNumber:D4}";

_adminLogger.Add(LogType.Chat,
Expand Down Expand Up @@ -330,21 +331,18 @@ private bool EnsureRecipientExists(Entity<NanoChatCardComponent> card, uint reci
if (receiverCart.Card != recipient.Owner)
continue;

// Check if devices are on same station/map
var recipientStation = _station.GetOwningStation(receiverUid);
var senderStation = _station.GetOwningStation(sender);
// Check if devices are on same map
var recipientMap = Transform(receiverUid).MapID;
var senderMap = Transform(sender).MapID;
// Must be on the same map/station unless long-range is allowed
if (!channel.LongRange && recipientMap != senderMap)
{
break;
}

// Both entities must be on a station
if (recipientStation == null || senderStation == null)
continue;

// Must be on same map/station unless long range allowed
if (!channel.LongRange && recipientStation != senderStation)
continue;

// Needs telecomms
if (!HasActiveServer(senderStation.Value) || !HasActiveServer(recipientStation.Value))
continue;
/* Must have an active common server
if (HasActiveServer(senderMap))
continue;*/

// Check if recipient can receive
var receiveAttemptEv = new RadioReceiveAttemptEvent(channel, sender, receiverUid);
Expand All @@ -364,15 +362,15 @@ private bool EnsureRecipientExists(Entity<NanoChatCardComponent> card, uint reci
/// <summary>
/// Checks if there are any active telecomms servers on the given station
/// </summary>
private bool HasActiveServer(EntityUid station)
private bool HasActiveServer(MapId mapId)
{
// I have no idea why this isn't public in the RadioSystem
var query =
EntityQueryEnumerator<TelecomServerComponent, EncryptionKeyHolderComponent, ApcPowerReceiverComponent>();

while (query.MoveNext(out var uid, out _, out _, out var power))
{
if (_station.GetOwningStation(uid) == station && power.Powered)
if (Transform(uid).MapID == mapId && power.Powered)
return true;
}

Expand Down

0 comments on commit 7bc1bf2

Please sign in to comment.