public void Initialize() { _netMgr.RegisterNetMessage <MsgUpdateAdminStatus>(MsgUpdateAdminStatus.NAME); // Cache permissions for loaded console commands with the requisite attributes. foreach (var(cmdName, cmd) in _consoleShell.AvailableCommands) { var(isAvail, flagsReq) = GetRequiredFlag(cmd); if (!isAvail) { continue; } if (flagsReq.Length != 0) { _adminCommands.Add(cmdName, flagsReq); } else { _anyCommands.Add(cmdName); } } // Load flags for engine commands, since those don't have the attributes. if (_res.TryContentFileRead(new ResourcePath("/engineCommandPerms.yml"), out var 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 flagNames = flagsNode.AsString().Split(",", StringSplitOptions.RemoveEmptyEntries); var flags = AdminFlagsExt.NamesToFlags(flagNames); foreach (var cmd in commands) { if (!_adminCommands.TryGetValue(cmd, out var exFlags)) { _adminCommands.Add(cmd, new [] { flags }); } else { var newArr = new AdminFlags[exFlags.Length + 1]; exFlags.CopyTo(newArr, 0); exFlags[^ 1] = flags;
public void TestNamesToFlags(string namesConcat, AdminFlags flags) { var names = namesConcat.Split(",", StringSplitOptions.RemoveEmptyEntries); Assert.That(AdminFlagsExt.NamesToFlags(names), Is.EqualTo(flags)); }