Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Languages #2226

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Content.Client/SS220/Language/LanguageSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using Content.Shared.SS220.Language;


namespace Content.Client.SS220.Language;
public sealed class LanguageSystem : SharedLanguageSystem;

20 changes: 10 additions & 10 deletions Content.Server/Chat/Managers/ChatSanitizationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,16 @@ public bool TrySanitizeEmoteShorthands(string message,
}

// SS220 no English begin
var ntAllowed = sanitized.Replace("NanoTrasen", string.Empty, StringComparison.OrdinalIgnoreCase);
ntAllowed = ntAllowed.Replace("nt", string.Empty, StringComparison.OrdinalIgnoreCase);

// Remember, no English
if (Regex.Matches(ntAllowed, @"[a-zA-Z]").Any())
{
sanitized = string.Empty;
emote = "кашляет";
return true;
}
//var ntAllowed = sanitized.Replace("NanoTrasen", string.Empty, StringComparison.OrdinalIgnoreCase);
Jopaglazik marked this conversation as resolved.
Show resolved Hide resolved
//ntAllowed = ntAllowed.Replace("nt", string.Empty, StringComparison.OrdinalIgnoreCase);

//// Remember, no English
//if (Regex.Matches(ntAllowed, @"[a-zA-Z]").Any())
//{
// sanitized = string.Empty;
// emote = "кашляет";
// return true;
//}
// SS220 no English end

sanitized = message.Trim();
Expand Down
99 changes: 81 additions & 18 deletions Content.Server/Chat/Systems/ChatSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
using Robust.Shared.Replays;
using Robust.Shared.Utility;
using Robust.Shared.Timing;
using Content.Shared.SS220.Language; // SS220-Add-Languages-begin
using Content.Server.SS220.Language; // SS220-Add-Languages-end

namespace Content.Server.Chat.Systems;

Expand Down Expand Up @@ -63,6 +65,7 @@ public sealed partial class ChatSystem : SharedChatSystem
[Dependency] private readonly ReplacementAccentSystem _wordreplacement = default!;
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
[Dependency] private readonly ExamineSystemShared _examineSystem = default!;
[Dependency] private readonly LanguageSystem _languageSystem = default!; // SS220-Add-Languages

public const int VoiceRange = 10; // how far voice goes in world units
public const int WhisperClearRange = 2; // how far whisper goes while still being understandable, in world units
Expand Down Expand Up @@ -162,9 +165,13 @@ public void TrySendInGameICMessage(
IConsoleShell? shell = null,
ICommonSession? player = null, string? nameOverride = null,
bool checkRadioPrefix = true,
bool ignoreActionBlocker = false)
bool ignoreActionBlocker = false,
LanguagesPrototype? languageProto = null) // SS220-Add-Languages
{
TrySendInGameICMessage(source, message, desiredType, hideChat ? ChatTransmitRange.HideChat : ChatTransmitRange.Normal, hideLog, shell, player, nameOverride, checkRadioPrefix, ignoreActionBlocker);
TrySendInGameICMessage(source, message, desiredType,
hideChat ? ChatTransmitRange.HideChat : ChatTransmitRange.Normal,
hideLog, shell, player, nameOverride, checkRadioPrefix,
ignoreActionBlocker, languageProto: languageProto); // SS220-Add-Languages
}

/// <summary>
Expand All @@ -188,8 +195,8 @@ public void TrySendInGameICMessage(
ICommonSession? player = null,
string? nameOverride = null,
bool checkRadioPrefix = true,
bool ignoreActionBlocker = false
)
bool ignoreActionBlocker = false,
LanguagesPrototype? languageProto = null) // SS220-Add-Languages
{
if (HasComp<GhostComponent>(source))
{
Expand Down Expand Up @@ -285,7 +292,7 @@ public void TrySendInGameICMessage(
SendEntitySpeak(source, message, range, nameOverride, hideLog, ignoreActionBlocker);
break;
case InGameICChatType.Whisper:
SendEntityWhisper(source, message, range, null, nameOverride, hideLog, ignoreActionBlocker);
SendEntityWhisper(source, message, range, null, nameOverride, hideLog, ignoreActionBlocker, languageProto); // SS220-Add-Languages
break;
case InGameICChatType.Emote:
SendEntityEmote(source, message, range, nameOverride, hideLog: hideLog, ignoreActionBlocker: ignoreActionBlocker);
Expand Down Expand Up @@ -496,16 +503,37 @@ private void SendEntitySpeak(
}

name = FormattedMessage.EscapeText(name);
// SS220-Add-Languages begin
foreach (var (session, data) in GetRecipients(source, VoiceRange))
{
if (session.AttachedEntity is not { Valid: true } playerEntity)
continue;

var wrappedMessage = Loc.GetString(speech.Bold ? "chat-manager-entity-say-bold-wrap-message" : "chat-manager-entity-say-wrap-message",
("entityName", name),
("verb", Loc.GetString(_random.Pick(speech.SpeechVerbStrings))),
("fontType", speech.FontId),
("fontSize", speech.FontSize),
("message", FormattedMessage.EscapeText(message)));
var listener = session.AttachedEntity.Value;
var languageProto = _languageSystem.GetProto(source);

if (languageProto == null)
return;

var canUnderstand = _languageSystem.CheckLanguage(listener, languageProto);

var currentMessage = canUnderstand ? message : _languageSystem.ScrambleText(source, originalMessage, languageProto);
if (languageProto?.Color != null)
{
currentMessage = _languageSystem.SetColor(currentMessage, languageProto);
}
// SS220-Add-Languages end

SendInVoiceRange(ChatChannel.Local, message, wrappedMessage, source, range);
var wrappedMessage = Loc.GetString(speech.Bold ? "chat-manager-entity-say-bold-wrap-message" : "chat-manager-entity-say-wrap-message",
("entityName", name),
("verb", Loc.GetString(_random.Pick(speech.SpeechVerbStrings))),
("fontType", speech.FontId),
("fontSize", speech.FontSize),
("message", currentMessage /*SS220-Add-Languages*/));

_chatManager.ChatMessageToOne(ChatChannel.Local, currentMessage, wrappedMessage, source, false, session.Channel); //SS220-Add-Languages
}
//SendInVoiceRange(ChatChannel.Local, message, wrappedMessage, source, range); //SS220-Add-Languages
var ev = new EntitySpokeEvent(source, message, originalMessage, null, null);
RaiseLocalEvent(source, ev, true);

Expand Down Expand Up @@ -539,8 +567,8 @@ private void SendEntityWhisper(
RadioChannelPrototype? channel,
string? nameOverride,
bool hideLog = false,
bool ignoreActionBlocker = false
)
bool ignoreActionBlocker = false,
LanguagesPrototype? languageProto = null) // SS220-Add-Languages
{
if (!_actionBlocker.CanSpeak(source) && !ignoreActionBlocker)
return;
Expand All @@ -566,9 +594,18 @@ private void SendEntityWhisper(
name = nameEv.VoiceName;
}
name = FormattedMessage.EscapeText(name);
// SS220-Add-Languages begin
if (languageProto == null)
languageProto = _languageSystem.GetProto(source);
Jopaglazik marked this conversation as resolved.
Show resolved Hide resolved

if (languageProto?.Color != null)
{
message = _languageSystem.SetColor(message, languageProto);
}
// SS220-Add-Languages end

var wrappedMessage = Loc.GetString("chat-manager-entity-whisper-wrap-message",
("entityName", name), ("message", FormattedMessage.EscapeText(message)));
("entityName", name), ("message", message /*SS220-Add-Languages*/));

var wrappedobfuscatedMessage = Loc.GetString("chat-manager-entity-whisper-wrap-message",
("entityName", nameIdentity), ("message", FormattedMessage.EscapeText(obfuscatedMessage)));
Expand All @@ -585,17 +622,43 @@ private void SendEntityWhisper(
continue;
listener = session.AttachedEntity.Value;

// SS220-Add-Languages begin
var scrambledMessage = message;
var obfuscatedScrambledMessage = obfuscatedMessage;
var wrappedScrambledMessage = wrappedMessage;
var wrappedObfuscatedScrambledMessage = wrappedobfuscatedMessage;
var wrappedUnknownScrambledMessage = wrappedUnknownMessage;

if (!_languageSystem.CheckLanguage(listener, languageProto) && languageProto != null)
{
scrambledMessage = _languageSystem.ScrambleText(source, message, languageProto);
obfuscatedScrambledMessage = ObfuscateMessageReadability(scrambledMessage, 0.2f);

if (languageProto.Color != null)
{
scrambledMessage = _languageSystem.SetColor(scrambledMessage, languageProto);
}

wrappedScrambledMessage = Loc.GetString("chat-manager-entity-whisper-wrap-message",
("entityName", name), ("message", scrambledMessage));
wrappedObfuscatedScrambledMessage = Loc.GetString("chat-manager-entity-whisper-wrap-message",
("entityName", nameIdentity), ("message", FormattedMessage.EscapeText(obfuscatedScrambledMessage)));
wrappedUnknownScrambledMessage = Loc.GetString("chat-manager-entity-whisper-unknown-wrap-message",
("message", FormattedMessage.EscapeText(obfuscatedScrambledMessage)));
}
// SS220-Add-Languages end

if (MessageRangeCheck(session, data, range) != MessageRangeCheckResult.Full)
continue; // Won't get logged to chat, and ghosts are too far away to see the pop-up, so we just won't send it to them.

if (data.Range <= WhisperClearRange || data.Observer /* SS220 Observer-Hearing */)
_chatManager.ChatMessageToOne(ChatChannel.Whisper, message, wrappedMessage, source, false, session.Channel);
_chatManager.ChatMessageToOne(ChatChannel.Whisper, scrambledMessage, wrappedScrambledMessage /*SS220-Add-Languages*/, source, false, session.Channel);
//If listener is too far, they only hear fragments of the message
else if (_examineSystem.InRangeUnOccluded(source, listener, WhisperMuffledRange))
_chatManager.ChatMessageToOne(ChatChannel.Whisper, obfuscatedMessage, wrappedobfuscatedMessage, source, false, session.Channel);
_chatManager.ChatMessageToOne(ChatChannel.Whisper, obfuscatedScrambledMessage, wrappedObfuscatedScrambledMessage /*SS220-Add-Languages*/, source, false, session.Channel);
//If listener is too far and has no line of sight, they can't identify the whisperer's identity
else
_chatManager.ChatMessageToOne(ChatChannel.Whisper, obfuscatedMessage, wrappedUnknownMessage, source, false, session.Channel);
_chatManager.ChatMessageToOne(ChatChannel.Whisper, obfuscatedScrambledMessage, wrappedUnknownScrambledMessage /*SS220-Add-Languages*/, source, false, session.Channel);
}

_replay.RecordServerMessage(new ChatMessage(ChatChannel.Whisper, message, wrappedMessage, GetNetEntity(source), null, MessageRangeHideChatForReplay(range)));
Expand Down
10 changes: 10 additions & 0 deletions Content.Server/EntityEffects/Effects/MakeSentient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Content.Server.Speech.Components;
using Content.Shared.EntityEffects;
using Content.Shared.Mind.Components;
using Content.Shared.SS220.Language; // SS220-Add-Languages
using Robust.Shared.Prototypes;

namespace Content.Server.EntityEffects.Effects;
Expand All @@ -22,6 +23,15 @@ public override void Effect(EntityEffectBaseArgs args)
entityManager.RemoveComponent<ReplacementAccentComponent>(uid);
entityManager.RemoveComponent<MonkeyAccentComponent>(uid);

// SS220-Add-Languages begin
if (!entityManager.HasComponent<LanguageComponent>(uid))
{
var language = entityManager.AddComponent<LanguageComponent>(uid);
language.LearnedLanguages.Add(LanguagesPrototype.Galactic);
language.CurrentLanguage = language.LearnedLanguages[0];
}
// SS220-Add-Languages end

// Stops from adding a ghost role to things like people who already have a mind
if (entityManager.TryGetComponent<MindContainerComponent>(uid, out var mindContainer) && mindContainer.HasMind)
{
Expand Down
27 changes: 27 additions & 0 deletions Content.Server/PAI/PAISystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Robust.Shared.Random;
using System.Text;
using Robust.Shared.Player;
using Content.Shared.SS220.Language; // SS220-Add-Languages

namespace Content.Server.PAI;

Expand Down Expand Up @@ -55,6 +56,7 @@ private void OnMindAdded(EntityUid uid, PAIComponent component, MindAddedMessage
// Cause then you could remotely figure out information about the owner's equipped items.

_metaData.SetEntityName(uid, val);
GetUserLanguages(component.LastUser, uid); // SS220-Add-Languages
}

private void OnMindRemoved(EntityUid uid, PAIComponent component, MindRemovedMessage args)
Expand Down Expand Up @@ -117,5 +119,30 @@ public void PAITurningOff(EntityUid uid)
if (proto != null)
_metaData.SetEntityName(uid, proto.Name);
}
// SS220-Add-Languages begin
if (TryComp<LanguageComponent>(uid, out var languages))
{
languages.LearnedLanguages.Clear();
languages.LearnedLanguages.Add(LanguagesPrototype.Galactic);
languages.LearnedLanguages.Add(LanguagesPrototype.Universal);
languages.CurrentLanguage = languages.LearnedLanguages[0];
}
}

public void GetUserLanguages(EntityUid? ent, EntityUid pai)
{
if (!TryComp<LanguageComponent>(ent, out var languages) || languages == null)
return;

if (!TryComp<LanguageComponent>(pai, out var paiLanguages))
return;

foreach (var language in languages.LearnedLanguages)
{
if (!paiLanguages.LearnedLanguages.Contains(language))
paiLanguages.LearnedLanguages.Add(language);
}
Dirty(pai, paiLanguages);
}
// SS220-Add-Languages end
}
9 changes: 8 additions & 1 deletion Content.Server/Radio/EntitySystems/HeadsetSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
using Content.Shared.Radio.EntitySystems;
using Robust.Shared.Network;
using Robust.Shared.Player;
using Content.Server.SS220.Language; // SS220-Add-Languages

namespace Content.Server.Radio.EntitySystems;

public sealed class HeadsetSystem : SharedHeadsetSystem
{
[Dependency] private readonly INetManager _netMan = default!;
[Dependency] private readonly RadioSystem _radio = default!;
[Dependency] private readonly LanguageSystem _languageSystem = default!; // SS220-Add-Languages

public override void Initialize()
{
Expand Down Expand Up @@ -104,7 +106,12 @@ private void OnHeadsetReceive(EntityUid uid, HeadsetComponent component, ref Rad
var actorUid = Transform(uid).ParentUid;
if (TryComp(actorUid, out ActorComponent? actor))
{
_netMan.ServerSendMessage(args.ChatMsg, actor.PlayerSession.Channel);
// SS220-Add-Languages begin
if (_languageSystem.CheckLanguage(actorUid, args.LanguageProto))
_netMan.ServerSendMessage(args.ChatMsg, actor.PlayerSession.Channel);
else
_netMan.ServerSendMessage(args.ScrambledChatMsg, actor.PlayerSession.Channel);
// SS220-Add-Languages end
if (actorUid != args.MessageSource && TryComp(args.MessageSource, out TTSComponent? _))
{
args.Receivers.Add(actorUid);
Expand Down
14 changes: 11 additions & 3 deletions Content.Server/Radio/EntitySystems/RadioDeviceSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
using Content.Shared.Chat;
using Content.Shared.UserInterface;
using Robust.Server.GameObjects;
using Robust.Shared.Utility;
using Content.Server.SS220.Language; // SS220-Add-Languages

namespace Content.Server.Radio.EntitySystems;

Expand All @@ -34,6 +36,7 @@ public sealed class RadioDeviceSystem : EntitySystem
[Dependency] private readonly InteractionSystem _interaction = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly UserInterfaceSystem _ui = default!;
[Dependency] private readonly LanguageSystem _languageSystem = default!; // SS220-Add-Languages

// Used to prevent a shitter from using a bunch of radios to spam chat.
private HashSet<(string, EntityUid, RadioChannelPrototype)> _recentlySent = new();
Expand Down Expand Up @@ -203,10 +206,13 @@ private void OnListen(EntityUid uid, RadioMicrophoneComponent component, ListenE
if (HasComp<RadioSpeakerComponent>(args.Source))
return; // no feedback loops please.

// SS220-Add-Languages begin
var message = _languageSystem.RemoveColorTags(args.Message);
var channel = _protoMan.Index<RadioChannelPrototype>(component.BroadcastChannel)!;
if (_recentlySent.Add((args.Message, args.Source, channel)))
_radio.SendRadioMessage(args.Source, args.Message, channel, uid);
}
_radio.SendRadioMessage(args.Source, message, channel, uid);
// SS220-Add-Languages end
}

private void OnAttemptListen(EntityUid uid, RadioMicrophoneComponent component, ListenAttemptEvent args)
{
Expand All @@ -230,7 +236,9 @@ private void OnReceiveRadio(EntityUid uid, RadioSpeakerComponent component, ref
("originalName", nameEv.VoiceName));

// log to chat so people can identity the speaker/source, but avoid clogging ghost chat if there are many radios
_chat.TrySendInGameICMessage(uid, args.Message, InGameICChatType.Whisper, ChatTransmitRange.GhostRangeLimit, nameOverride: name, checkRadioPrefix: false);
_chat.TrySendInGameICMessage(uid, args.Message, InGameICChatType.Whisper,
ChatTransmitRange.GhostRangeLimit, nameOverride: name, checkRadioPrefix: false,
languageProto: args.LanguageProto); // SS220-Add-Languages
}

private void OnIntercomEncryptionChannelsChanged(Entity<IntercomComponent> ent, ref EncryptionChannelsChangedEvent args)
Expand Down
Loading
Loading