Files

508 lines
21 KiB
C#
Raw Permalink Normal View History

using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
2022-01-19 13:35:31 +11:00
using Content.Server.Administration.Logs;
2021-06-09 22:19:39 +02:00
using Content.Server.Administration.Managers;
2023-03-23 10:10:49 -05:00
using Content.Server.Administration.Systems;
2021-06-09 22:19:39 +02:00
using Content.Server.MoMMI;
using Content.Server.Preferences.Managers;
using Content.Server._White.PandaSocket.Main;
using Content.Server._White.Reputation;
using Content.Server._White.Sponsors;
using Content.Shared.Administration;
using Content.Shared.CCVar;
using Content.Shared.Chat;
2022-01-19 13:35:31 +11:00
using Content.Shared.Database;
using Content.Shared.Mind;
using Content.Shared._White;
using Robust.Server.Player;
using Robust.Shared.Asynchronous;
2021-02-16 20:14:32 +01:00
using Robust.Shared.Configuration;
using Robust.Shared.Network;
using Robust.Shared.Player;
2022-11-23 00:52:19 +13:00
using Robust.Shared.Replays;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
2021-06-09 22:19:39 +02:00
namespace Content.Server.Chat.Managers
{
/// <summary>
/// Dispatches chat messages to clients.
/// </summary>
internal sealed partial 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" }
};
2022-11-23 00:52:19 +13:00
[Dependency] private readonly IReplayRecordingManager _replay = default!;
2021-02-16 20:14:32 +01:00
[Dependency] private readonly IServerNetManager _netManager = default!;
[Dependency] private readonly IMoMMILink _mommiLink = default!;
[Dependency] private readonly IAdminManager _adminManager = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
2021-02-16 20:14:32 +01:00
[Dependency] private readonly IServerPreferencesManager _preferencesManager = default!;
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
[Dependency] private readonly INetConfigurationManager _netConfigManager = default!;
2023-03-23 10:10:49 -05:00
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
2021-02-16 20:14:32 +01:00
/// WD-EDIT
[Dependency] private readonly SponsorsManager _sponsorsManager = default!;
[Feat] Panda socket (#616) * base server side * token check & base command response * panda base command response addition & some commands * web event, rest of commands & events * fix empty api * [DRAFT] Panda HTTP server (#570) * [Sponsor] Nairsark ghost (#492) * [Sponsor] Trora ghost (#493) * [Sponsor] Trora ghost * ckey * Vtergot fluff (#494) * Твики (#491) * Economy additions * Tweak implant cooldowns * Cult stuff * Random appearance aspect nuke ops fix * Auto shuttle enable on round end * Holy water threshold * Automatic changelog update * [Sponsor] Geraldiy fluff (#496) * [Fix] Reputation respawn hotfix (#497) * Automatic changelog update * Новые аспекты (#495) * Add ReflectAspect * Add SlipperyAspect * Add TraitorRichAspect * Add WhisperAspect * Add DarknessAspect & StolenFloorAspect * Add WindowLeakAspect * Add CatEarsAspect * Add NothingAspect * Fix fast and furious clone * Add SkeletonAspect * Add cvar ceanup * Automatic changelog update * [Sponsor] Fluff knife cappy (#498) * [Sponsor] Fluff KnifeCappy * loadout * Всякое (#501) * eftpos form jurist * ebal parameda * Automatic changelog update * [Sponsor] Zilendorie ghost upgrade (#502) * Апдейт карт, станция прибытия (#503) * Automatic changelog update * Fix aspects (#500) * Automatic changelog update * Rules popup fix (#504) * Defib fix (#499) * Automatic changelog update * Фикс флаффа (#507) * Фикс прибытия (#509) * Automatic changelog update * Фиксы (#508) * Fix cult blindfold * Add stamina resistances * Energy bolt is energy * Laser shield is anti-laser * Cult blindfold welding protection * Eject id cards on deconstruct * Wires panel power fix * Add markings for species * Ebow gaming * feat: настенные консольки (#505) * Automatic changelog update * [Sponsor] Fluff Medicgaming (#510) * Привязка банковского аккаунта (#506) * Sustenance vend price fix * Account link * Automatic changelog update * antag ban fix (#511) * antag ban fix * rename some shit * Bugfixes (#512) * Bullets go through open crates * Bullets don't hit pulled dead bodies * No glued cuffs * Missed reflect aspect mark * vehicles cannot be shot (#18910) Co-authored-by: deltanedas <@deltanedas:kde.org> * Cleanup --------- Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> * Automatic changelog update * атмос гейминг indeed (#513) * fix hypernob + plasma and trit fire * add 11 new gas types * actually fix hypernob --------- Co-authored-by: halicopter <kirillhalic@gmail.com> * Automatic changelog update * [Sponsor] thechaotic fluff * Revert "[Sponsor] thechaotic fluff" This reverts commit d19c807751258f9cfb205db01b0e4617b638fe98. * [Sponsor] Fluff updates (#518) * warete update * renosan & warete size * [Sponsor] thechaotic fluff (#519) (cherry picked from commit d19c807751258f9cfb205db01b0e4617b638fe98) * fix tts sanitize (#517) * Automatic changelog update * [Fluff] ghost regari * Buffs (#515) * FIRE axe * Bow pro * Bang * Meleeeee * Disarm two-handed hard * Automatic changelog update * Игнор вайтлист требования ролей если стоит флаг TOOLS (#514) * forAmins be like * >вайтлист в девелопменте * а описание кто напишет а * Размеры попапов в чате (#525) * попытка деконить магнит пока он активен гибает интернет приколистов (#524) * Интернет прикол * попап * Prevent using cultist items & halberd (#523) * Fix skeleton aspect (#522) * Fix cult door (#521) * Fix cult door * Prevent emagging * Walls and griders * Fix * Drone fix (#520) * Drone fix * RCD * Automatic changelog update * Смешное в конце раунда с аспектом (#516) * Cats * Fix * Automatic changelog update * Fix cult win conditions (#527) * Runes stuff (#526) * Blood boil 2.0 * Attach to grid * No * Automatic changelog update * [Sponsor] thefrendlypsychopath ghost (#529) * knifeCappy (#528) Co-authored-by: Mona Hmiza <you@example.com> * [Feat] TTS 8 new voices * borg fix * Automatic changelog update * мапперы тестили * fix void prototype * [Fix] Cult chat fix (#536) * ERT tweak (#530) * tweak values * tweak spawn logic * Invisible rune (#531) * Automatic changelog update * [Sponsor] Oleg_Tinkoff fluff (#534) * [Sponsor] Oleg_Tinkoff fluff * name fix * Small fixes (#537) * No sleeping emotes * Beakers & jugs in fridge * Drone fix * Fix teleport pulling * Fix loc * More fixes * Fix ghost role * Stuff * Automatic changelog update * Nerf grilles (#541) * Nerf grilles * tweak * Bola fix (#540) * Automatic changelog update * Куча говна (#539) * No Emp resistance (#538) * No EMP resistance * Cleanup * Automatic changelog update * mappews mapped some mowe~ * anothew update UwU * [Sponsor] Geraldiy fluff 2 (#542) * fix drydock * Objective changes (#543) * Automatic changelog update * UwU spawnews are now fixed, hopefully~ * UwU tired of it alweady * Automatic changelog update * Респрайт капитанского лазера (#546) * antique lasergun resprite lol * лицуха * Automatic changelog update * Апдейт арахнидов (#544) * Web underwear * Fix layers * Change melee sound * Arachnid 2: Episode 2 (#19984) * Shield * minor sprite changes and buffs * structure buff * Crafting stuff * tweaks * 88-88 * Better web pocket sprites. * yeah it's fine now. * Fix * Sprite tweaks * This I guess * Eye sprite --------- Co-authored-by: PixelTK <85175107+PixelTheKermit@users.noreply.github.com> * [Sponsor] Zilendorie fluff (#545) * Automatic changelog update * Fire buff (#549) * EntityStorage deletion fix? (#548) * strip fix (#21552) (#547) Co-authored-by: PixelTK <85175107+PixelTheKermit@users.noreply.github.com> * Automatic changelog update * [Fluff] SSAO Ghost * [Fluff] svinka ghost tweak * [Fluff] Svinka Coat * Meaty-Ore Idea (#550) * qwe * yeah * Vtergot fluff fix (#552) * наяриваем на лишние пиксели * Чтобы мапперы не втыкали * fix atmos (#551) * fix atmos * fixie * Automatic changelog update * Meow hotfix (#553) * Many stuff (#555) * Drone bucket * Weird insuls * Not too strong * No cult door bolts * Emergency shuttle after round end fix * Fix spiders * Automatic changelog update * [FEAT] Всякие прикольные разности и вкусности (#554) * feat: трикодер * feat: принтер документов * fix: текст фелинидов * feat: возможность менять голос эмоутов * feat: мяукаем при аспекте мяуканья * feat: ПНВ * fix: забирай свои метадаты * fix: oopsies * fix: линтер снова * fix: пожалуйста линтер отстань * Automatic changelog update * Гарпии (#533) * harpy initial * fix and some locale * ru locale * actions refactor shit * пофиксив гавпий~~~ пойду тестить~~ * hawpies are ready UwU * cweanup OwO * hawpies fixed a bit, still cant seawch them nya~ * hawpies can be stwipped now, fixie-dixie awwived~ * emotes fixie-dixied nya~ * говно * говно говна линтер соси * Automatic changelog update * Revert "Гарпии (#533)" (#557) This reverts commit e3f2166bf7cbd775278a396a3f8d8215a2d5c506. * Doom fluff (#556) * DOOMMAX fluff * Detective meow * Сеньёр помидор офицер * RSI validator su4ka * [Fluff] MR_Regari ghost tweak * [Fluff] svinka ghost tweak * [Fluff] Antohag gasmask fluff * ГАРПИИ (#559) * harpy initial * fix and some locale * ru locale * actions refactor shit * пофиксив гавпий~~~ пойду тестить~~ * hawpies are ready UwU * cweanup OwO * hawpies fixed a bit, still cant seawch them nya~ * hawpies can be stwipped now, fixie-dixie awwived~ * emotes fixie-dixied nya~ * говно * говно говна линтер соси * Automatic changelog update * [Tweak] Бумажная работа и фикс крафта пнв. (#560) * fix: персонал станции вспомнил как делать пнв * tweak: блюспейс технологии убраны у принтера документов * feat: заказ бумаги в карго * feat: бумажная дверь * Automatic changelog update * doommaxx-fluff nothing interesting * fluff skufa (#562) * [Sponsor] Fluff Forg (#567) * [Sponsor] Fluff Forg * fix size * sound * [Feat] TTS 15 new voices (#568) * Automatic changelog update * base server side * token check & base command response * panda base command response addition & some commands * web event, rest of commands & events * fix empty api --------- Co-authored-by: Cinkafox <70429757+Cinkafox@users.noreply.github.com> Co-authored-by: Aviu00 <93730715+Aviu00@users.noreply.github.com> Co-authored-by: RavmorganButOnCocaine <valtos@nextmail.ru> Co-authored-by: Kotovskiy <77529717+wCATw@users.noreply.github.com> Co-authored-by: ThereDrD0 <88589686+ThereDrD0@users.noreply.github.com> Co-authored-by: Remuchi <72476615+Remuchi@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: KurokoTurbo <92106367+melanoTurbo@users.noreply.github.com> Co-authored-by: halicopter <kirillhalic@gmail.com> Co-authored-by: rhailrake <49613070+rhailrake@users.noreply.github.com> Co-authored-by: Subversionary <109166122+Subversionary@users.noreply.github.com> Co-authored-by: RavMorgan <48182970+RavMorgan@users.noreply.github.com> Co-authored-by: Mona Hmiza <you@example.com> Co-authored-by: Valtos <valtos@spaces.ru> Co-authored-by: REBOLUTION228-a11 <128076300+REBOLUTION228-a11@users.noreply.github.com> Co-authored-by: PixelTK <85175107+PixelTheKermit@users.noreply.github.com> * newtonsoft version change * remove semaphore * remove double dooc * fix admin stealth * cleanup * remove utka sockets --------- Co-authored-by: Cinkafox <70429757+Cinkafox@users.noreply.github.com> Co-authored-by: Aviu00 <93730715+Aviu00@users.noreply.github.com> Co-authored-by: RavmorganButOnCocaine <valtos@nextmail.ru> Co-authored-by: Kotovskiy <77529717+wCATw@users.noreply.github.com> Co-authored-by: ThereDrD0 <88589686+ThereDrD0@users.noreply.github.com> Co-authored-by: Remuchi <72476615+Remuchi@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: KurokoTurbo <92106367+melanoTurbo@users.noreply.github.com> Co-authored-by: halicopter <kirillhalic@gmail.com> Co-authored-by: rhailrake <49613070+rhailrake@users.noreply.github.com> Co-authored-by: Subversionary <109166122+Subversionary@users.noreply.github.com> Co-authored-by: RavMorgan <48182970+RavMorgan@users.noreply.github.com> Co-authored-by: Mona Hmiza <you@example.com> Co-authored-by: Valtos <valtos@spaces.ru> Co-authored-by: REBOLUTION228-a11 <128076300+REBOLUTION228-a11@users.noreply.github.com> Co-authored-by: PixelTK <85175107+PixelTheKermit@users.noreply.github.com>
2024-01-09 15:54:16 +03:00
[Dependency] private readonly PandaWebManager _pandaWeb = default!;
2023-08-17 23:40:16 +03:00
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly ReputationManager _repManager = default!;
[Dependency] private readonly ITaskManager _taskManager = default!;
/// WD-EDIT
/// <summary>
/// The maximum length a player-sent message can be sent
/// </summary>
public int MaxMessageLength => _configurationManager.GetCVar(CCVars.ChatMaxMessageLength);
2021-02-16 20:14:32 +01:00
private bool _oocEnabled = true;
private bool _adminOocEnabled = true;
private readonly Dictionary<NetUserId, ChatUser> _players = new();
2023-08-17 23:40:16 +03:00
private readonly Dictionary<NetUserId, (string, TimeSpan)> _lastMessages = new();
private bool _antispam;
private int _antispamMinLength;
private double _antispamIntervalSeconds;
public void Initialize()
{
_netManager.RegisterNetMessage<MsgChatMessage>();
_netManager.RegisterNetMessage<MsgDeleteChatMessagesBy>();
2021-02-16 20:14:32 +01:00
_configurationManager.OnValueChanged(CCVars.OocEnabled, OnOocEnabledChanged, true);
_configurationManager.OnValueChanged(CCVars.AdminOocEnabled, OnAdminOocEnabledChanged, true);
_playerManager.PlayerStatusChanged += PlayerStatusChanged;
2023-08-17 23:40:16 +03:00
// WD START
_configurationManager.OnValueChanged(WhiteCVars.ChatAntispam, val => _antispam = val, true);
_configurationManager.OnValueChanged(WhiteCVars.AntispamMinLength, val => _antispamMinLength = val, true);
_configurationManager.OnValueChanged(WhiteCVars.AntispamIntervalSeconds,
val => _antispamIntervalSeconds = val, true);
// WD END
2021-02-16 20:14:32 +01:00
}
private void OnOocEnabledChanged(bool val)
{
if (_oocEnabled == val)
return;
2022-01-19 13:35:31 +11:00
2021-02-16 20:14:32 +01:00
_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)
{
if (_adminOocEnabled == val)
return;
2022-01-19 13:35:31 +11:00
2021-02-16 20:14:32 +01:00
_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;
}
2022-03-30 22:21:58 -07:00
#region Server Announcements
public void DispatchServerAnnouncement(string message, Color? colorOverride = null)
{
var wrappedMessage = Loc.GetString("chat-manager-server-wrap-message", ("message", FormattedMessage.EscapeText(message)));
2022-11-23 00:52:19 +13:00
ChatMessageToAll(ChatChannel.Server, message, wrappedMessage, EntityUid.Invalid, hideChat: false, recordReplay: true, colorOverride: colorOverride);
2021-02-12 10:45:22 +01:00
Logger.InfoS("SERVER", message);
2022-01-19 13:35:31 +11:00
_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)
{
var clients = _adminManager.ActiveAdmins.Select(p => p.Channel);
2021-12-05 18:09:01 +01:00
var wrappedMessage = Loc.GetString("chat-manager-send-admin-announcement-wrap-message",
("adminChannelName", Loc.GetString("chat-manager-admin-channel-name")), ("message", FormattedMessage.EscapeText(message)));
2022-11-23 00:52:19 +13:00
ChatMessageToMany(ChatChannel.Admin, message, wrappedMessage, default, false, true, clients);
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Admin announcement: {message}");
}
2023-03-23 10:10:49 -05:00
public void SendAdminAlert(string message)
{
var clients = _adminManager.ActiveAdmins.Select(p => p.Channel);
2023-03-23 10:10:49 -05:00
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)
2023-03-23 10:10:49 -05:00
{
var mindSystem = _entityManager.System<SharedMindSystem>();
if (!mindSystem.TryGetMind(player, out _, out var mind))
2023-03-23 10:10:49 -05:00
{
SendAdminAlert(message);
return;
}
var adminSystem = _entityManager.System<AdminSystem>();
var antag = mind.UserId != null && (adminSystem.GetCachedPlayerInfo(mind.UserId.Value)?.Antag ?? false);
2023-03-23 10:10:49 -05:00
SendAdminAlert($"{mind.Session?.Name}{(antag ? " (ANTAG)" : "")} {message}");
2023-03-23 10:10:49 -05:00
}
2022-03-30 22:21:58 -07:00
public void SendHookOOC(string sender, string message)
{
if (_configurationManager.GetCVar(CCVars.DisableHookedOOC))
{
return;
}
var wrappedMessage = Loc.GetString("chat-manager-send-hook-ooc-wrap-message", ("senderName", sender), ("message", FormattedMessage.EscapeText(message)));
2022-11-23 00:52:19 +13:00
ChatMessageToAll(ChatChannel.OOC, message, wrappedMessage, source: EntityUid.Invalid, hideChat: false, recordReplay: true);
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Hook OOC from {sender}: {message}");
}
//WD-EDIT
public void SendHookAdminChat(string sender, string message)
{
var admins = _adminManager.ActiveAdmins;
var wrappedMessage = Loc.GetString("chat-manager-send-admin-chat-wrap-message",
("adminChannelName", Loc.GetString("chat-manager-admin-discord-channel-name")),
("playerName", sender), ("message", FormattedMessage.EscapeText(message)));
ChatMessageToMany(ChatChannel.Admin, message, wrappedMessage, EntityUid.Invalid, false, false, admins.Select(p => p.ConnectedClient));
}
2023-07-31 09:33:04 +03:00
public bool TrySendNewMessage(ICommonSession session, string newMessage, bool checkLength = false)
2023-07-31 09:33:04 +03:00
{
if (!_antispam || checkLength && newMessage.Length < _antispamMinLength)
2023-08-17 23:40:16 +03:00
{
_lastMessages.Remove(session.Data.UserId);
2023-07-31 09:33:04 +03:00
return true;
2023-08-17 23:40:16 +03:00
}
2023-07-31 09:33:04 +03:00
2023-08-17 23:40:16 +03:00
var curTime = _timing.CurTime;
2023-07-31 09:33:04 +03:00
if (_lastMessages.TryGetValue(session.Data.UserId, out var value))
{
2023-08-17 23:40:16 +03:00
var interval = (curTime - value.Item2).TotalSeconds;
var difference = _antispamIntervalSeconds - interval;
if (value.Item1 == newMessage && difference > 0d)
2023-07-31 09:33:04 +03:00
{
2023-08-17 23:40:16 +03:00
DispatchServerMessage(session,
Loc.GetString("chat-manager-antispam-warn-message", ("remainingTime", (int) difference)));
2023-07-31 09:33:04 +03:00
return false;
}
}
2023-08-17 23:40:16 +03:00
_lastMessages[session.Data.UserId] = (newMessage, curTime);
2023-07-31 09:33:04 +03:00
return true;
}
//WD-EDIT
2022-03-30 22:21:58 -07:00
#endregion
2022-03-30 22:21:58 -07:00
#region Public OOC Chat API
2022-03-30 22:21:58 -07:00
/// <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;
2022-01-11 16:29:55 +03:00
// Check if message exceeds the character limit
if (message.Length > MaxMessageLength)
{
DispatchServerMessage(player, Loc.GetString("chat-manager-max-message-length-exceeded-message", ("limit", MaxMessageLength)));
2022-01-11 16:29:55 +03:00
return;
}
2022-03-30 22:21:58 -07:00
switch (type)
{
case OOCChatType.OOC:
SendOOC(player, message);
break;
case OOCChatType.Admin:
SendAdminChat(player, message);
break;
}
}
2022-03-30 22:21:58 -07:00
#endregion
2022-01-19 13:35:31 +11:00
2022-03-30 22:21:58 -07:00
#region Private API
private void SendOOC(ICommonSession player, string message)
{
2021-02-16 20:14:32 +01:00
if (_adminManager.IsAdmin(player))
{
if (!_adminOocEnabled)
{
return;
}
}
else if (!_oocEnabled)
{
return;
}
2023-07-31 09:33:04 +03:00
if (!TrySendNewMessage(player, message)) // WD
return;
// WD start
//_repManager.GetCachedPlayerReputation(player.UserId, out var value);
var task = Task.Run(async () => await _repManager.GetPlayerReputation(player.UserId));
_taskManager.BlockWaitOnTask(task);
var value = task.GetAwaiter().GetResult();
var reputation = "";
if (value != null)
{
var color = value >= 0 ? "green" : "red";
reputation = $"[color={color}]({value})[/color]";
}
// WD end
2022-03-30 22:21:58 -07:00
Color? colorOverride = null;
var wrappedMessage = Loc.GetString("chat-manager-send-ooc-wrap-message", ("playerName",player.Name), ("message", FormattedMessage.EscapeText(message)), ("rep", reputation));
if (_adminManager.HasAdminFlag(player, AdminFlags.Admin))
{
2021-02-16 20:14:32 +01:00
var prefs = _preferencesManager.GetPreferences(player.UserId);
2022-03-30 22:21:58 -07:00
colorOverride = prefs.AdminOOCColor;
}
if ( _netConfigManager.GetClientCVar(player.Channel, CCVars.ShowOocPatronColor) && player.Channel.UserData.PatronTier is { } patron && PatronOocColors.TryGetValue(patron, out var patronColor))
2021-02-28 18:51:42 +01:00
{
wrappedMessage = Loc.GetString("chat-manager-send-ooc-patron-wrap-message", ("patronColor", patronColor),("playerName", player.Name), ("message", FormattedMessage.EscapeText(message)), ("rep", reputation));
2021-02-28 18:51:42 +01:00
}
//WD-EDIT
if (_sponsorsManager.TryGetInfo(player.UserId, out var sponsorData) && sponsorData.OOCColor != null)
{
wrappedMessage = Loc.GetString("chat-manager-send-ooc-patron-wrap-message", ("patronColor", sponsorData.OOCColor),("playerName", player.Name), ("message", FormattedMessage.EscapeText(message)), ("rep", reputation));
}
//WD-EDIT
//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}");
//WD-EDIT
var toUtkaMessage = new UtkaChatMessageEvent()
{
Command = "ooc",
Ckey = player.Name,
Message = message,
};
_pandaWeb.SendBotPostMessage(toUtkaMessage);
//WD-EDIT
2019-04-17 23:31:43 +02:00
}
private void SendAdminChat(ICommonSession player, string message)
{
2023-04-28 04:44:00 +06:00
if (!_adminManager.HasAdminFlag(player, AdminFlags.Admin))
{
_adminLogger.Add(LogType.Chat, LogImpact.Extreme, $"{player:Player} attempted to send admin message but was not admin");
return;
}
2023-04-28 04:44:00 +06:00
var clients = _adminManager.ActiveAdmins
.Where(p => _adminManager.HasAdminFlag(p, AdminFlags.Admin))
.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);
}
2022-01-19 13:35:31 +11:00
_adminLogger.Add(LogType.Chat, $"Admin chat from {player:Player}: {message}");
//WD-EDIT
var asayEventMessage = new UtkaChatMessageEvent()
{
Command = "asay",
Ckey = player.Name,
Message = message
};
_pandaWeb.SendBotPostMessage(asayEventMessage);
//WD-EDIT
}
2022-03-30 22:21:58 -07:00
#endregion
2020-11-01 23:56:35 +01:00
2022-03-30 22:21:58 -07:00
#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)
2022-03-30 22:21:58 -07:00
{
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);
2022-11-23 00:52:19 +13:00
2023-06-05 16:33:49 +12:00
if (!recordReplay)
return;
if ((channel & ChatChannel.AdminRelated) == 0 ||
_configurationManager.GetCVar(CCVars.ReplayRecordAdminChat))
{
_replay.RecordServerMessage(msg);
2023-06-05 16:33:49 +12:00
}
}
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);
}
2022-11-23 00:52:19 +13:00
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);
2022-11-23 00:52:19 +13:00
2023-06-05 16:33:49 +12:00
if (!recordReplay)
return;
if ((channel & ChatChannel.AdminRelated) == 0 ||
_configurationManager.GetCVar(CCVars.ReplayRecordAdminChat))
{
_replay.RecordServerMessage(msg);
2023-06-05 16:33:49 +12:00
}
}
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)
{
2022-11-23 00:52:19 +13:00
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 });
2022-11-23 00:52:19 +13:00
2023-06-05 16:33:49 +12:00
if (!recordReplay)
return;
if ((channel & ChatChannel.AdminRelated) == 0 ||
_configurationManager.GetCVar(CCVars.ReplayRecordAdminChat))
{
_replay.RecordServerMessage(msg);
2023-06-05 16:33:49 +12:00
}
}
public bool MessageCharacterLimit(ICommonSession? player, string message)
{
var isOverLength = false;
2022-03-30 22:21:58 -07:00
// 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
2022-03-30 22:21:58 -07:00
if (message.Length > MaxMessageLength)
{
var feedback = Loc.GetString("chat-manager-max-message-length-exceeded-message", ("limit", MaxMessageLength));
2022-03-30 22:21:58 -07:00
DispatchServerMessage(player, feedback);
isOverLength = true;
}
return isOverLength;
}
2022-03-30 22:21:58 -07:00
#endregion
}
2022-03-30 22:21:58 -07:00
public enum OOCChatType : byte
{
OOC,
Admin
}
}