mirror of
https://github.com/corvax-team/ss14-wl.git
synced 2026-02-15 03:31:38 +01:00
# Conflicts: # Content.Packaging/ServerPackaging.cs # Resources/Prototypes/Accents/word_replacements.yml # Resources/Prototypes/Entities/Clothing/Neck/mantles.yml # Resources/Prototypes/Entities/Structures/Doors/Airlocks/highsec.yml # Resources/Prototypes/Maps/marathon.yml # Resources/Prototypes/Maps/packed.yml # Resources/Prototypes/Roles/Jobs/Engineering/atmospheric_technician.yml # Resources/Prototypes/Roles/Jobs/Security/detective.yml # Resources/Textures/Clothing/Head/Hardsuits/cybersun.rsi/meta.json # Resources/Textures/Clothing/Head/Hardsuits/spatiohelm.rsi/meta.json # Resources/Textures/Clothing/Head/Hardsuits/syndiecommander.rsi/meta.json # Resources/Textures/Clothing/Head/Hardsuits/syndieelite.rsi/meta.json # Resources/Textures/Clothing/Head/Helmets/atmos_firehelmet.rsi/meta.json # Resources/Textures/Clothing/Head/Helmets/paramedhelm.rsi/meta.json # Resources/Textures/Clothing/Mask/plaguedoctormask.rsi/meta.json # Resources/Textures/Clothing/Neck/Cloaks/capcloakformal.rsi/meta.json # Resources/Textures/Clothing/Neck/mantles/capmantle.rsi/meta.json # Resources/Textures/Clothing/Neck/mantles/cemantle.rsi/meta.json # Resources/Textures/Clothing/Neck/mantles/cmomantle.rsi/meta.json # Resources/Textures/Clothing/Neck/mantles/hopmantle.rsi/meta.json # Resources/Textures/Clothing/Neck/mantles/hosmantle.rsi/meta.json # Resources/Textures/Clothing/Neck/mantles/rdmantle.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/Armor/lingarmor.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/Coats/labcoat.rsi/equipped-OUTERCLOTHING.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat.rsi/icon-open.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat.rsi/icon.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat.rsi/inhand-left.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat.rsi/inhand-right.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/Coats/labcoat.rsi/open-equipped-OUTERCLOTHING.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat.rsi/open-inhand-left.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat.rsi/open-inhand-right.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_chem.rsi/equipped-OUTERCLOTHING.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_chem.rsi/icon-open.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_chem.rsi/icon.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_chem.rsi/inhand-left.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_chem.rsi/inhand-right.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_chem.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_chem.rsi/open-equipped-OUTERCLOTHING.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_chem.rsi/open-inhand-left.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_chem.rsi/open-inhand-right.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_cmo.rsi/equipped-OUTERCLOTHING.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_cmo.rsi/icon-open.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_cmo.rsi/icon.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_cmo.rsi/inhand-left.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_cmo.rsi/inhand-right.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_cmo.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_cmo.rsi/open-equipped-OUTERCLOTHING.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_gene.rsi/equipped-OUTERCLOTHING.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_gene.rsi/icon.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_gene.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_robo.rsi/equipped-OUTERCLOTHING.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_robo.rsi/icon.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_robo.rsi/inhand-left.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_robo.rsi/inhand-right.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_robo.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_sci.rsi/equipped-OUTERCLOTHING-reptilian.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_sci.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_sci.rsi/open-equipped-OUTERCLOTHING-reptilian.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_viro.rsi/equipped-OUTERCLOTHING.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_viro.rsi/icon.png # Resources/Textures/Clothing/OuterClothing/Coats/labcoat_viro.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/Coats/rndcoat.rsi/equipped-OUTERCLOTHING.png # Resources/Textures/Clothing/OuterClothing/Coats/rndcoat.rsi/icon.png # Resources/Textures/Clothing/OuterClothing/Hardsuits/cybersun.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/Hardsuits/paramed.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/Hardsuits/spatio.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/Hardsuits/syndiecommander.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/Hardsuits/syndieelite.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/Suits/atmos_firesuit.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coat.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatatmos.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatcap.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatcargo.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatce.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatcentcom.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatchem.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatcmo.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatengi.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatgen.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coathop.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coathos.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coathydro.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatjani.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatmed.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatmime.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatminer.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatparamed.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatqm.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatrd.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatrobo.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatsci.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatsec.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatviro.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatwarden.rsi/meta.json # Resources/Textures/Clothing/Shoes/Boots/combatboots.rsi/meta.json # Resources/Textures/Clothing/Shoes/Specific/bling.rsi/meta.json # Resources/Textures/Clothing/Uniforms/Jumpskirt/atmosf.rsi/meta.json # Resources/Textures/Clothing/Uniforms/Jumpskirt/capformaldress.rsi/meta.json # Resources/Textures/Clothing/Uniforms/Jumpskirt/operative_s.rsi/meta.json # Resources/Textures/Clothing/Uniforms/Jumpsuit/atmos.rsi/meta.json # Resources/Textures/Clothing/Uniforms/Jumpsuit/capformal.rsi/meta.json # Resources/Textures/Clothing/Uniforms/Jumpsuit/centcom_officer.rsi/meta.json # Resources/Textures/Clothing/Uniforms/Jumpsuit/centcomformal.rsi/meta.json # Resources/Textures/Clothing/Uniforms/Jumpsuit/hosformal.rsi/meta.json # Resources/Textures/Clothing/Uniforms/Jumpsuit/journalist.rsi/meta.json # Resources/Textures/Clothing/Uniforms/Jumpsuit/operative.rsi/meta.json # Resources/Textures/Clothing/Uniforms/Jumpsuit/psychologist.rsi/meta.json # Resources/Textures/Clothing/Uniforms/Jumpsuit/reporter.rsi/meta.json # Resources/Textures/Mobs/Animals/regalrat.rsi/meta.json # Resources/Textures/Objects/Storage/boxes.rsi/meta.json # Resources/Textures/Objects/Weapons/Guns/Battery/antiquelasergun.rsi/meta.json # Resources/Textures/Structures/Doors/Airlocks/Glass/atmospherics.rsi/meta.json # Resources/Textures/Structures/Doors/Airlocks/Standard/atmospherics.rsi/meta.json # Resources/Textures/Structures/Doors/Airlocks/highsec/highsec.rsi/meta.json # Resources/Textures/Structures/Furniture/chairs.rsi/meta.json # Resources/Textures/Structures/Holo/holofan.rsi/meta.json # Resources/Textures/Structures/Holo/wetfloor.rsi/meta.json
408 lines
18 KiB
C#
408 lines
18 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using Content.Corvax.Interfaces.Server;
|
|
using Content.Server.Administration.Logs;
|
|
using Content.Server.Administration.Managers;
|
|
using Content.Server.Administration.Systems;
|
|
using Content.Server.MoMMI;
|
|
using Content.Server.Preferences.Managers;
|
|
using Content.Shared.Administration;
|
|
using Content.Shared.CCVar;
|
|
using Content.Shared.Chat;
|
|
using Content.Shared.Database;
|
|
using Content.Shared.Mind;
|
|
using Robust.Server.Player;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.Network;
|
|
using Robust.Shared.Player;
|
|
using Robust.Shared.Replays;
|
|
using Robust.Shared.Timing;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Server.Chat.Managers
|
|
{
|
|
/// <summary>
|
|
/// Dispatches chat messages to clients.
|
|
/// </summary>
|
|
internal sealed partial class ChatManager : IChatManager
|
|
{
|
|
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 IReplayRecordingManager _replay = default!;
|
|
[Dependency] private readonly IServerNetManager _netManager = default!;
|
|
[Dependency] private readonly IMoMMILink _mommiLink = default!;
|
|
[Dependency] private readonly IAdminManager _adminManager = default!;
|
|
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
|
[Dependency] private readonly IServerPreferencesManager _preferencesManager = default!;
|
|
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
|
[Dependency] private readonly INetConfigurationManager _netConfigManager = default!;
|
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
private IServerSponsorsManager? _sponsorsManager; // Corvax-Sponsors
|
|
|
|
/// <summary>
|
|
/// The maximum length a player-sent message can be sent
|
|
/// </summary>
|
|
public int MaxMessageLength => _configurationManager.GetCVar(CCVars.ChatMaxMessageLength);
|
|
|
|
private bool _oocEnabled = true;
|
|
private bool _adminOocEnabled = true;
|
|
|
|
private readonly Dictionary<NetUserId, ChatUser> _players = new();
|
|
|
|
public void Initialize()
|
|
{
|
|
IoCManager.Instance!.TryResolveType(out _sponsorsManager); // Corvax-Sponsors
|
|
_netManager.RegisterNetMessage<MsgChatMessage>();
|
|
_netManager.RegisterNetMessage<MsgDeleteChatMessagesBy>();
|
|
|
|
_configurationManager.OnValueChanged(CCVars.OocEnabled, OnOocEnabledChanged, true);
|
|
_configurationManager.OnValueChanged(CCVars.AdminOocEnabled, OnAdminOocEnabledChanged, true);
|
|
|
|
_playerManager.PlayerStatusChanged += PlayerStatusChanged;
|
|
}
|
|
|
|
private void OnOocEnabledChanged(bool val)
|
|
{
|
|
if (_oocEnabled == val) return;
|
|
|
|
_oocEnabled = val;
|
|
DispatchServerAnnouncement(Loc.GetString(val ? "chat-manager-ooc-chat-enabled-message" : "chat-manager-ooc-chat-disabled-message"));
|
|
}
|
|
|
|
private void OnAdminOocEnabledChanged(bool val)
|
|
{
|
|
if (_adminOocEnabled == val) return;
|
|
|
|
_adminOocEnabled = val;
|
|
DispatchServerAnnouncement(Loc.GetString(val ? "chat-manager-admin-ooc-chat-enabled-message" : "chat-manager-admin-ooc-chat-disabled-message"));
|
|
}
|
|
|
|
public void DeleteMessagesBy(ICommonSession player)
|
|
{
|
|
if (!_players.TryGetValue(player.UserId, out var user))
|
|
return;
|
|
|
|
var msg = new MsgDeleteChatMessagesBy { Key = user.Key, Entities = user.Entities };
|
|
_netManager.ServerSendToAll(msg);
|
|
}
|
|
|
|
[return: NotNullIfNotNull(nameof(author))]
|
|
public ChatUser? EnsurePlayer(NetUserId? author)
|
|
{
|
|
if (author == null)
|
|
return null;
|
|
|
|
ref var user = ref CollectionsMarshal.GetValueRefOrAddDefault(_players, author.Value, out var exists);
|
|
if (!exists || user == null)
|
|
user = new ChatUser(_players.Count);
|
|
|
|
return user;
|
|
}
|
|
|
|
#region Server Announcements
|
|
|
|
public void DispatchServerAnnouncement(string message, Color? colorOverride = null)
|
|
{
|
|
var wrappedMessage = Loc.GetString("chat-manager-server-wrap-message", ("message", FormattedMessage.EscapeText(message)));
|
|
ChatMessageToAll(ChatChannel.Server, message, wrappedMessage, EntityUid.Invalid, hideChat: false, recordReplay: true, colorOverride: colorOverride);
|
|
Logger.InfoS("SERVER", message);
|
|
|
|
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Server announcement: {message}");
|
|
}
|
|
|
|
public void DispatchServerMessage(ICommonSession player, string message, bool suppressLog = false)
|
|
{
|
|
var wrappedMessage = Loc.GetString("chat-manager-server-wrap-message", ("message", FormattedMessage.EscapeText(message)));
|
|
ChatMessageToOne(ChatChannel.Server, message, wrappedMessage, default, false, player.Channel);
|
|
|
|
if (!suppressLog)
|
|
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Server message to {player:Player}: {message}");
|
|
}
|
|
|
|
public void SendAdminAnnouncement(string message, AdminFlags? flagBlacklist, AdminFlags? flagWhitelist)
|
|
{
|
|
var clients = _adminManager.ActiveAdmins.Where(p =>
|
|
{
|
|
var adminData = _adminManager.GetAdminData(p);
|
|
|
|
DebugTools.AssertNotNull(adminData);
|
|
|
|
if (adminData == null)
|
|
return false;
|
|
|
|
if (flagBlacklist != null && adminData.HasFlag(flagBlacklist.Value))
|
|
return false;
|
|
|
|
return flagWhitelist == null || adminData.HasFlag(flagWhitelist.Value);
|
|
|
|
}).Select(p => p.Channel);
|
|
|
|
var wrappedMessage = Loc.GetString("chat-manager-send-admin-announcement-wrap-message",
|
|
("adminChannelName", Loc.GetString("chat-manager-admin-channel-name")), ("message", FormattedMessage.EscapeText(message)));
|
|
|
|
ChatMessageToMany(ChatChannel.Admin, message, wrappedMessage, default, false, true, clients);
|
|
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Admin announcement: {message}");
|
|
}
|
|
|
|
public void SendAdminAlert(string message)
|
|
{
|
|
var clients = _adminManager.ActiveAdmins.Select(p => p.Channel);
|
|
|
|
var wrappedMessage = Loc.GetString("chat-manager-send-admin-announcement-wrap-message",
|
|
("adminChannelName", Loc.GetString("chat-manager-admin-channel-name")), ("message", FormattedMessage.EscapeText(message)));
|
|
|
|
ChatMessageToMany(ChatChannel.AdminAlert, message, wrappedMessage, default, false, true, clients);
|
|
}
|
|
|
|
public void SendAdminAlert(EntityUid player, string message)
|
|
{
|
|
var mindSystem = _entityManager.System<SharedMindSystem>();
|
|
if (!mindSystem.TryGetMind(player, out var mindId, out var mind))
|
|
{
|
|
SendAdminAlert(message);
|
|
return;
|
|
}
|
|
|
|
var adminSystem = _entityManager.System<AdminSystem>();
|
|
var antag = mind.UserId != null && (adminSystem.GetCachedPlayerInfo(mind.UserId.Value)?.Antag ?? false);
|
|
|
|
SendAdminAlert($"{mind.Session?.Name}{(antag ? " (ANTAG)" : "")} {message}");
|
|
}
|
|
|
|
public void SendHookOOC(string sender, string message)
|
|
{
|
|
if (!_oocEnabled && _configurationManager.GetCVar(CCVars.DisablingOOCDisablesRelay))
|
|
{
|
|
return;
|
|
}
|
|
var wrappedMessage = Loc.GetString("chat-manager-send-hook-ooc-wrap-message", ("senderName", sender), ("message", FormattedMessage.EscapeText(message)));
|
|
ChatMessageToAll(ChatChannel.OOC, message, wrappedMessage, source: EntityUid.Invalid, hideChat: false, recordReplay: true);
|
|
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Hook OOC from {sender}: {message}");
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Public OOC Chat API
|
|
|
|
/// <summary>
|
|
/// Called for a player to attempt sending an OOC, out-of-game. message.
|
|
/// </summary>
|
|
/// <param name="player">The player sending the message.</param>
|
|
/// <param name="message">The message.</param>
|
|
/// <param name="type">The type of message.</param>
|
|
public void TrySendOOCMessage(ICommonSession player, string message, OOCChatType type)
|
|
{
|
|
if (!HandleRateLimit(player))
|
|
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;
|
|
}
|
|
|
|
switch (type)
|
|
{
|
|
case OOCChatType.OOC:
|
|
SendOOC(player, message);
|
|
break;
|
|
case OOCChatType.Admin:
|
|
SendAdminChat(player, message);
|
|
break;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Private API
|
|
|
|
private void SendOOC(ICommonSession player, string message)
|
|
{
|
|
if (_adminManager.IsAdmin(player))
|
|
{
|
|
if (!_adminOocEnabled)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
else if (!_oocEnabled)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Color? colorOverride = null;
|
|
var wrappedMessage = Loc.GetString("chat-manager-send-ooc-wrap-message", ("playerName",player.Name), ("message", FormattedMessage.EscapeText(message)));
|
|
if (_adminManager.HasAdminFlag(player, AdminFlags.Admin))
|
|
{
|
|
var prefs = _preferencesManager.GetPreferences(player.UserId);
|
|
colorOverride = prefs.AdminOOCColor;
|
|
}
|
|
if (player.Channel.UserData.PatronTier is { } patron &&
|
|
PatronOocColors.TryGetValue(patron, out var patronColor))
|
|
{
|
|
wrappedMessage = Loc.GetString("chat-manager-send-ooc-patron-wrap-message", ("patronColor", patronColor),("playerName", player.Name), ("message", FormattedMessage.EscapeText(message)));
|
|
}
|
|
|
|
// Corvax-Sponsors-Start
|
|
if (_sponsorsManager != null && _sponsorsManager.TryGetOocColor(player.UserId, out var oocColor))
|
|
{
|
|
wrappedMessage = Loc.GetString("chat-manager-send-ooc-patron-wrap-message", ("patronColor", oocColor),("playerName", player.Name), ("message", FormattedMessage.EscapeText(message)));
|
|
}
|
|
// Corvax-Sponsors-End
|
|
|
|
//TODO: player.Name color, this will need to change the structure of the MsgChatMessage
|
|
ChatMessageToAll(ChatChannel.OOC, message, wrappedMessage, EntityUid.Invalid, hideChat: false, recordReplay: true, colorOverride: colorOverride, author: player.UserId);
|
|
_mommiLink.SendOOCMessage(player.Name, message);
|
|
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"OOC from {player:Player}: {message}");
|
|
}
|
|
|
|
private void SendAdminChat(ICommonSession player, string message)
|
|
{
|
|
if (!_adminManager.IsAdmin(player))
|
|
{
|
|
_adminLogger.Add(LogType.Chat, LogImpact.Extreme, $"{player:Player} attempted to send admin message but was not admin");
|
|
return;
|
|
}
|
|
|
|
var clients = _adminManager.ActiveAdmins.Select(p => p.Channel);
|
|
var wrappedMessage = Loc.GetString("chat-manager-send-admin-chat-wrap-message",
|
|
("adminChannelName", Loc.GetString("chat-manager-admin-channel-name")),
|
|
("playerName", player.Name), ("message", FormattedMessage.EscapeText(message)));
|
|
|
|
foreach (var client in clients)
|
|
{
|
|
var isSource = client != player.Channel;
|
|
ChatMessageToOne(ChatChannel.AdminChat,
|
|
message,
|
|
wrappedMessage,
|
|
default,
|
|
false,
|
|
client,
|
|
audioPath: isSource ? _netConfigManager.GetClientCVar(client, CCVars.AdminChatSoundPath) : default,
|
|
audioVolume: isSource ? _netConfigManager.GetClientCVar(client, CCVars.AdminChatSoundVolume) : default,
|
|
author: player.UserId);
|
|
}
|
|
|
|
_adminLogger.Add(LogType.Chat, $"Admin chat from {player:Player}: {message}");
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Utility
|
|
|
|
public void ChatMessageToOne(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, INetChannel client, Color? colorOverride = null, bool recordReplay = false, string? audioPath = null, float audioVolume = 0, NetUserId? author = null)
|
|
{
|
|
var user = author == null ? null : EnsurePlayer(author);
|
|
var netSource = _entityManager.GetNetEntity(source);
|
|
user?.AddEntity(netSource);
|
|
|
|
var msg = new ChatMessage(channel, message, wrappedMessage, netSource, user?.Key, hideChat, colorOverride, audioPath, audioVolume);
|
|
_netManager.ServerSendMessage(new MsgChatMessage() { Message = msg }, client);
|
|
|
|
if (!recordReplay)
|
|
return;
|
|
|
|
if ((channel & ChatChannel.AdminRelated) == 0 ||
|
|
_configurationManager.GetCVar(CCVars.ReplayRecordAdminChat))
|
|
{
|
|
_replay.RecordServerMessage(msg);
|
|
}
|
|
}
|
|
|
|
public void ChatMessageToMany(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, IEnumerable<INetChannel> clients, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0, NetUserId? author = null)
|
|
=> ChatMessageToMany(channel, message, wrappedMessage, source, hideChat, recordReplay, clients.ToList(), colorOverride, audioPath, audioVolume, author);
|
|
|
|
public void ChatMessageToMany(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, List<INetChannel> clients, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0, NetUserId? author = null)
|
|
{
|
|
var user = author == null ? null : EnsurePlayer(author);
|
|
var netSource = _entityManager.GetNetEntity(source);
|
|
user?.AddEntity(netSource);
|
|
|
|
var msg = new ChatMessage(channel, message, wrappedMessage, netSource, user?.Key, hideChat, colorOverride, audioPath, audioVolume);
|
|
_netManager.ServerSendToMany(new MsgChatMessage() { Message = msg }, clients);
|
|
|
|
if (!recordReplay)
|
|
return;
|
|
|
|
if ((channel & ChatChannel.AdminRelated) == 0 ||
|
|
_configurationManager.GetCVar(CCVars.ReplayRecordAdminChat))
|
|
{
|
|
_replay.RecordServerMessage(msg);
|
|
}
|
|
}
|
|
|
|
public void ChatMessageToManyFiltered(Filter filter, ChatChannel channel, string message, string wrappedMessage, EntityUid source,
|
|
bool hideChat, bool recordReplay, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0)
|
|
{
|
|
if (!recordReplay && !filter.Recipients.Any())
|
|
return;
|
|
|
|
var clients = new List<INetChannel>();
|
|
foreach (var recipient in filter.Recipients)
|
|
{
|
|
clients.Add(recipient.Channel);
|
|
}
|
|
|
|
ChatMessageToMany(channel, message, wrappedMessage, source, hideChat, recordReplay, clients, colorOverride, audioPath, audioVolume);
|
|
}
|
|
|
|
public void ChatMessageToAll(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0, NetUserId? author = null)
|
|
{
|
|
var user = author == null ? null : EnsurePlayer(author);
|
|
var netSource = _entityManager.GetNetEntity(source);
|
|
user?.AddEntity(netSource);
|
|
|
|
var msg = new ChatMessage(channel, message, wrappedMessage, netSource, user?.Key, hideChat, colorOverride, audioPath, audioVolume);
|
|
_netManager.ServerSendToAll(new MsgChatMessage() { Message = msg });
|
|
|
|
if (!recordReplay)
|
|
return;
|
|
|
|
if ((channel & ChatChannel.AdminRelated) == 0 ||
|
|
_configurationManager.GetCVar(CCVars.ReplayRecordAdminChat))
|
|
{
|
|
_replay.RecordServerMessage(msg);
|
|
}
|
|
}
|
|
|
|
public bool MessageCharacterLimit(ICommonSession? player, string message)
|
|
{
|
|
var isOverLength = false;
|
|
|
|
// Non-players don't need to be checked.
|
|
if (player == null)
|
|
return false;
|
|
|
|
// Check if message exceeds the character limit if the sender is a player
|
|
if (message.Length > MaxMessageLength)
|
|
{
|
|
var feedback = Loc.GetString("chat-manager-max-message-length-exceeded-message", ("limit", MaxMessageLength));
|
|
|
|
DispatchServerMessage(player, feedback);
|
|
|
|
isOverLength = true;
|
|
}
|
|
|
|
return isOverLength;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
public enum OOCChatType : byte
|
|
{
|
|
OOC,
|
|
Admin
|
|
}
|
|
}
|