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 event Action? AdminStatusUpdated;
|
||||||
|
|
||||||
|
public bool IsActive()
|
||||||
|
{
|
||||||
|
return _adminData?.Active ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
public bool HasFlag(AdminFlags flag)
|
public bool HasFlag(AdminFlags flag)
|
||||||
{
|
{
|
||||||
return _adminData?.HasFlag(flag) ?? false;
|
return _adminData?.HasFlag(flag) ?? false;
|
||||||
|
|||||||
@@ -15,6 +15,12 @@ namespace Content.Client.Administration
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
event Action AdminStatusUpdated;
|
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>
|
/// <summary>
|
||||||
/// Checks whether the local player has an admin flag.
|
/// Checks whether the local player has an admin flag.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
|
using Content.Client.Administration;
|
||||||
using Content.Client.Chat;
|
using Content.Client.Chat;
|
||||||
using Content.Client.Interfaces.Chat;
|
using Content.Client.Interfaces.Chat;
|
||||||
using Content.Client.UserInterface;
|
using Content.Client.UserInterface;
|
||||||
using Content.Client.Voting;
|
using Content.Client.Voting;
|
||||||
|
using Content.Shared;
|
||||||
using Content.Shared.Input;
|
using Content.Shared.Input;
|
||||||
using Robust.Client.Input;
|
using Robust.Client.Input;
|
||||||
using Robust.Client.UserInterface;
|
using Robust.Client.UserInterface;
|
||||||
using Robust.Client.UserInterface.Controls;
|
using Robust.Client.UserInterface.Controls;
|
||||||
|
using Robust.Shared.Configuration;
|
||||||
using Robust.Shared.Input.Binding;
|
using Robust.Shared.Input.Binding;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Localization;
|
using Robust.Shared.Localization;
|
||||||
@@ -20,9 +23,14 @@ namespace Content.Client.State
|
|||||||
[Dependency] private readonly IInputManager _inputManager = default!;
|
[Dependency] private readonly IInputManager _inputManager = default!;
|
||||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||||
[Dependency] private readonly IVoteManager _voteManager = default!;
|
[Dependency] private readonly IVoteManager _voteManager = default!;
|
||||||
|
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
||||||
|
[Dependency] private readonly IClientAdminManager _adminManager = default!;
|
||||||
|
|
||||||
[ViewVariables] private ChatBox _gameChat;
|
[ViewVariables] private ChatBox _gameChat;
|
||||||
|
|
||||||
|
private bool _oocEnabled;
|
||||||
|
private bool _adminOocEnabled;
|
||||||
|
|
||||||
public override void Startup()
|
public override void Startup()
|
||||||
{
|
{
|
||||||
base.Startup();
|
base.Startup();
|
||||||
@@ -42,13 +50,17 @@ namespace Content.Client.State
|
|||||||
_gameChat.Input.PlaceHolder = Loc.GetString("Say something! [ for OOC");
|
_gameChat.Input.PlaceHolder = Loc.GetString("Say something! [ for OOC");
|
||||||
|
|
||||||
_inputManager.SetInputCommand(ContentKeyFunctions.FocusChat,
|
_inputManager.SetInputCommand(ContentKeyFunctions.FocusChat,
|
||||||
InputCmdHandler.FromDelegate(s => FocusChat(_gameChat)));
|
InputCmdHandler.FromDelegate(_ => FocusChat(_gameChat)));
|
||||||
|
|
||||||
_inputManager.SetInputCommand(ContentKeyFunctions.FocusOOC,
|
_inputManager.SetInputCommand(ContentKeyFunctions.FocusOOC,
|
||||||
InputCmdHandler.FromDelegate(s => FocusOOC(_gameChat)));
|
InputCmdHandler.FromDelegate(_ => FocusOOC(_gameChat)));
|
||||||
|
|
||||||
_inputManager.SetInputCommand(ContentKeyFunctions.FocusAdminChat,
|
_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()
|
public override void Shutdown()
|
||||||
@@ -59,6 +71,37 @@ namespace Content.Client.State
|
|||||||
_gameHud.RootControl.Orphan();
|
_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)
|
internal static void FocusChat(ChatBox chat)
|
||||||
{
|
{
|
||||||
if (chat == null || chat.UserInterfaceManager.KeyboardFocused != null)
|
if (chat == null || chat.UserInterfaceManager.KeyboardFocused != null)
|
||||||
|
|||||||
@@ -53,6 +53,11 @@ namespace Content.Server.Administration
|
|||||||
private readonly HashSet<string> _anyCommands = new();
|
private readonly HashSet<string> _anyCommands = new();
|
||||||
private readonly Dictionary<string, AdminFlags[]> _adminCommands = 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)
|
public AdminData? GetAdminData(IPlayerSession session, bool includeDeAdmin = false)
|
||||||
{
|
{
|
||||||
if (_admins.TryGetValue(session, out var reg) && (reg.Data.Active || includeDeAdmin))
|
if (_admins.TryGetValue(session, out var reg) && (reg.Data.Active || includeDeAdmin))
|
||||||
|
|||||||
@@ -25,12 +25,22 @@ namespace Content.Server.Administration
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
IEnumerable<IPlayerSession> ActiveAdmins { get; }
|
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>
|
/// <summary>
|
||||||
/// Gets the admin data for a player, if they are an admin.
|
/// Gets the admin data for a player, if they are an admin.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="session">The player to get admin data for.</param>
|
/// <param name="session">The player to get admin data for.</param>
|
||||||
/// <param name="includeDeAdmin">
|
/// <param name="includeDeAdmin">
|
||||||
/// Whether to return admin data for admins that are current de-adminned.
|
/// Whether to return admin data for admins that are current de-adminned.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns><see langword="null" /> if the player is not an admin.</returns>
|
/// <returns><see langword="null" /> if the player is not an admin.</returns>
|
||||||
AdminData? GetAdminData(IPlayerSession session, bool includeDeAdmin = false);
|
AdminData? GetAdminData(IPlayerSession session, bool includeDeAdmin = false);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using Content.Server.GameObjects.Components.Observer;
|
|||||||
using Content.Server.GameObjects.EntitySystems;
|
using Content.Server.GameObjects.EntitySystems;
|
||||||
using Content.Server.Interfaces;
|
using Content.Server.Interfaces;
|
||||||
using Content.Server.Interfaces.Chat;
|
using Content.Server.Interfaces.Chat;
|
||||||
|
using Content.Shared;
|
||||||
using Content.Shared.Administration;
|
using Content.Shared.Administration;
|
||||||
using Content.Shared.Chat;
|
using Content.Shared.Chat;
|
||||||
using Content.Shared.GameObjects.Components.Inventory;
|
using Content.Shared.GameObjects.Components.Inventory;
|
||||||
@@ -15,6 +16,7 @@ using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
|
|||||||
using Content.Shared.Interfaces;
|
using Content.Shared.Interfaces;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Server.Player;
|
using Robust.Server.Player;
|
||||||
|
using Robust.Shared.Configuration;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Localization;
|
using Robust.Shared.Localization;
|
||||||
@@ -29,10 +31,17 @@ namespace Content.Server.Chat
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal sealed class ChatManager : IChatManager
|
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>
|
/// <summary>
|
||||||
/// The maximum length a player-sent message can be sent
|
/// The maximum length a player-sent message can be sent
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int MaxMessageLength = 1000;
|
public const int MaxMessageLength = 1000;
|
||||||
|
|
||||||
private const int VoiceRange = 7; // how far voice goes in world units
|
private const int VoiceRange = 7; // how far voice goes in world units
|
||||||
|
|
||||||
@@ -43,12 +52,8 @@ namespace Content.Server.Chat
|
|||||||
|
|
||||||
//TODO: make prio based?
|
//TODO: make prio based?
|
||||||
private List<TransformChat> _chatTransformHandlers;
|
private List<TransformChat> _chatTransformHandlers;
|
||||||
|
private bool _oocEnabled = true;
|
||||||
[Dependency] private readonly IServerNetManager _netManager = default!;
|
private bool _adminOocEnabled = true;
|
||||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
||||||
[Dependency] private readonly IMoMMILink _mommiLink = default!;
|
|
||||||
[Dependency] private readonly IAdminManager _adminManager = default!;
|
|
||||||
[Dependency] private readonly IServerPreferencesManager _preferencesManager = default!;
|
|
||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
@@ -61,6 +66,21 @@ namespace Content.Server.Chat
|
|||||||
_netManager.ServerSendToAll(msg);
|
_netManager.ServerSendToAll(msg);
|
||||||
|
|
||||||
_chatTransformHandlers = new List<TransformChat>();
|
_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)
|
public void DispatchServerAnnouncement(string message)
|
||||||
@@ -166,15 +186,17 @@ namespace Content.Server.Chat
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if entity is a player
|
// 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
|
// Check if message exceeds the character limit
|
||||||
if (playerSession != null)
|
if (actor.playerSession != null && action.Length > MaxMessageLength)
|
||||||
if (action.Length > MaxMessageLength)
|
{
|
||||||
{
|
DispatchServerMessage(actor.playerSession, Loc.GetString(MaxLengthExceededMessage, MaxMessageLength));
|
||||||
DispatchServerMessage(playerSession, Loc.GetString(MaxLengthExceededMessage, MaxMessageLength));
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var pos = source.Transform.Coordinates;
|
var pos = source.Transform.Coordinates;
|
||||||
var clients = _playerManager.GetPlayersInRange(pos, VoiceRange).Select(p => p.ConnectedClient);
|
var clients = _playerManager.GetPlayersInRange(pos, VoiceRange).Select(p => p.ConnectedClient);
|
||||||
@@ -189,6 +211,18 @@ namespace Content.Server.Chat
|
|||||||
|
|
||||||
public void SendOOC(IPlayerSession player, string message)
|
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
|
// Check if message exceeds the character limit
|
||||||
if (message.Length > MaxMessageLength)
|
if (message.Length > MaxMessageLength)
|
||||||
{
|
{
|
||||||
@@ -202,7 +236,7 @@ namespace Content.Server.Chat
|
|||||||
msg.MessageWrap = $"OOC: {player.Name}: {{0}}";
|
msg.MessageWrap = $"OOC: {player.Name}: {{0}}";
|
||||||
if (_adminManager.HasAdminFlag(player, AdminFlags.Admin))
|
if (_adminManager.HasAdminFlag(player, AdminFlags.Admin))
|
||||||
{
|
{
|
||||||
var prefs = _preferencesManager.GetPreferences((player.UserId));
|
var prefs = _preferencesManager.GetPreferences(player.UserId);
|
||||||
msg.MessageColorOverride = prefs.AdminOOCColor;
|
msg.MessageColorOverride = prefs.AdminOOCColor;
|
||||||
}
|
}
|
||||||
//TODO: player.Name color, this will need to change the structure of the MsgChatMessage
|
//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);
|
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