Fix client-only command permissions. (#5899)
This commit is contained in:
committed by
GitHub
parent
1e42bafea4
commit
666be08d86
@@ -2,6 +2,7 @@ using System;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Content.Client.Resources;
|
using Content.Client.Resources;
|
||||||
using Content.Client.Stylesheets;
|
using Content.Client.Stylesheets;
|
||||||
|
using Content.Shared.Administration;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Client.AutoGenerated;
|
using Robust.Client.AutoGenerated;
|
||||||
using Robust.Client.ResourceManagement;
|
using Robust.Client.ResourceManagement;
|
||||||
@@ -198,7 +199,7 @@ namespace Content.Client.Changelog
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[UsedImplicitly]
|
[UsedImplicitly, AnyCommand]
|
||||||
public sealed class ChangelogCommand : IConsoleCommand
|
public sealed class ChangelogCommand : IConsoleCommand
|
||||||
{
|
{
|
||||||
public string Command => "changelog";
|
public string Command => "changelog";
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
using Content.Client.Credits;
|
using Content.Client.Credits;
|
||||||
using Content.Client.UserInterface;
|
using Content.Client.UserInterface;
|
||||||
|
using Content.Shared.Administration;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Shared.Console;
|
using Robust.Shared.Console;
|
||||||
|
|
||||||
namespace Content.Client.Commands
|
namespace Content.Client.Commands
|
||||||
{
|
{
|
||||||
[UsedImplicitly]
|
[UsedImplicitly, AnyCommand]
|
||||||
public sealed class CreditsCommand : IConsoleCommand
|
public sealed class CreditsCommand : IConsoleCommand
|
||||||
{
|
{
|
||||||
public string Command => "credits";
|
public string Command => "credits";
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Content.Shared;
|
using Content.Shared.Administration;
|
||||||
using Content.Shared.CCVar;
|
using Content.Shared.CCVar;
|
||||||
using Robust.Shared.Configuration;
|
using Robust.Shared.Configuration;
|
||||||
using Robust.Shared.Console;
|
using Robust.Shared.Console;
|
||||||
@@ -6,6 +6,7 @@ using Robust.Shared.IoC;
|
|||||||
|
|
||||||
namespace Content.Client.Commands
|
namespace Content.Client.Commands
|
||||||
{
|
{
|
||||||
|
[AnyCommand]
|
||||||
public class ToggleOutlineCommand : IConsoleCommand
|
public class ToggleOutlineCommand : IConsoleCommand
|
||||||
{
|
{
|
||||||
public string Command => "toggleoutline";
|
public string Command => "toggleoutline";
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using Content.Client.Stylesheets;
|
using Content.Client.Stylesheets;
|
||||||
|
using Content.Shared.Administration;
|
||||||
using Content.Shared.Voting;
|
using Content.Shared.Voting;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Client.AutoGenerated;
|
using Robust.Client.AutoGenerated;
|
||||||
@@ -150,7 +151,7 @@ namespace Content.Client.Voting.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[UsedImplicitly]
|
[UsedImplicitly, AnyCommand]
|
||||||
public sealed class VoteMenuCommand : IConsoleCommand
|
public sealed class VoteMenuCommand : IConsoleCommand
|
||||||
{
|
{
|
||||||
public string Command => "votemenu";
|
public string Command => "votemenu";
|
||||||
|
|||||||
@@ -193,42 +193,54 @@ namespace Content.Server.Administration.Managers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load flags for engine commands, since those don't have the attributes.
|
// Load flags for engine commands, since those don't have the attributes.
|
||||||
if (_res.TryContentFileRead(new ResourcePath("/engineCommandPerms.yml"), out var fs))
|
if (_res.TryContentFileRead(new ResourcePath("/engineCommandPerms.yml"), out var efs))
|
||||||
{
|
{
|
||||||
using var reader = new StreamReader(fs, EncodingHelpers.UTF8);
|
LoadPermissionsFromStream(efs);
|
||||||
var yStream = new YamlStream();
|
}
|
||||||
yStream.Load(reader);
|
|
||||||
var root = (YamlSequenceNode) yStream.Documents[0].RootNode;
|
|
||||||
|
|
||||||
foreach (var child in root)
|
// Load flags for client-only commands, those don't have the flag attributes, only "AnyCommand".
|
||||||
|
if (_res.TryContentFileRead(new ResourcePath("/clientCommandPerms.yml"), out var cfs))
|
||||||
|
{
|
||||||
|
LoadPermissionsFromStream(cfs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadPermissionsFromStream(Stream fs)
|
||||||
|
{
|
||||||
|
using var reader = new StreamReader(fs, EncodingHelpers.UTF8);
|
||||||
|
var yStream = new YamlStream();
|
||||||
|
yStream.Load(reader);
|
||||||
|
var root = (YamlSequenceNode) yStream.Documents[0].RootNode;
|
||||||
|
|
||||||
|
foreach (var child in root)
|
||||||
|
{
|
||||||
|
var map = (YamlMappingNode) child;
|
||||||
|
var commands = map.GetNode<YamlSequenceNode>("Commands").Select(p => p.AsString());
|
||||||
|
if (map.TryGetNode("Flags", out var flagsNode))
|
||||||
{
|
{
|
||||||
var map = (YamlMappingNode) child;
|
var flagNames = flagsNode.AsString().Split(",", StringSplitOptions.RemoveEmptyEntries);
|
||||||
var commands = map.GetNode<YamlSequenceNode>("Commands").Select(p => p.AsString());
|
var flags = AdminFlagsHelper.NamesToFlags(flagNames);
|
||||||
if (map.TryGetNode("Flags", out var flagsNode))
|
foreach (var cmd in commands)
|
||||||
{
|
{
|
||||||
var flagNames = flagsNode.AsString().Split(",", StringSplitOptions.RemoveEmptyEntries);
|
if (!_adminCommands.TryGetValue(cmd, out var exFlags))
|
||||||
var flags = AdminFlagsHelper.NamesToFlags(flagNames);
|
|
||||||
foreach (var cmd in commands)
|
|
||||||
{
|
{
|
||||||
if (!_adminCommands.TryGetValue(cmd, out var exFlags))
|
_adminCommands.Add(cmd, new[] {flags});
|
||||||
{
|
}
|
||||||
_adminCommands.Add(cmd, new[] {flags});
|
else
|
||||||
}
|
{
|
||||||
else
|
var newArr = new AdminFlags[exFlags.Length + 1];
|
||||||
{
|
exFlags.CopyTo(newArr, 0);
|
||||||
var newArr = new AdminFlags[exFlags.Length + 1];
|
exFlags[^1] = flags;
|
||||||
exFlags.CopyTo(newArr, 0);
|
_adminCommands[cmd] = newArr;
|
||||||
exFlags[^1] = flags;
|
|
||||||
_adminCommands[cmd] = newArr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
_anyCommands.UnionWith(commands);
|
{
|
||||||
}
|
_anyCommands.UnionWith(commands);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PromoteHost(IPlayerSession player)
|
public void PromoteHost(IPlayerSession player)
|
||||||
|
|||||||
30
Resources/clientCommandPerms.yml
Normal file
30
Resources/clientCommandPerms.yml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
- Flags: DEBUG
|
||||||
|
Commands:
|
||||||
|
- atvrange
|
||||||
|
- atvmode
|
||||||
|
- atvcbm
|
||||||
|
- debugai
|
||||||
|
- notify
|
||||||
|
- pathfinder
|
||||||
|
- entitymenug
|
||||||
|
- hidemechanisms
|
||||||
|
- showmechanisms
|
||||||
|
- menuvis
|
||||||
|
- togglehealthoverlay
|
||||||
|
- toggledecals
|
||||||
|
- nodevis
|
||||||
|
- nodevisfilter
|
||||||
|
|
||||||
|
- Flags: MAPPING
|
||||||
|
Commands:
|
||||||
|
- showmarkers
|
||||||
|
- showsubfloor
|
||||||
|
- showsubfloorforever
|
||||||
|
- mapping
|
||||||
|
- toggledecals
|
||||||
|
- nodevis
|
||||||
|
- nodevisfilter
|
||||||
|
|
||||||
|
- Flags: ADMIN
|
||||||
|
Commands:
|
||||||
|
- togglehealthoverlay
|
||||||
@@ -38,7 +38,9 @@ SHARED_IGNORED_RESOURCES = {
|
|||||||
CLIENT_IGNORED_RESOURCES = {
|
CLIENT_IGNORED_RESOURCES = {
|
||||||
"Maps",
|
"Maps",
|
||||||
"emotes.xml",
|
"emotes.xml",
|
||||||
"Groups"
|
"Groups",
|
||||||
|
"engineCommandPerms.yml",
|
||||||
|
"clientCommandPerms.yml"
|
||||||
}
|
}
|
||||||
|
|
||||||
CLIENT_CONTENT_ASSEMBLIES = [
|
CLIENT_CONTENT_ASSEMBLIES = [
|
||||||
|
|||||||
Reference in New Issue
Block a user