mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-18 14:07:53 +03:00
# Description The language PR was merged early and OH GOD I ALREADY REGRET IT This PR is intended to provide the missing refactors and address the issues that were missed due to the early merge. --- # TODO - [X] Introduced a polymorphic obfuscation property to the LanguagePrototype - now it supports more than just 2 hardcoded methods, and each method can be configured per-language. Currently there are 3 obfuscation methods: replacement (same as replacement accent), obuscation by syllables and obfuscation by phrases. - [X] Refactored the existing obfuscation methods to not be a big hardcoded mess. - [X] Updated the existing languages accordingly: animalistic languages are now less of an unreadable mess and include less syllables. Certain languages like binary and snake seriously benefit from that. - [X] Refactored the existing commands in response to the never-addressed review (it got lost among hundreds of others) - [X] Refactored the commands to be more user-friendly (you can now use the number of the language in saylang and languageselect which can allow using keybinds to switch between languages) - [X] Moved a lot of obfuscation-related stuff from server to shared. The actual obfuscation process, however, is still done on the server. That may or may not be subject to change, too. - [X] Refactored the entire process of resolution of entities' languages. Instead of raising an event every time it's required to learn what languages an entity knows, the lists of ALL languages available to the entity (including via translators) is stored in LanguageSpeakerComponent and only updated when necessary (e.g. when a translator gets toggled). The list of languages the entity knows on its own is now stored in LanguageKnowledgeComponent. - [X] Made handheld translators automatically change your current language when activated. - [X] Rewrote the translator implanter system, now using the real implants and implanters - [ ] Rebalance science stuff (translators are incredibly expensive for what they're worth) - [ ] Uhhh stuff --- <details><summary><h1>Media</h1></summary> <p> N/A for now </p> </details> --- # Changelog 🆑 - tweak: Translator implants are now proper implants that can be removed. - tweak: Animalistic languages should now look less messy. - fix: Hopefully fixed language menu desync and other issues. --------- Signed-off-by: Mnemotechnican <69920617+Mnemotechnician@users.noreply.github.com>
205 lines
8.7 KiB
C#
205 lines
8.7 KiB
C#
using Content.Server.Administration.Logs;
|
|
using Content.Server.Chat.Systems;
|
|
using Content.Server.Language;
|
|
using Content.Server.Power.Components;
|
|
using Content.Server.Radio.Components;
|
|
using Content.Server.Speech;
|
|
using Content.Server.VoiceMask;
|
|
using Content.Shared.Chat;
|
|
using Content.Shared.Database;
|
|
using Content.Shared.Language;
|
|
using Content.Shared.Radio;
|
|
using Content.Shared.Radio.Components;
|
|
using Content.Shared.Speech;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Network;
|
|
using Robust.Shared.Player;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Random;
|
|
using Robust.Shared.Replays;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Server.Radio.EntitySystems;
|
|
|
|
/// <summary>
|
|
/// This system handles intrinsic radios and the general process of converting radio messages into chat messages.
|
|
/// </summary>
|
|
public sealed class RadioSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly INetManager _netMan = default!;
|
|
[Dependency] private readonly IReplayRecordingManager _replay = default!;
|
|
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
|
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
[Dependency] private readonly ChatSystem _chat = default!;
|
|
[Dependency] private readonly LanguageSystem _language = 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.Language);
|
|
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))
|
|
{
|
|
// Einstein-Engines - languages mechanic
|
|
var listener = component.Owner;
|
|
var msg = args.OriginalChatMsg;
|
|
if (listener != null && !_language.CanUnderstand(listener, args.Language.ID))
|
|
msg = args.LanguageObfuscatedChatMsg;
|
|
|
|
_netMan.ServerSendMessage(new MsgChatMessage { Message = msg}, actor.PlayerSession.Channel);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Send radio message to all active radio listeners
|
|
/// </summary>
|
|
public void SendRadioMessage(EntityUid messageSource, string message, ProtoId<RadioChannelPrototype> channel, EntityUid radioSource, LanguagePrototype? language = null, bool escapeMarkup = true)
|
|
{
|
|
SendRadioMessage(messageSource, message, _prototype.Index(channel), radioSource, escapeMarkup: escapeMarkup, language: language);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Send radio message to all active radio listeners
|
|
/// </summary>
|
|
/// <param name="messageSource">Entity that spoke the message</param>
|
|
/// <param name="radioSource">Entity that picked up the message and will send it, e.g. headset</param>
|
|
public void SendRadioMessage(EntityUid messageSource, string message, RadioChannelPrototype channel, EntityUid radioSource, LanguagePrototype? language = null, bool escapeMarkup = true)
|
|
{
|
|
if (language == null)
|
|
language = _language.GetLanguage(messageSource);
|
|
|
|
// TODO if radios ever garble / modify messages, feedback-prevention needs to be handled better than this.
|
|
if (!_messages.Add(message))
|
|
return;
|
|
|
|
var name = TryComp(messageSource, out VoiceMaskComponent? mask) && mask.Enabled
|
|
? mask.VoiceName
|
|
: MetaData(messageSource).EntityName;
|
|
|
|
// Delta-V: Support syrinx voice mask on radio.
|
|
if (TryComp(messageSource, out SyrinxVoiceMaskComponent? syrinx) && syrinx.Enabled)
|
|
name = syrinx.VoiceName;
|
|
|
|
name = FormattedMessage.EscapeText(name);
|
|
|
|
// most radios are relayed to chat, so lets parse the chat message beforehand
|
|
SpeechVerbPrototype speech;
|
|
if (mask != null
|
|
&& mask.Enabled
|
|
&& mask.SpeechVerb != null
|
|
&& _prototype.TryIndex<SpeechVerbPrototype>(mask.SpeechVerb, out var proto))
|
|
{
|
|
speech = proto;
|
|
}
|
|
else
|
|
speech = _chat.GetSpeechVerb(messageSource, message);
|
|
|
|
var content = escapeMarkup
|
|
? FormattedMessage.EscapeText(message)
|
|
: message;
|
|
|
|
var wrappedMessage = WrapRadioMessage(messageSource, channel, name, content);
|
|
var msg = new ChatMessage(ChatChannel.Radio, content, wrappedMessage, NetEntity.Invalid, null);
|
|
|
|
// ... you guess it
|
|
var obfuscated = _language.ObfuscateSpeech(content, language);
|
|
var obfuscatedWrapped = WrapRadioMessage(messageSource, channel, name, obfuscated);
|
|
var notUdsMsg = new ChatMessage(ChatChannel.Radio, obfuscated, obfuscatedWrapped, NetEntity.Invalid, null);
|
|
|
|
var ev = new RadioReceiveEvent(messageSource, channel, msg, notUdsMsg, language);
|
|
|
|
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 hasMicro = HasComp<RadioMicrophoneComponent>(radioSource);
|
|
|
|
var speakerQuery = GetEntityQuery<RadioSpeakerComponent>();
|
|
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 && (!hasMicro || !speakerQuery.HasComponent(receiver));
|
|
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(msg);
|
|
_messages.Remove(message);
|
|
}
|
|
|
|
private string WrapRadioMessage(EntityUid source, RadioChannelPrototype channel, string name, string message)
|
|
{
|
|
var speech = _chat.GetSpeechVerb(source, message);
|
|
return 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", 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;
|
|
}
|
|
}
|