static AdminFlagsHelper() { var t = typeof(AdminFlags); var flags = (AdminFlags[])Enum.GetValues(t); var allFlags = new List <AdminFlags>(); foreach (var value in flags) { var name = value.ToString().ToUpper(); // If, in the future, somebody adds a combined admin flag or something for convenience, // ignore it. if (BitOperations.PopCount((uint)value) != 1) { continue; } allFlags.Add(value); Everything |= value; NameFlagsMap.Add(name, value); FlagsNameMap[BitOperations.Log2((uint)value)] = name; } AllFlags = allFlags.ToArray(); }
public static string PosNegFlagsText(AdminFlags posFlags, AdminFlags negFlags) { var posFlagNames = FlagsToNames(posFlags).Select(f => (flag: f, fText: $"+{f}")); var negFlagNames = FlagsToNames(negFlags).Select(f => (flag: f, fText: $"-{f}")); var flagsText = string.Join(' ', posFlagNames.Concat(negFlagNames).OrderBy(f => f.flag).Select(p => p.fText)); return(flagsText); }
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;
/// <summary> /// Converts a bitfield of admin flags to an array of all the flag names set. /// </summary> public static string[] FlagsToNames(AdminFlags flags) { var array = new string[BitOperations.PopCount((uint)flags)]; var highest = BitOperations.LeadingZeroCount((uint)flags); var ai = 0; for (var i = 0; i < 32 - highest; i++) { var flagValue = (AdminFlags)(1u << i); if ((flags & flagValue) != 0) { array[ai++] = FlagsNameMap[i]; } } return(array); }
static AdminFlagsExt() { var t = typeof(AdminFlags); var flags = (AdminFlags[])Enum.GetValues(t); foreach (var value in flags) { var name = value.ToString().ToUpper(); if (BitOperations.PopCount((uint)value) != 1) { continue; } Everything |= value; NameFlagsMap.Add(name, value); FlagsNameMap[BitOperations.Log2((uint)value)] = name; } }
/// <summary> /// Checks whether this admin has an admin flag. /// </summary> /// <param name="flag">The flags to check. Multiple flags can be specified, they must all be held.</param> /// <returns>False if this admin is not <see cref="Active"/> or does not have all the flags specified.</returns> public bool HasFlag(AdminFlags flag) { return(Active && (Flags & flag) == flag); }
public AdminCommandAttribute(AdminFlags flags) { Flags = flags; }
internal bool HasFlag(AdminFlags flag) { return(this.flags.HasFlag(flag)); }
public AdminRank(string name, AdminFlags flags) { Name = name; Flags = flags; }
public void TestFlagsToNames(string namesConcat, AdminFlags flags) { var names = namesConcat.Split(",", StringSplitOptions.RemoveEmptyEntries); Assert.That(AdminFlagsHelper.FlagsToNames(flags), Is.EquivalentTo(names)); }
/// <summary> /// Initializes a new instance of the <see cref="AdminInfo"/> class. /// </summary> /// <param name="authId">The 64 bit AuthID of the user.</param> /// <param name="immunity">The user's immunity level.</param> /// <param name="flags">The user's access flags.</param> internal AdminInfo(string authId, int immunity, AdminFlags flags) { this.AuthID = authId; this.Immunity = immunity; this.Flags = flags; }
/// <summary> /// Creates a new <see cref="AdminCommand"/> or returns the existing one if one with the same name already exists. /// </summary> /// <param name="cmd">The name of the admin command.</param> /// <param name="accessFlags">The <see cref="AdminFlags"/> value required to execute the admin command.</param> /// <param name="description">An optional description for the admin command.</param> /// <returns>The <see cref="AdminCommand"/> object representing the admin command.</returns> protected AdminCommand RegAdminCmd(string cmd, AdminFlags accessFlags, string description = "") { return(AdminCommandManager.CreateCommand(this, cmd, accessFlags, description)); }
public void TestNamesToFlags(string namesConcat, AdminFlags flags) { var names = namesConcat.Split(",", StringSplitOptions.RemoveEmptyEntries); Assert.That(AdminFlagsExt.NamesToFlags(names), Is.EqualTo(flags)); }
private bool UserAdminFlagCheck(AdminFlags flags) { return(_adminManager.HasAdminFlag(Player, flags)); }
internal AdminOptionsConfiguration(int flags) { this.flags = (AdminFlags)flags; }
public bool HasFlag(AdminFlags flag) { return(_adminData?.HasFlag(flag) ?? false); }
/// <summary> /// Initializes a new instance of the <see cref="AdminCommand"/> class. /// </summary> /// <param name="command">The name of the command.</param> /// <param name="description">The description for the command.</param> /// <param name="accessFlags">The <see cref="AccessFlags"/> value required to execute this /// command.</param> internal AdminCommand(string command, string description, AdminFlags accessFlags) { this.Command = command; this.Description = description; this.AccessFlags = accessFlags; }