mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
* ports chat follow function from AL and removes PJB implementation forgor to commit earlier so it's just one chunk * fixes accidental MiscTab.xaml restructuring * fix name color * remove unused function * cvar summary * typo * accidental doc removal * fix test fail * fix test fail * like i said first pr :| * inject in constructor * adds chat links to Local, Whisper, LOOC and Dead Chat respects Admin ghost privacy * i hate chat code * remove cvar * single events file * adds CanGhostWarp back * filter for admin ghosts * move tag * remove ChatLinkTag.cs * fix speechbubble rendering * i want to bash my brain in * kill chatcode * formatting * testfail * still not working * atleast deadchat works now * even prettier TextLinkTag.cs * fix speechbubble rendering for looc * docs * renaming and better docs * Revert "remove cvar" This reverts commit 1acb168f * final changes (hopefully) * requested changes * can't parse - * change TextLinkTag again * formatting and typo Co-authored-by: Connor Huffine <chuffine@gmail.com> * quickfix * no logging for now actually * i will work on this in the morning * restructuring * wip * final restructuring and docs * still not done btw * review * docfix * actually we can filter for admin ghosts * doc * fix color * fix fix color * review * all I care to clean up * bold names * doc * admin warp * fixed * fsaasffsa * GOD ONCE SAID: GOOD ENOUGH * they call me the shuffler * admin chat links * forgor newline * fix? * actual fix * dumb stuff * chungus --------- Co-authored-by: Connor Huffine <chuffine@gmail.com> Co-authored-by: Princess Cheeseballs <66055347+Princess-Cheeseballs@users.noreply.github.com>
158 lines
6.6 KiB
C#
158 lines
6.6 KiB
C#
using Content.Server.Administration.Logs;
|
|
using Content.Server.Chat.Systems;
|
|
using Content.Server.Power.Components;
|
|
using Content.Shared.Chat;
|
|
using Content.Shared.Database;
|
|
using Content.Shared.Radio;
|
|
using Content.Shared.Radio.Components;
|
|
using Content.Shared.Radio.EntitySystems;
|
|
using Content.Shared.Speech;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Network;
|
|
using Robust.Shared.Player;
|
|
using Robust.Shared.Random;
|
|
using Robust.Shared.Replays;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Server.Radio.EntitySystems;
|
|
|
|
/// <inheritdoc/>
|
|
public sealed partial class RadioSystem : SharedRadioSystem
|
|
{
|
|
[Dependency] private INetManager _netMan = default!;
|
|
[Dependency] private IReplayRecordingManager _replay = default!;
|
|
[Dependency] private IAdminLogManager _adminLogger = default!;
|
|
[Dependency] private IRobustRandom _random = default!;
|
|
[Dependency] private ChatSystem _chat = default!;
|
|
[Dependency] private EntityQuery<TelecomExemptComponent> _exemptQuery = default!;
|
|
|
|
// set used to prevent radio feedback loops.
|
|
private readonly HashSet<string> _messages = new();
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<IntrinsicRadioReceiverComponent, RadioReceiveEvent>(OnIntrinsicReceive);
|
|
SubscribeLocalEvent<IntrinsicRadioTransmitterComponent, EntitySpokeEvent>(OnIntrinsicSpeak);
|
|
}
|
|
|
|
private void OnIntrinsicSpeak(EntityUid uid, IntrinsicRadioTransmitterComponent component, EntitySpokeEvent args)
|
|
{
|
|
if (args.Channel != null && component.Channels.Contains(args.Channel.ID))
|
|
{
|
|
SendRadioMessage(uid, args.Message, args.Channel, uid);
|
|
args.Channel = null; // prevent duplicate messages from other listeners.
|
|
}
|
|
}
|
|
|
|
private void OnIntrinsicReceive(EntityUid uid, IntrinsicRadioReceiverComponent component, ref RadioReceiveEvent args)
|
|
{
|
|
if (TryComp(uid, out ActorComponent? actor))
|
|
_netMan.ServerSendMessage(args.ChatMsg, actor.PlayerSession.Channel);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public override void SendRadioMessage(EntityUid messageSource, string message, RadioChannelPrototype channel, EntityUid radioSource, bool escapeMarkup = true)
|
|
{
|
|
// TODO if radios ever garble / modify messages, feedback-prevention needs to be handled better than this.
|
|
if (!_messages.Add(message))
|
|
return;
|
|
|
|
var evt = new TransformSpeakerNameEvent(messageSource, MetaData(messageSource).EntityName);
|
|
RaiseLocalEvent(messageSource, evt);
|
|
|
|
var name = evt.VoiceName;
|
|
name = _chat.ChatNameLinks ? $"[textlink=\"{FormattedMessage.EscapeStringParameter(name)}\" entity=\"{GetNetEntity(messageSource)}\" color=\"{channel.Color.ToHex()}\"]" : FormattedMessage.EscapeText(name);
|
|
|
|
SpeechVerbPrototype speech;
|
|
if (evt.SpeechVerb != null && ProtoMan.Resolve(evt.SpeechVerb, out var evntProto))
|
|
speech = evntProto;
|
|
else
|
|
speech = _chat.GetSpeechVerb(messageSource, message);
|
|
|
|
var content = escapeMarkup
|
|
? FormattedMessage.EscapeText(message)
|
|
: message;
|
|
|
|
var wrappedMessage = Loc.GetString(speech.Bold ? "chat-radio-message-wrap-bold" : "chat-radio-message-wrap",
|
|
("color", channel.Color),
|
|
("fontType", speech.FontId),
|
|
("fontSize", speech.FontSize),
|
|
("verb", Loc.GetString(_random.Pick(speech.SpeechVerbStrings))),
|
|
("channel", $"\\[{channel.LocalizedName}\\]"),
|
|
("name", name),
|
|
("message", content));
|
|
|
|
// most radios are relayed to chat, so lets parse the chat message beforehand
|
|
var chat = new ChatMessage(
|
|
ChatChannel.Radio,
|
|
message,
|
|
wrappedMessage,
|
|
NetEntity.Invalid,
|
|
null);
|
|
var chatMsg = new MsgChatMessage { Message = chat };
|
|
var ev = new RadioReceiveEvent(message, messageSource, channel, radioSource, chatMsg);
|
|
|
|
var sendAttemptEv = new RadioSendAttemptEvent(channel, radioSource);
|
|
RaiseLocalEvent(ref sendAttemptEv);
|
|
RaiseLocalEvent(radioSource, ref sendAttemptEv);
|
|
var canSend = !sendAttemptEv.Cancelled;
|
|
|
|
var sourceMapId = Transform(radioSource).MapID;
|
|
var hasActiveServer = HasActiveServer(sourceMapId, channel.ID);
|
|
var sourceServerExempt = _exemptQuery.HasComp(radioSource);
|
|
|
|
var radioQuery = EntityQueryEnumerator<ActiveRadioComponent, TransformComponent>();
|
|
while (canSend && radioQuery.MoveNext(out var receiver, out var radio, out var transform))
|
|
{
|
|
if (!radio.ReceiveAllChannels)
|
|
{
|
|
if (!radio.Channels.Contains(channel.ID) || (TryComp<IntercomComponent>(receiver, out var intercom) &&
|
|
!intercom.SupportedChannels.Contains(channel.ID)))
|
|
continue;
|
|
}
|
|
|
|
if (!channel.LongRange && transform.MapID != sourceMapId && !radio.GlobalReceive)
|
|
continue;
|
|
|
|
// don't need telecom server for long range channels or handheld radios and intercoms
|
|
var needServer = !channel.LongRange && !sourceServerExempt;
|
|
if (needServer && !hasActiveServer)
|
|
continue;
|
|
|
|
// check if message can be sent to specific receiver
|
|
var attemptEv = new RadioReceiveAttemptEvent(channel, radioSource, receiver);
|
|
RaiseLocalEvent(ref attemptEv);
|
|
RaiseLocalEvent(receiver, ref attemptEv);
|
|
if (attemptEv.Cancelled)
|
|
continue;
|
|
|
|
// send the message
|
|
RaiseLocalEvent(receiver, ref ev);
|
|
}
|
|
|
|
if (name != Name(messageSource))
|
|
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Radio message from {ToPrettyString(messageSource):user} as {name} on {channel.LocalizedName}: {message}");
|
|
else
|
|
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Radio message from {ToPrettyString(messageSource):user} on {channel.LocalizedName}: {message}");
|
|
|
|
_replay.RecordServerMessage(chat);
|
|
_messages.Remove(message);
|
|
}
|
|
|
|
/// <inheritdoc cref="TelecomServerComponent"/>
|
|
private bool HasActiveServer(MapId mapId, string channelId)
|
|
{
|
|
var servers = EntityQuery<TelecomServerComponent, EncryptionKeyHolderComponent, ApcPowerReceiverComponent, TransformComponent>();
|
|
foreach (var (_, keys, power, transform) in servers)
|
|
{
|
|
if (transform.MapID == mapId &&
|
|
power.Powered &&
|
|
keys.Channels.Contains(channelId))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|