From 0f9e31c988475bd780cdb3d554ca7b6d8f79d2dd Mon Sep 17 00:00:00 2001 From: Flipp Syder <76629141+vulppine@users.noreply.github.com> Date: Thu, 11 Aug 2022 02:25:29 -0700 Subject: [PATCH] Listener fix for speech (#10240) --- Content.Server/Chat/Systems/ChatSystem.cs | 1 + Content.Server/Headset/HeadsetComponent.cs | 11 +++++--- .../Components/HandheldRadioComponent.cs | 26 ++++++++++++++----- Content.Server/Radio/Components/IListen.cs | 4 +-- .../Radio/EntitySystems/ListeningSystem.cs | 2 +- 5 files changed, 32 insertions(+), 12 deletions(-) diff --git a/Content.Server/Chat/Systems/ChatSystem.cs b/Content.Server/Chat/Systems/ChatSystem.cs index 477e46985d..69e23704ed 100644 --- a/Content.Server/Chat/Systems/ChatSystem.cs +++ b/Content.Server/Chat/Systems/ChatSystem.cs @@ -266,6 +266,7 @@ public sealed partial class ChatSystem : SharedChatSystem ("entityName", Name(source))); SendInVoiceRange(ChatChannel.Local, message, messageWrap, source, hideChat); + _listener.PingListeners(source, message, null); var ev = new EntitySpokeEvent(message); RaiseLocalEvent(source, ev); diff --git a/Content.Server/Headset/HeadsetComponent.cs b/Content.Server/Headset/HeadsetComponent.cs index b7c60fc351..588440e58a 100644 --- a/Content.Server/Headset/HeadsetComponent.cs +++ b/Content.Server/Headset/HeadsetComponent.cs @@ -45,9 +45,9 @@ namespace Content.Server.Headset _radioSystem = EntitySystem.Get(); } - public bool CanListen(string message, EntityUid source, RadioChannelPrototype prototype) + public bool CanListen(string message, EntityUid source, RadioChannelPrototype? prototype) { - return Channels.Contains(prototype.ID) && RadioRequested; + return prototype != null && Channels.Contains(prototype.ID) && RadioRequested; } public void Receive(string message, RadioChannelPrototype channel, EntityUid source) @@ -73,8 +73,13 @@ namespace Content.Server.Headset _netManager.ServerSendMessage(msg, playerChannel); } - public void Listen(string message, EntityUid speaker, RadioChannelPrototype channel) + public void Listen(string message, EntityUid speaker, RadioChannelPrototype? channel) { + if (channel == null) + { + return; + } + Broadcast(message, speaker, channel); } diff --git a/Content.Server/Radio/Components/HandheldRadioComponent.cs b/Content.Server/Radio/Components/HandheldRadioComponent.cs index 66c2cefd3e..64a8ba4bcf 100644 --- a/Content.Server/Radio/Components/HandheldRadioComponent.cs +++ b/Content.Server/Radio/Components/HandheldRadioComponent.cs @@ -1,3 +1,4 @@ +using System.Linq; using Content.Server.Chat; using Content.Server.Chat.Systems; using Content.Server.Radio.EntitySystems; @@ -20,6 +21,7 @@ namespace Content.Server.Radio.Components { private ChatSystem _chatSystem = default!; private RadioSystem _radioSystem = default!; + private IPrototypeManager _prototypeManager = default!; private bool _radioOn; [DataField("channels", customTypeSerializer: typeof(PrototypeIdHashSetSerializer))] @@ -52,6 +54,7 @@ namespace Content.Server.Radio.Components _radioSystem = EntitySystem.Get(); _chatSystem = EntitySystem.Get(); + IoCManager.Resolve(ref _prototypeManager); RadioOn = false; } @@ -72,12 +75,16 @@ namespace Content.Server.Radio.Components return true; } - public bool CanListen(string message, EntityUid source, RadioChannelPrototype prototype) + public bool CanListen(string message, EntityUid source, RadioChannelPrototype? prototype) { - if (!_channels.Contains(prototype.ID)) return false; + if (prototype != null && !_channels.Contains(prototype.ID) + || !_prototypeManager.HasIndex(BroadcastChannel)) + { + return false; + } - return RadioOn && - EntitySystem.Get().InRangeUnobstructed(Owner, source, range: ListenRange); + return RadioOn + && EntitySystem.Get().InRangeUnobstructed(Owner, source, range: ListenRange); } public void Receive(string message, RadioChannelPrototype channel, EntityUid speaker) @@ -88,9 +95,16 @@ namespace Content.Server.Radio.Components } } - public void Listen(string message, EntityUid speaker, RadioChannelPrototype channel) + public void Listen(string message, EntityUid speaker, RadioChannelPrototype? prototype) { - Broadcast(message, speaker, channel); + // if we can't get the channel, we need to just use the broadcast frequency + if (prototype == null + && !_prototypeManager.TryIndex(BroadcastChannel, out prototype)) + { + return; + } + + Broadcast(message, speaker, prototype); } public void Broadcast(string message, EntityUid speaker, RadioChannelPrototype channel) diff --git a/Content.Server/Radio/Components/IListen.cs b/Content.Server/Radio/Components/IListen.cs index 1effcab101..8e76f50df6 100644 --- a/Content.Server/Radio/Components/IListen.cs +++ b/Content.Server/Radio/Components/IListen.cs @@ -10,8 +10,8 @@ namespace Content.Server.Radio.Components { int ListenRange { get; } - bool CanListen(string message, EntityUid source, RadioChannelPrototype channelPrototype); + bool CanListen(string message, EntityUid source, RadioChannelPrototype? channelPrototype); - void Listen(string message, EntityUid speaker, RadioChannelPrototype channel); + void Listen(string message, EntityUid speaker, RadioChannelPrototype? channel); } } diff --git a/Content.Server/Radio/EntitySystems/ListeningSystem.cs b/Content.Server/Radio/EntitySystems/ListeningSystem.cs index 08486ad7e6..341a5c216b 100644 --- a/Content.Server/Radio/EntitySystems/ListeningSystem.cs +++ b/Content.Server/Radio/EntitySystems/ListeningSystem.cs @@ -7,7 +7,7 @@ namespace Content.Server.Radio.EntitySystems [UsedImplicitly] public sealed class ListeningSystem : EntitySystem { - public void PingListeners(EntityUid source, string message, RadioChannelPrototype channel) + public void PingListeners(EntityUid source, string message, RadioChannelPrototype? channel) { foreach (var listener in EntityManager.EntityQuery(true)) {