Add LOOC and change OOC color (#5841)
This commit is contained in:
56
Content.Server/Chat/Commands/LOOCCommand.cs
Normal file
56
Content.Server/Chat/Commands/LOOCCommand.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.Chat.Managers;
|
||||
using Content.Server.Players;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Chat.Commands
|
||||
{
|
||||
[AnyCommand]
|
||||
internal class LOOCCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "looc";
|
||||
public string Description => "Send Local Out Of Character chat messages.";
|
||||
public string Help => "looc <text>";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var player = shell.Player as IPlayerSession;
|
||||
if (player == null)
|
||||
{
|
||||
shell.WriteLine("This command cannot be run from the server.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.Status != SessionStatus.InGame || player.AttachedEntity == null)
|
||||
return;
|
||||
|
||||
if (args.Length < 1)
|
||||
return;
|
||||
|
||||
var message = string.Join(" ", args).Trim();
|
||||
if (string.IsNullOrEmpty(message))
|
||||
return;
|
||||
|
||||
var chat = IoCManager.Resolve<IChatManager>();
|
||||
var mindComponent = player.ContentData()?.Mind;
|
||||
|
||||
if (mindComponent == null)
|
||||
{
|
||||
shell.WriteError("You don't have a mind!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (mindComponent.OwnedEntity == null)
|
||||
{
|
||||
shell.WriteError("You don't have an entity!");
|
||||
return;
|
||||
}
|
||||
|
||||
chat.EntityLOOC(mindComponent.OwnedEntity.Value, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
44
Content.Server/Chat/Commands/SetLOOCCommand.cs
Normal file
44
Content.Server/Chat/Commands/SetLOOCCommand.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.CCVar;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Server.Chat.Commands;
|
||||
|
||||
[AdminCommand(AdminFlags.Server)]
|
||||
public class SetLOOCCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "setlooc";
|
||||
public string Description => Loc.GetString("set-looc-command-description");
|
||||
public string Help => Loc.GetString("set-looc-command-help");
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var cfg = IoCManager.Resolve<IConfigurationManager>();
|
||||
|
||||
if (args.Length > 1)
|
||||
{
|
||||
shell.WriteError(Loc.GetString("set-looc-command-too-many-arguments-error"));
|
||||
return;
|
||||
}
|
||||
|
||||
var looc = cfg.GetCVar(CCVars.LoocEnabled);
|
||||
|
||||
if (args.Length == 0)
|
||||
{
|
||||
looc = !looc;
|
||||
}
|
||||
|
||||
if (args.Length == 1 && !bool.TryParse(args[0], out looc))
|
||||
{
|
||||
shell.WriteError(Loc.GetString("set-looc-command-invalid-argument-error"));
|
||||
return;
|
||||
}
|
||||
|
||||
cfg.SetCVar(CCVars.LoocEnabled, looc);
|
||||
|
||||
shell.WriteLine(Loc.GetString(looc ? "set-looc-command-looc-enabled" : "set-looc-command-looc-disabled"));
|
||||
}
|
||||
}
|
||||
@@ -59,12 +59,15 @@ namespace Content.Server.Chat.Managers
|
||||
private readonly List<TransformChat> _chatTransformHandlers = new();
|
||||
private bool _oocEnabled = true;
|
||||
private bool _adminOocEnabled = true;
|
||||
private bool _loocEnabled = true;
|
||||
private bool _adminLoocEnabled = true;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
_netManager.RegisterNetMessage<MsgChatMessage>();
|
||||
|
||||
_configurationManager.OnValueChanged(CCVars.OocEnabled, OnOocEnabledChanged, true);
|
||||
_configurationManager.OnValueChanged(CCVars.LoocEnabled, OnLoocEnabledChanged, true);
|
||||
_configurationManager.OnValueChanged(CCVars.AdminOocEnabled, OnAdminOocEnabledChanged, true);
|
||||
}
|
||||
|
||||
@@ -74,6 +77,12 @@ namespace Content.Server.Chat.Managers
|
||||
DispatchServerAnnouncement(Loc.GetString(val ? "chat-manager-ooc-chat-enabled-message" : "chat-manager-ooc-chat-disabled-message"));
|
||||
}
|
||||
|
||||
private void OnLoocEnabledChanged(bool val)
|
||||
{
|
||||
_loocEnabled = val;
|
||||
DispatchServerAnnouncement(Loc.GetString(val ? "chat-manager-looc-chat-enabled-message" : "chat-manager-looc-chat-disabled-message"));
|
||||
}
|
||||
|
||||
private void OnAdminOocEnabledChanged(bool val)
|
||||
{
|
||||
_adminOocEnabled = val;
|
||||
@@ -238,6 +247,47 @@ namespace Content.Server.Chat.Managers
|
||||
_netManager.ServerSendToMany(msg, clients);
|
||||
}
|
||||
|
||||
public void EntityLOOC(EntityUid source, string message)
|
||||
{
|
||||
// Check if entity is a player
|
||||
if (!_entManager.TryGetComponent(source, out ActorComponent? actor))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_adminManager.IsAdmin(actor.PlayerSession))
|
||||
{
|
||||
if (!_adminLoocEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!_loocEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if message exceeds the character limit
|
||||
if (message.Length > MaxMessageLength)
|
||||
{
|
||||
DispatchServerMessage(actor.PlayerSession, Loc.GetString("chat-manager-max-message-length-exceeded-message", ("limit", MaxMessageLength)));
|
||||
return;
|
||||
}
|
||||
|
||||
message = FormattedMessage.EscapeText(message);
|
||||
|
||||
var clients = Filter.Empty()
|
||||
.AddInRange(_entManager.GetComponent<TransformComponent>(source).MapPosition, VoiceRange)
|
||||
.Recipients
|
||||
.Select(p => p.ConnectedClient)
|
||||
.ToList();
|
||||
|
||||
var msg = _netManager.CreateNetMessage<MsgChatMessage>();
|
||||
msg.Channel = ChatChannel.LOOC;
|
||||
msg.Message = message;
|
||||
msg.MessageWrap = Loc.GetString("chat-manager-entity-looc-wrap-message", ("entityName", Name: _entManager.GetComponent<MetaDataComponent>(source).EntityName));
|
||||
_netManager.ServerSendToMany(msg, clients);
|
||||
}
|
||||
public void SendOOC(IPlayerSession player, string message)
|
||||
{
|
||||
if (_adminManager.IsAdmin(player))
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace Content.Server.Chat.Managers
|
||||
/// <param name="hideChat">If true, message will not be logged to chat boxes but will still produce a speech bubble.</param>
|
||||
void EntitySay(EntityUid source, string message, bool hideChat=false);
|
||||
void EntityMe(EntityUid source, string action);
|
||||
void EntityLOOC(EntityUid source, string message);
|
||||
|
||||
void SendOOC(IPlayerSession player, string message);
|
||||
void SendAdminChat(IPlayerSession player, string message);
|
||||
|
||||
Reference in New Issue
Block a user