Add cvar to disable ooc chat (#3258)
This commit is contained in:
@@ -21,6 +21,11 @@ namespace Content.Client.Administration
|
||||
|
||||
public event Action? AdminStatusUpdated;
|
||||
|
||||
public bool IsActive()
|
||||
{
|
||||
return _adminData?.Active ?? false;
|
||||
}
|
||||
|
||||
public bool HasFlag(AdminFlags flag)
|
||||
{
|
||||
return _adminData?.HasFlag(flag) ?? false;
|
||||
|
||||
@@ -15,6 +15,12 @@ namespace Content.Client.Administration
|
||||
/// </summary>
|
||||
event Action AdminStatusUpdated;
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the local player is an admin.
|
||||
/// </summary>
|
||||
/// <returns>true if the local player is an admin, false otherwise even if they are deadminned.</returns>
|
||||
bool IsActive();
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the local player has an admin flag.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
using Content.Client.Administration;
|
||||
using Content.Client.Chat;
|
||||
using Content.Client.Interfaces.Chat;
|
||||
using Content.Client.UserInterface;
|
||||
using Content.Client.Voting;
|
||||
using Content.Shared;
|
||||
using Content.Shared.Input;
|
||||
using Robust.Client.Input;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
@@ -20,9 +23,14 @@ namespace Content.Client.State
|
||||
[Dependency] private readonly IInputManager _inputManager = default!;
|
||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||
[Dependency] private readonly IVoteManager _voteManager = default!;
|
||||
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
||||
[Dependency] private readonly IClientAdminManager _adminManager = default!;
|
||||
|
||||
[ViewVariables] private ChatBox _gameChat;
|
||||
|
||||
private bool _oocEnabled;
|
||||
private bool _adminOocEnabled;
|
||||
|
||||
public override void Startup()
|
||||
{
|
||||
base.Startup();
|
||||
@@ -42,13 +50,17 @@ namespace Content.Client.State
|
||||
_gameChat.Input.PlaceHolder = Loc.GetString("Say something! [ for OOC");
|
||||
|
||||
_inputManager.SetInputCommand(ContentKeyFunctions.FocusChat,
|
||||
InputCmdHandler.FromDelegate(s => FocusChat(_gameChat)));
|
||||
InputCmdHandler.FromDelegate(_ => FocusChat(_gameChat)));
|
||||
|
||||
_inputManager.SetInputCommand(ContentKeyFunctions.FocusOOC,
|
||||
InputCmdHandler.FromDelegate(s => FocusOOC(_gameChat)));
|
||||
InputCmdHandler.FromDelegate(_ => FocusOOC(_gameChat)));
|
||||
|
||||
_inputManager.SetInputCommand(ContentKeyFunctions.FocusAdminChat,
|
||||
InputCmdHandler.FromDelegate(s => FocusAdminChat(_gameChat)));
|
||||
InputCmdHandler.FromDelegate(_ => FocusAdminChat(_gameChat)));
|
||||
|
||||
_configurationManager.OnValueChanged(CCVars.OocEnabled, OnOocEnabledChanged, true);
|
||||
_configurationManager.OnValueChanged(CCVars.AdminOocEnabled, OnAdminOocEnabledChanged, true);
|
||||
_adminManager.AdminStatusUpdated += OnAdminStatusUpdated;
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
@@ -59,6 +71,37 @@ namespace Content.Client.State
|
||||
_gameHud.RootControl.Orphan();
|
||||
}
|
||||
|
||||
private void OnOocEnabledChanged(bool val)
|
||||
{
|
||||
_oocEnabled = val;
|
||||
|
||||
if (_adminManager.IsActive())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_gameChat.Input.PlaceHolder = Loc.GetString(_oocEnabled ? "Say something! [ for OOC" : "Say something!");
|
||||
}
|
||||
|
||||
private void OnAdminOocEnabledChanged(bool val)
|
||||
{
|
||||
_adminOocEnabled = val;
|
||||
|
||||
if (!_adminManager.IsActive())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_gameChat.Input.PlaceHolder = Loc.GetString(_adminOocEnabled ? "Say something! [ for OOC" : "Say something!");
|
||||
}
|
||||
|
||||
private void OnAdminStatusUpdated()
|
||||
{
|
||||
_gameChat.Input.PlaceHolder = _adminManager.IsActive()
|
||||
? Loc.GetString(_adminOocEnabled ? "Say something! [ for OOC" : "Say something!")
|
||||
: Loc.GetString(_oocEnabled ? "Say something! [ for OOC" : "Say something!");
|
||||
}
|
||||
|
||||
internal static void FocusChat(ChatBox chat)
|
||||
{
|
||||
if (chat == null || chat.UserInterfaceManager.KeyboardFocused != null)
|
||||
|
||||
@@ -53,6 +53,11 @@ namespace Content.Server.Administration
|
||||
private readonly HashSet<string> _anyCommands = new();
|
||||
private readonly Dictionary<string, AdminFlags[]> _adminCommands = new();
|
||||
|
||||
public bool IsAdmin(IPlayerSession session, bool includeDeAdmin = false)
|
||||
{
|
||||
return GetAdminData(session, includeDeAdmin) != null;
|
||||
}
|
||||
|
||||
public AdminData? GetAdminData(IPlayerSession session, bool includeDeAdmin = false)
|
||||
{
|
||||
if (_admins.TryGetValue(session, out var reg) && (reg.Data.Active || includeDeAdmin))
|
||||
|
||||
@@ -25,6 +25,16 @@ namespace Content.Server.Administration
|
||||
/// </remarks>
|
||||
IEnumerable<IPlayerSession> ActiveAdmins { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a player is an admin.
|
||||
/// </summary>
|
||||
/// <param name="session">The player to check.</param>
|
||||
/// <param name="includeDeAdmin">
|
||||
/// Whether to return admin data for admins that are current de-adminned.
|
||||
/// </param>
|
||||
/// <returns>true if the player is an admin, false otherwise.</returns>
|
||||
bool IsAdmin(IPlayerSession session, bool includeDeAdmin = false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the admin data for a player, if they are an admin.
|
||||
/// </summary>
|
||||
|
||||
@@ -8,6 +8,7 @@ using Content.Server.GameObjects.Components.Observer;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Server.Interfaces.Chat;
|
||||
using Content.Shared;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Chat;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
@@ -15,6 +16,7 @@ using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
|
||||
using Content.Shared.Interfaces;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
@@ -29,10 +31,17 @@ namespace Content.Server.Chat
|
||||
/// </summary>
|
||||
internal sealed class ChatManager : IChatManager
|
||||
{
|
||||
[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 = 1000;
|
||||
public const int MaxMessageLength = 1000;
|
||||
|
||||
private const int VoiceRange = 7; // how far voice goes in world units
|
||||
|
||||
@@ -43,12 +52,8 @@ namespace Content.Server.Chat
|
||||
|
||||
//TODO: make prio based?
|
||||
private List<TransformChat> _chatTransformHandlers;
|
||||
|
||||
[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!;
|
||||
private bool _oocEnabled = true;
|
||||
private bool _adminOocEnabled = true;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
@@ -61,6 +66,21 @@ namespace Content.Server.Chat
|
||||
_netManager.ServerSendToAll(msg);
|
||||
|
||||
_chatTransformHandlers = new List<TransformChat>();
|
||||
|
||||
_configurationManager.OnValueChanged(CCVars.OocEnabled, OnOocEnabledChanged, true);
|
||||
_configurationManager.OnValueChanged(CCVars.AdminOocEnabled, OnAdminOocEnabledChanged, true);
|
||||
}
|
||||
|
||||
private void OnOocEnabledChanged(bool val)
|
||||
{
|
||||
_oocEnabled = val;
|
||||
DispatchServerAnnouncement(val ? "OOC chat has been enabled." : "OOC chat has been disabled.");
|
||||
}
|
||||
|
||||
private void OnAdminOocEnabledChanged(bool val)
|
||||
{
|
||||
_adminOocEnabled = val;
|
||||
DispatchServerAnnouncement(val ? "Admin OOC chat has been enabled." : "Admin OOC chat has been disabled.");
|
||||
}
|
||||
|
||||
public void DispatchServerAnnouncement(string message)
|
||||
@@ -166,13 +186,15 @@ namespace Content.Server.Chat
|
||||
}
|
||||
|
||||
// Check if entity is a player
|
||||
IPlayerSession playerSession = source.GetComponent<IActorComponent>().playerSession;
|
||||
if (!source.TryGetComponent(out IActorComponent actor))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if message exceeds the character limit
|
||||
if (playerSession != null)
|
||||
if (action.Length > MaxMessageLength)
|
||||
if (actor.playerSession != null && action.Length > MaxMessageLength)
|
||||
{
|
||||
DispatchServerMessage(playerSession, Loc.GetString(MaxLengthExceededMessage, MaxMessageLength));
|
||||
DispatchServerMessage(actor.playerSession, Loc.GetString(MaxLengthExceededMessage, MaxMessageLength));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -189,6 +211,18 @@ namespace Content.Server.Chat
|
||||
|
||||
public void SendOOC(IPlayerSession player, string message)
|
||||
{
|
||||
if (_adminManager.IsAdmin(player))
|
||||
{
|
||||
if (!_adminOocEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!_oocEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if message exceeds the character limit
|
||||
if (message.Length > MaxMessageLength)
|
||||
{
|
||||
@@ -202,7 +236,7 @@ namespace Content.Server.Chat
|
||||
msg.MessageWrap = $"OOC: {player.Name}: {{0}}";
|
||||
if (_adminManager.HasAdminFlag(player, AdminFlags.Admin))
|
||||
{
|
||||
var prefs = _preferencesManager.GetPreferences((player.UserId));
|
||||
var prefs = _preferencesManager.GetPreferences(player.UserId);
|
||||
msg.MessageColorOverride = prefs.AdminOOCColor;
|
||||
}
|
||||
//TODO: player.Name color, this will need to change the structure of the MsgChatMessage
|
||||
|
||||
@@ -252,5 +252,14 @@ namespace Content.Shared
|
||||
*/
|
||||
|
||||
public static readonly CVarDef<bool> BrandingSteam = CVarDef.Create("branding.steam", false, CVar.CLIENTONLY);
|
||||
|
||||
/*
|
||||
* OOC
|
||||
*/
|
||||
|
||||
public static readonly CVarDef<bool> OocEnabled = CVarDef.Create("ooc.enabled", true, CVar.NOTIFY);
|
||||
|
||||
public static readonly CVarDef<bool> AdminOocEnabled =
|
||||
CVarDef.Create("ooc.enabled_admin", true, CVar.NOTIFY);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user