Files
OldThink/Content.Server/Radio/EntitySystems/RadioSystem.cs

105 lines
4.2 KiB
C#
Raw Normal View History

2022-12-24 14:50:34 -06:00
using Content.Server.Administration.Logs;
2022-11-15 17:09:27 +13:00
using Content.Server.Chat.Systems;
2021-06-09 22:19:39 +02:00
using Content.Server.Radio.Components;
2022-11-15 17:09:27 +13:00
using Content.Server.VoiceMask;
using Content.Server.Popups;
2022-11-15 17:09:27 +13:00
using Content.Shared.Chat;
2022-12-24 14:50:34 -06:00
using Content.Shared.Database;
using Content.Shared.Radio;
2022-11-15 17:09:27 +13:00
using Robust.Server.GameObjects;
using Robust.Shared.Network;
2022-11-23 00:52:19 +13:00
using Robust.Shared.Replays;
2022-11-15 17:09:27 +13:00
using Robust.Shared.Utility;
using Content.Shared.Popups;
2022-11-15 17:09:27 +13:00
namespace Content.Server.Radio.EntitySystems;
/// <summary>
2022-11-23 00:52:19 +13:00
/// This system handles intrinsic radios and the general process of converting radio messages into chat messages.
2022-11-15 17:09:27 +13:00
/// </summary>
public sealed class RadioSystem : EntitySystem
{
2022-11-15 17:09:27 +13:00
[Dependency] private readonly INetManager _netMan = default!;
2022-11-23 00:52:19 +13:00
[Dependency] private readonly IReplayRecordingManager _replay = default!;
2022-12-24 14:50:34 -06:00
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
2022-11-15 17:09:27 +13:00
// set used to prevent radio feedback loops.
private readonly HashSet<string> _messages = new();
public override void Initialize()
{
2022-11-15 17:09:27 +13:00
base.Initialize();
SubscribeLocalEvent<IntrinsicRadioReceiverComponent, RadioReceiveEvent>(OnIntrinsicReceive);
SubscribeLocalEvent<IntrinsicRadioTransmitterComponent, EntitySpokeEvent>(OnIntrinsicSpeak);
}
Headsets (#2023) * add headset component * add basic headset logic * fix formatting in listening component, add dependency to headset * test function for headset * implement headset as listener * ANNIHILATES ListeningComponent, refactor of radio/listener sys * basic headset functionality * rename RadioComponent to HandheldRadioComponent * change channel to list of channels * basic headset implementation complete * message now always excludes ';' * add radio color; state channel freq. and source name * undocumented game breaking bug commit (DO NOT RESEARCH) actually just changes frequency from 1457 (what signalers are set to by default) to 1459, the actual frequency for common * Add more sprites * Reorganizes * Added job headsets * Adds headset as an ignored component * Jobs now spawn with headsets * remove system.tracing * Catchup commits * Add headset property serialization * Turn GetChannels into a property * ListenRange property and serializatioon * Adjust interfaces * Address reviews * Cleanup * Address reviews * Update rsi * Fix licenses and copyright * Fix missing textures * Merge fixes * Move headset textures from objects/devices to clothing/ears * Fix rsi state names and add equipped states * Fix headsets not working * Add missing brackets to channel number in chat * heck * Fix broken rsi * Fix radio id and names * Put quotes around headset messages * Fix method names * Fix handheld radios * Fix capitalization when using radio channels and trim * Remove unnecessary dependency * Indent that * Separate this part * Goodbye icons * Implement IActivate in HandheldRadioComponent * Add examine tooltip to radios and headsets * Rename IListen methods Co-authored-by: Bright <nsmoak10@yahoo.com> Co-authored-by: Swept <jamesurquhartwebb@gmail.com> Co-authored-by: Bright0 <55061890+Bright0@users.noreply.github.com>
2020-10-07 14:02:12 +02:00
2022-11-15 17:09:27 +13:00
private void OnIntrinsicSpeak(EntityUid uid, IntrinsicRadioTransmitterComponent component, EntitySpokeEvent args)
{
if (args.Channel != null && component.Channels.Contains(args.Channel.ID))
2022-04-08 17:17:25 -04:00
{
2022-11-15 17:09:27 +13:00
SendRadioMessage(uid, args.Message, args.Channel);
args.Channel = null; // prevent duplicate messages from other listeners.
}
2022-11-15 17:09:27 +13:00
}
2022-11-15 17:09:27 +13:00
private void OnIntrinsicReceive(EntityUid uid, IntrinsicRadioReceiverComponent component, RadioReceiveEvent args)
{
if (TryComp(uid, out ActorComponent? actor))
_netMan.ServerSendMessage(args.ChatMsg, actor.PlayerSession.ConnectedClient);
}
public void SendRadioMessage(EntityUid source, string message, RadioChannelPrototype channel, EntityUid? radioSource = null)
2022-11-15 17:09:27 +13:00
{
// TODO if radios ever garble / modify messages, feedback-prevention needs to be handled better than this.
if (!_messages.Add(message))
return;
var name = TryComp(source, out VoiceMaskComponent? mask) && mask.Enabled
? mask.VoiceName
2022-11-15 17:09:27 +13:00
: MetaData(source).EntityName;
2022-04-08 17:17:25 -04:00
2022-11-15 17:09:27 +13:00
name = FormattedMessage.EscapeText(name);
// most radios are relayed to chat, so lets parse the chat message beforehand
2022-11-23 00:52:19 +13:00
var chat = new ChatMessage(
ChatChannel.Radio,
message,
Loc.GetString("chat-radio-message-wrap", ("color", channel.Color), ("channel", $"\\[{channel.LocalizedName}\\]"), ("name", name), ("message", FormattedMessage.EscapeText(message))),
EntityUid.Invalid);
var chatMsg = new MsgChatMessage { Message = chat };
2022-04-08 17:17:25 -04:00
var ev = new RadioReceiveEvent(message, source, channel, chatMsg, radioSource);
var attemptEv = new RadioReceiveAttemptEvent(message, source, channel, radioSource);
2023-02-15 00:53:13 -05:00
var sentAtLeastOnce = false;
2022-11-15 17:09:27 +13:00
foreach (var radio in EntityQuery<ActiveRadioComponent>())
Headsets (#2023) * add headset component * add basic headset logic * fix formatting in listening component, add dependency to headset * test function for headset * implement headset as listener * ANNIHILATES ListeningComponent, refactor of radio/listener sys * basic headset functionality * rename RadioComponent to HandheldRadioComponent * change channel to list of channels * basic headset implementation complete * message now always excludes ';' * add radio color; state channel freq. and source name * undocumented game breaking bug commit (DO NOT RESEARCH) actually just changes frequency from 1457 (what signalers are set to by default) to 1459, the actual frequency for common * Add more sprites * Reorganizes * Added job headsets * Adds headset as an ignored component * Jobs now spawn with headsets * remove system.tracing * Catchup commits * Add headset property serialization * Turn GetChannels into a property * ListenRange property and serializatioon * Adjust interfaces * Address reviews * Cleanup * Address reviews * Update rsi * Fix licenses and copyright * Fix missing textures * Merge fixes * Move headset textures from objects/devices to clothing/ears * Fix rsi state names and add equipped states * Fix headsets not working * Add missing brackets to channel number in chat * heck * Fix broken rsi * Fix radio id and names * Put quotes around headset messages * Fix method names * Fix handheld radios * Fix capitalization when using radio channels and trim * Remove unnecessary dependency * Indent that * Separate this part * Goodbye icons * Implement IActivate in HandheldRadioComponent * Add examine tooltip to radios and headsets * Rename IListen methods Co-authored-by: Bright <nsmoak10@yahoo.com> Co-authored-by: Swept <jamesurquhartwebb@gmail.com> Co-authored-by: Bright0 <55061890+Bright0@users.noreply.github.com>
2020-10-07 14:02:12 +02:00
{
2023-02-15 00:53:13 -05:00
var ent = radio.Owner;
2022-11-15 17:09:27 +13:00
// TODO map/station/range checks?
2022-11-15 17:09:27 +13:00
if (!radio.Channels.Contains(channel.ID))
continue;
2023-02-15 00:53:13 -05:00
RaiseLocalEvent(ent, attemptEv);
2022-11-15 17:09:27 +13:00
if (attemptEv.Cancelled)
{
2022-11-15 17:09:27 +13:00
attemptEv.Uncancel();
continue;
}
sentAtLeastOnce = true;
2023-02-15 00:53:13 -05:00
RaiseLocalEvent(ent, ev);
}
if (!sentAtLeastOnce)
2023-02-15 00:53:13 -05:00
_popupSystem.PopupEntity(Loc.GetString("failed-to-send-message"), source, source, PopupType.MediumCaution);
2022-11-15 17:09:27 +13:00
if (name != Name(source))
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Radio message from {ToPrettyString(source):user} as {name} on {channel.LocalizedName}: {message}");
else
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Radio message from {ToPrettyString(source):user} on {channel.LocalizedName}: {message}");
2022-12-24 14:50:34 -06:00
2022-11-23 00:52:19 +13:00
_replay.QueueReplayMessage(chat);
2022-11-15 17:09:27 +13:00
_messages.Remove(message);
}
}