Client command perms cleanup. (#9599)
This commit is contained in:
committed by
GitHub
parent
d3c1c9b330
commit
221c23000e
@@ -1,13 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Reflection;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.Administration.Managers
|
||||
{
|
||||
@@ -15,10 +10,13 @@ namespace Content.Client.Administration.Managers
|
||||
{
|
||||
[Dependency] private readonly IClientNetManager _netMgr = default!;
|
||||
[Dependency] private readonly IClientConGroupController _conGroup = default!;
|
||||
[Dependency] private readonly IResourceManager _res = default!;
|
||||
|
||||
private AdminData? _adminData;
|
||||
private readonly HashSet<string> _availableCommands = new();
|
||||
|
||||
private readonly AdminCommandPermissions _localCommandPermissions = new();
|
||||
|
||||
public event Action? AdminStatusUpdated;
|
||||
|
||||
public bool IsActive()
|
||||
@@ -33,6 +31,16 @@ namespace Content.Client.Administration.Managers
|
||||
|
||||
public bool CanCommand(string cmdName)
|
||||
{
|
||||
if (_adminData != null && _adminData.HasFlag(AdminFlags.Host))
|
||||
{
|
||||
// Host can execute all commands when connected.
|
||||
// Kind of a shortcut to avoid pains during development.
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_localCommandPermissions.CanCommand(cmdName, _adminData))
|
||||
return true;
|
||||
|
||||
return _availableCommands.Contains(cmdName);
|
||||
}
|
||||
|
||||
@@ -59,6 +67,12 @@ namespace Content.Client.Administration.Managers
|
||||
public void Initialize()
|
||||
{
|
||||
_netMgr.RegisterNetMessage<MsgUpdateAdminStatus>(UpdateMessageRx);
|
||||
|
||||
// Load flags for engine commands, since those don't have the attributes.
|
||||
if (_res.TryContentFileRead(new ResourcePath("/clientCommandPerms.yml"), out var efs))
|
||||
{
|
||||
_localCommandPermissions.LoadPermissionsFromStream(efs);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateMessageRx(MsgUpdateAdminStatus message)
|
||||
|
||||
Reference in New Issue
Block a user