Files
crystall-punk-14/Content.Server/Chat/Managers/ChatManager.cs

394 lines
16 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Linq;
2021-06-09 22:19:39 +02:00
using Content.Server.Administration.Managers;
using Content.Server.Ghost.Components;
using Content.Server.Headset;
using Content.Server.Inventory.Components;
using Content.Server.Items;
using Content.Server.MoMMI;
using Content.Server.Preferences.Managers;
using Content.Server.Radio.EntitySystems;
using Content.Shared.ActionBlocker;
using Content.Shared.Administration;
using Content.Shared.CCVar;
using Content.Shared.Chat;
2021-06-09 22:19:39 +02:00
using Content.Shared.Inventory;
2021-09-26 15:18:45 +02:00
using Content.Shared.Popups;
using Robust.Server.GameObjects;
using Robust.Server.Player;
using Robust.Shared.Audio;
2021-02-16 20:14:32 +01:00
using Robust.Shared.Configuration;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
2020-04-09 03:08:06 +02:00
using Robust.Shared.Localization;
2021-02-12 10:45:22 +01:00
using Robust.Shared.Log;
using Robust.Shared.Network;
using Robust.Shared.Player;
using Robust.Shared.Utility;
2021-06-09 22:19:39 +02:00
using static Content.Server.Chat.Managers.IChatManager;
2021-06-09 22:19:39 +02:00
namespace Content.Server.Chat.Managers
{
/// <summary>
/// Dispatches chat messages to clients.
/// </summary>
internal sealed class ChatManager : IChatManager
{
2021-02-28 18:51:42 +01:00
private static readonly Dictionary<string, string> PatronOocColors = new()
{
// I had plans for multiple colors and those went nowhere so...
{ "nuclear_operative", "#aa00ff" },
{ "syndicate_agent", "#aa00ff" },
{ "revolutionary", "#aa00ff" }
};
[Dependency] private readonly IEntityManager _entManager = default!;
2021-02-16 20:14:32 +01:00
[Dependency] private readonly IServerNetManager _netManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IMoMMILink _mommiLink = default!;
[Dependency] private readonly IAdminManager _adminManager = default!;
[Dependency] private readonly IServerPreferencesManager _preferencesManager = default!;
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
/// <summary>
/// The maximum length a player-sent message can be sent
/// </summary>
public int MaxMessageLength => _configurationManager.GetCVar(CCVars.ChatMaxMessageLength);
private const int VoiceRange = 7; // how far voice goes in world units
//TODO: make prio based?
private readonly List<TransformChat> _chatTransformHandlers = new();
2021-02-16 20:14:32 +01:00
private bool _oocEnabled = true;
private bool _adminOocEnabled = true;
public void Initialize()
{
_netManager.RegisterNetMessage<MsgChatMessage>();
2021-02-16 20:14:32 +01:00
_configurationManager.OnValueChanged(CCVars.OocEnabled, OnOocEnabledChanged, true);
_configurationManager.OnValueChanged(CCVars.AdminOocEnabled, OnAdminOocEnabledChanged, true);
}
private void OnOocEnabledChanged(bool val)
{
_oocEnabled = val;
DispatchServerAnnouncement(Loc.GetString(val ? "chat-manager-ooc-chat-enabled-message" : "chat-manager-ooc-chat-disabled-message"));
2021-02-16 20:14:32 +01:00
}
private void OnAdminOocEnabledChanged(bool val)
{
_adminOocEnabled = val;
DispatchServerAnnouncement(Loc.GetString(val ? "chat-manager-admin-ooc-chat-enabled-message" : "chat-manager-admin-ooc-chat-disabled-message"));
}
public void DispatchServerAnnouncement(string message)
{
var msg = _netManager.CreateNetMessage<MsgChatMessage>();
msg.Channel = ChatChannel.Server;
msg.Message = message;
msg.MessageWrap = Loc.GetString("chat-manager-server-wrap-message");
_netManager.ServerSendToAll(msg);
2021-02-12 10:45:22 +01:00
Logger.InfoS("SERVER", message);
}
public void DispatchStationAnnouncement(string message, string sender = "CentComm", bool playDefaultSound = true)
{
var msg = _netManager.CreateNetMessage<MsgChatMessage>();
msg.Channel = ChatChannel.Radio;
msg.Message = message;
msg.MessageWrap = Loc.GetString("chat-manager-sender-announcement-wrap-message", ("sender", sender));
_netManager.ServerSendToAll(msg);
if (playDefaultSound)
{
SoundSystem.Play(Filter.Broadcast(), "/Audio/Announcements/announce.ogg", AudioParams.Default.WithVolume(-2f));
}
}
public void DispatchServerMessage(IPlayerSession player, string message)
{
var msg = _netManager.CreateNetMessage<MsgChatMessage>();
msg.Channel = ChatChannel.Server;
msg.Message = message;
msg.MessageWrap = Loc.GetString("chat-manager-server-wrap-message");
_netManager.ServerSendMessage(msg, player.ConnectedClient);
}
2021-11-19 07:36:25 +01:00
public void EntitySay(IEntity source, string message, bool hideChat=false)
{
if (!EntitySystem.Get<ActionBlockerSystem>().CanSpeak(source.Uid))
{
return;
}
// Check if message exceeds the character limit if the sender is a player
if (source.TryGetComponent(out ActorComponent? actor) &&
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
message.Length > MaxMessageLength)
{
var feedback = Loc.GetString("chat-manager-max-message-length-exceeded-message", ("limit", MaxMessageLength));
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
DispatchServerMessage(actor.PlayerSession, feedback);
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
return;
}
foreach (var handler in _chatTransformHandlers)
{
//TODO: rather return a bool and use a out var?
message = handler(source.Uid, message);
}
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
message = message.Trim();
// We'll try to avoid using MapPosition as EntityCoordinates can early-out and potentially be faster for common use cases
// Downside is it may potentially convert to MapPosition unnecessarily.
var sourceMapId = source.Transform.MapID;
var sourceCoords = source.Transform.Coordinates;
var clients = new List<INetChannel>();
foreach (var player in _playerManager.Sessions)
{
if (player.AttachedEntity == null) continue;
var transform = player.AttachedEntity.Transform;
if (transform.MapID != sourceMapId ||
!player.AttachedEntity.HasComponent<GhostComponent>() &&
!sourceCoords.InRange(_entManager, transform.Coordinates, VoiceRange)) continue;
clients.Add(player.ConnectedClient);
}
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
if (message.StartsWith(';'))
{
// Remove semicolon
message = message.Substring(1).TrimStart();
// Capitalize first letter
message = message[0].ToString().ToUpper() +
2020-11-01 23:56:35 +01:00
message.Remove(0, 1);
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
if (source.TryGetComponent(out InventoryComponent? inventory) &&
inventory.TryGetSlotItem(EquipmentSlotDefines.Slots.EARS, out ItemComponent? item) &&
item.Owner.TryGetComponent(out HeadsetComponent? headset))
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
{
headset.RadioRequested = true;
}
else
{
source.PopupMessage(Loc.GetString("chat-manager-no-headset-on-message"));
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
}
}
else
{
// Capitalize first letter
message = message[0].ToString().ToUpper() +
2020-11-01 23:56:35 +01:00
message.Remove(0, 1);
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
}
var listeners = EntitySystem.Get<ListeningSystem>();
listeners.PingListeners(source, message);
message = FormattedMessage.EscapeText(message);
var msg = _netManager.CreateNetMessage<MsgChatMessage>();
msg.Channel = ChatChannel.Local;
msg.Message = message;
msg.MessageWrap = Loc.GetString("chat-manager-entity-say-wrap-message",("entityName", source.Name));
msg.SenderEntity = source.Uid;
2021-11-19 07:36:25 +01:00
msg.HideChat = hideChat;
_netManager.ServerSendToMany(msg, clients);
}
public void EntityMe(IEntity source, string action)
{
if (!EntitySystem.Get<ActionBlockerSystem>().CanEmote(source.Uid))
{
return;
}
// Check if entity is a player
if (!source.TryGetComponent(out ActorComponent? actor))
2021-02-16 20:14:32 +01:00
{
return;
}
// Check if message exceeds the character limit
if (action.Length > MaxMessageLength)
2021-02-16 20:14:32 +01:00
{
DispatchServerMessage(actor.PlayerSession, Loc.GetString("chat-manager-max-message-length-exceeded-message",("limit", MaxMessageLength)));
2021-02-16 20:14:32 +01:00
return;
}
action = FormattedMessage.EscapeText(action);
var clients = Filter.Empty()
.AddInRange(source.Transform.MapPosition, VoiceRange)
.Recipients
.Select(p => p.ConnectedClient)
.ToList();
var msg = _netManager.CreateNetMessage<MsgChatMessage>();
msg.Channel = ChatChannel.Emotes;
msg.Message = action;
msg.MessageWrap = Loc.GetString("chat-manager-entity-me-wrap-message", ("entityName",source.Name));
msg.SenderEntity = source.Uid;
_netManager.ServerSendToMany(msg, clients);
}
public void SendOOC(IPlayerSession player, string message)
{
2021-02-16 20:14:32 +01:00
if (_adminManager.IsAdmin(player))
{
if (!_adminOocEnabled)
{
return;
}
}
else if (!_oocEnabled)
{
return;
}
// Check if message exceeds the character limit
if (message.Length > MaxMessageLength)
{
DispatchServerMessage(player, Loc.GetString("chat-manager-max-message-length-exceeded-message", ("limit", MaxMessageLength)));
return;
}
message = FormattedMessage.EscapeText(message);
var msg = _netManager.CreateNetMessage<MsgChatMessage>();
msg.Channel = ChatChannel.OOC;
msg.Message = message;
msg.MessageWrap = Loc.GetString("chat-manager-send-ooc-wrap-message", ("playerName",player.Name));
if (_adminManager.HasAdminFlag(player, AdminFlags.Admin))
{
2021-02-16 20:14:32 +01:00
var prefs = _preferencesManager.GetPreferences(player.UserId);
msg.MessageColorOverride = prefs.AdminOOCColor;
}
2021-02-28 18:51:42 +01:00
if (player.ConnectedClient.UserData.PatronTier is { } patron &&
PatronOocColors.TryGetValue(patron, out var patronColor))
{
msg.MessageWrap = Loc.GetString("chat-manager-send-ooc-patron-wrap-message", ("patronColor", patronColor),("playerName", player.Name));
2021-02-28 18:51:42 +01:00
}
//TODO: player.Name color, this will need to change the structure of the MsgChatMessage
_netManager.ServerSendToAll(msg);
2019-04-17 23:31:43 +02:00
_mommiLink.SendOOCMessage(player.Name, message);
2019-04-17 23:31:43 +02:00
}
2020-03-30 01:15:43 +02:00
public void SendDeadChat(IPlayerSession player, string message)
{
// Check if message exceeds the character limit
if (message.Length > MaxMessageLength)
{
DispatchServerMessage(player, Loc.GetString("chat-manager-max-message-length-exceeded-message",("limit", MaxMessageLength)));
return;
}
message = FormattedMessage.EscapeText(message);
var clients = GetDeadChatClients();
2020-03-30 01:15:43 +02:00
var msg = _netManager.CreateNetMessage<MsgChatMessage>();
msg.Channel = ChatChannel.Dead;
msg.Message = message;
msg.MessageWrap = Loc.GetString("chat-manager-send-dead-chat-wrap-message",
("deadChannelName", Loc.GetString("chat-manager-dead-channel-name")),
("playerName", player.AttachedEntity?.Name ?? "???"));
2020-04-09 03:31:40 +02:00
msg.SenderEntity = player.AttachedEntityUid.GetValueOrDefault();
2020-03-30 01:15:43 +02:00
_netManager.ServerSendToMany(msg, clients.ToList());
}
public void SendAdminDeadChat(IPlayerSession player, string message)
{
// Check if message exceeds the character limit
if (message.Length > MaxMessageLength)
{
DispatchServerMessage(player, Loc.GetString("chat-manager-max-message-length-exceeded-message", ("limit", MaxMessageLength)));
return;
}
message = FormattedMessage.EscapeText(message);
var clients = GetDeadChatClients();
var msg = _netManager.CreateNetMessage<MsgChatMessage>();
msg.Channel = ChatChannel.Dead;
msg.Message = message;
msg.MessageWrap = Loc.GetString("chat-manager-send-admin-dead-chat-wrap-message",
("adminChannelName", Loc.GetString("chat-manager-admin-channel-name")),
("userName", player.ConnectedClient.UserName));
_netManager.ServerSendToMany(msg, clients.ToList());
}
private IEnumerable<INetChannel> GetDeadChatClients()
{
return Filter.Empty()
.AddWhereAttachedEntity(uid => _entManager.HasComponent<GhostComponent>(uid))
.Recipients
.Union(_adminManager.ActiveAdmins)
.Select(p => p.ConnectedClient);
}
public void SendAdminChat(IPlayerSession player, string message)
{
// Check if message exceeds the character limit
if (message.Length > MaxMessageLength)
{
DispatchServerMessage(player, Loc.GetString("chat-manager-max-message-length-exceeded-message", ("limit", MaxMessageLength)));
return;
}
message = FormattedMessage.EscapeText(message);
var clients = _adminManager.ActiveAdmins.Select(p => p.ConnectedClient);
var msg = _netManager.CreateNetMessage<MsgChatMessage>();
Chat improvements. (#4283) * UI is an abbreviation, in XAML. * Chat improvements. Changing the "selected" channel on the chat box is now only done via the tab cycle or clicking the button. Prefix chars like [ will temporarily replace the active chat channel. This is based 100% on message box contents so there's no input eating garbage or anything. Pressing specific channel focusing keys inserts the correct prefix character, potentially replacing an existing one. Existing chat contents are left in place just fine and selected so you can easily delete them (but are not forced to). Channel focusing keys now match the QWERTY key codes. Deadchat works now. Console can no longer be selected as a chat channel, but you can still use it with the / prefix. Refactored the connection between chat manager and chat box so that it's event based, reducing tons of spaghetti everywhere. Main chat box control uses XAML now. General cleanup. Added focus hotkeys for deadchat/console. Also added prefix for deadchat. Local chat is mapped to deadchat when a ghost. Probably more stuff I can't think of right now. * Add preferred channel system to chat box to automatically select local. I can't actually test this works because the non-lobby chat box code is complete disastrous spaghetti and i need to refactor it. * Move chatbox resizing and all that to a subclass. Refine preferred channel & deadchat mapping code further. * Don't do prefixes for channels you don't have access to. * Change format on channel select popup. * Clean up code with console handling somewhat.
2021-07-20 10:29:09 +02:00
msg.Channel = ChatChannel.Admin;
msg.Message = message;
msg.MessageWrap = Loc.GetString("chat-manager-send-admin-chat-wrap-message",
("adminChannelName", Loc.GetString("chat-manager-admin-channel-name")),
("playerName", player.Name));
_netManager.ServerSendToMany(msg, clients.ToList());
}
2020-11-01 23:56:35 +01:00
public void SendAdminAnnouncement(string message)
{
var clients = _adminManager.ActiveAdmins.Select(p => p.ConnectedClient);
message = FormattedMessage.EscapeText(message);
2020-11-01 23:56:35 +01:00
var msg = _netManager.CreateNetMessage<MsgChatMessage>();
Chat improvements. (#4283) * UI is an abbreviation, in XAML. * Chat improvements. Changing the "selected" channel on the chat box is now only done via the tab cycle or clicking the button. Prefix chars like [ will temporarily replace the active chat channel. This is based 100% on message box contents so there's no input eating garbage or anything. Pressing specific channel focusing keys inserts the correct prefix character, potentially replacing an existing one. Existing chat contents are left in place just fine and selected so you can easily delete them (but are not forced to). Channel focusing keys now match the QWERTY key codes. Deadchat works now. Console can no longer be selected as a chat channel, but you can still use it with the / prefix. Refactored the connection between chat manager and chat box so that it's event based, reducing tons of spaghetti everywhere. Main chat box control uses XAML now. General cleanup. Added focus hotkeys for deadchat/console. Also added prefix for deadchat. Local chat is mapped to deadchat when a ghost. Probably more stuff I can't think of right now. * Add preferred channel system to chat box to automatically select local. I can't actually test this works because the non-lobby chat box code is complete disastrous spaghetti and i need to refactor it. * Move chatbox resizing and all that to a subclass. Refine preferred channel & deadchat mapping code further. * Don't do prefixes for channels you don't have access to. * Change format on channel select popup. * Clean up code with console handling somewhat.
2021-07-20 10:29:09 +02:00
msg.Channel = ChatChannel.Admin;
2020-11-01 23:56:35 +01:00
msg.Message = message;
msg.MessageWrap = Loc.GetString("chat-manager-send-admin-announcement-wrap-message",
("adminChannelName", Loc.GetString("chat-manager-admin-channel-name")));
2020-11-01 23:56:35 +01:00
_netManager.ServerSendToMany(msg, clients.ToList());
}
2019-04-17 23:31:43 +02:00
public void SendHookOOC(string sender, string message)
{
message = FormattedMessage.EscapeText(message);
2019-04-17 23:31:43 +02:00
var msg = _netManager.CreateNetMessage<MsgChatMessage>();
msg.Channel = ChatChannel.OOC;
msg.Message = message;
msg.MessageWrap = Loc.GetString("chat-manager-send-hook-ooc-wrap-message", ("senderName", sender));
2019-04-17 23:31:43 +02:00
_netManager.ServerSendToAll(msg);
}
public void RegisterChatTransform(TransformChat handler)
{
// TODO: Literally just make this an event...
_chatTransformHandlers.Add(handler);
}
}
}