From 57b049d17336e3854611cc657852d2b17532c460 Mon Sep 17 00:00:00 2001 From: Leo Date: Sun, 3 Jan 2021 12:13:31 -0300 Subject: [PATCH] Adds DSay command (#2901) * DSay command * Moves getting the clients from DeadChat and AdminDeadChat to a function --- .../Administration/Commands/DSay.cs | 40 +++++++++++++++++++ Content.Server/Chat/ChatManager.cs | 31 ++++++++++++-- .../Interfaces/Chat/IChatManager.cs | 3 +- 3 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 Content.Server/Administration/Commands/DSay.cs diff --git a/Content.Server/Administration/Commands/DSay.cs b/Content.Server/Administration/Commands/DSay.cs new file mode 100644 index 0000000000..40bf93b5b5 --- /dev/null +++ b/Content.Server/Administration/Commands/DSay.cs @@ -0,0 +1,40 @@ +using Content.Server.Interfaces.Chat; +using Content.Shared.Administration; +using Robust.Server.Interfaces.Console; +using Robust.Server.Interfaces.Player; +using Robust.Shared.IoC; +using Robust.Shared.Localization; + +namespace Content.Server.Administration.Commands +{ + [AdminCommand(AdminFlags.Admin)] + class DSay : IClientCommand + { + public string Command => "dsay"; + + public string Description => Loc.GetString("Sends a message to deadchat as an admin"); + + public string Help => Loc.GetString($"Usage: {Command} "); + + public void Execute(IConsoleShell shell, IPlayerSession player, string[] args) + { + if (player == null) + { + shell.SendText((IPlayerSession) null, "Only players can use this command"); + return; + } + + if (args.Length < 1) + return; + + var message = string.Join(" ", args).Trim(); + if (string.IsNullOrEmpty(message)) + return; + + var chat = IoCManager.Resolve(); + + chat.SendAdminDeadChat(player, message); + + } + } +} diff --git a/Content.Server/Chat/ChatManager.cs b/Content.Server/Chat/ChatManager.cs index 0add7b9891..72c2842b1e 100644 --- a/Content.Server/Chat/ChatManager.cs +++ b/Content.Server/Chat/ChatManager.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using Content.Server.Administration; using Content.Server.GameObjects.Components.GUI; @@ -212,9 +212,7 @@ namespace Content.Server.Chat return; } - var clients = _playerManager - .GetPlayersBy(x => x.AttachedEntity != null && x.AttachedEntity.HasComponent()) - .Select(p => p.ConnectedClient); + var clients = GetDeadChatClients(); var msg = _netManager.CreateNetMessage(); msg.Channel = ChatChannel.Dead; @@ -224,6 +222,31 @@ namespace Content.Server.Chat _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(MaxLengthExceededMessage, MaxMessageLength)); + return; + } + + var clients = GetDeadChatClients(); + + var msg = _netManager.CreateNetMessage(); + msg.Channel = ChatChannel.Dead; + msg.Message = message; + msg.MessageWrap = $"{Loc.GetString("ADMIN")}:(${player.ConnectedClient.UserName}): {{0}}"; + _netManager.ServerSendToMany(msg, clients.ToList()); + } + + private IEnumerable GetDeadChatClients() + { + return _playerManager + .GetPlayersBy(x => x.AttachedEntity != null && x.AttachedEntity.HasComponent()) + .Select(p => p.ConnectedClient); + } + public void SendAdminChat(IPlayerSession player, string message) { // Check if message exceeds the character limit diff --git a/Content.Server/Interfaces/Chat/IChatManager.cs b/Content.Server/Interfaces/Chat/IChatManager.cs index ce5304d5c6..0edfff50cd 100644 --- a/Content.Server/Interfaces/Chat/IChatManager.cs +++ b/Content.Server/Interfaces/Chat/IChatManager.cs @@ -1,4 +1,4 @@ -using Robust.Server.Interfaces.Player; +using Robust.Server.Interfaces.Player; using Robust.Shared.Interfaces.GameObjects; namespace Content.Server.Interfaces.Chat @@ -27,6 +27,7 @@ namespace Content.Server.Interfaces.Chat void SendOOC(IPlayerSession player, string message); void SendAdminChat(IPlayerSession player, string message); void SendDeadChat(IPlayerSession player, string message); + void SendAdminDeadChat(IPlayerSession player, string message); void SendHookOOC(string sender, string message);