ConGroups are gone. Long live admin flags in content.
This commit is contained in:
39
Content.Shared/Administration/AdminData.cs
Normal file
39
Content.Shared/Administration/AdminData.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
#nullable enable
|
||||
|
||||
namespace Content.Shared.Administration
|
||||
{
|
||||
public sealed class AdminData
|
||||
{
|
||||
public const string DefaultTitle = "Admin";
|
||||
|
||||
// Can be false if they're de-adminned with the ability to re-admin.
|
||||
public bool Active;
|
||||
public string? Title;
|
||||
public AdminFlags Flags;
|
||||
|
||||
public bool HasFlag(AdminFlags flag)
|
||||
{
|
||||
return Active && (Flags & flag) == flag;
|
||||
}
|
||||
|
||||
public bool CanViewVar()
|
||||
{
|
||||
return HasFlag(AdminFlags.VarEdit);
|
||||
}
|
||||
|
||||
public bool CanAdminPlace()
|
||||
{
|
||||
return HasFlag(AdminFlags.Spawn);
|
||||
}
|
||||
|
||||
public bool CanScript()
|
||||
{
|
||||
return HasFlag(AdminFlags.Host);
|
||||
}
|
||||
|
||||
public bool CanAdminMenu()
|
||||
{
|
||||
return HasFlag(AdminFlags.Admin);
|
||||
}
|
||||
}
|
||||
}
|
||||
68
Content.Shared/Administration/AdminFlags.cs
Normal file
68
Content.Shared/Administration/AdminFlags.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
|
||||
namespace Content.Shared.Administration
|
||||
{
|
||||
/// <summary>
|
||||
/// Permissions that admins can have.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum AdminFlags : uint
|
||||
{
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Basic admin verbs.
|
||||
/// </summary>
|
||||
Admin = 1 << 0,
|
||||
|
||||
/// <summary>
|
||||
/// Ability to ban people.
|
||||
/// </summary>
|
||||
Ban = 1 << 1,
|
||||
|
||||
/// <summary>
|
||||
/// Debug commands for coders.
|
||||
/// </summary>
|
||||
Debug = 1 << 2,
|
||||
|
||||
/// <summary>
|
||||
/// !!FUN!!
|
||||
/// </summary>
|
||||
Fun = 1 << 3,
|
||||
|
||||
/// <summary>
|
||||
/// Ability to edit permissions for other administrators.
|
||||
/// </summary>
|
||||
Permissions = 1 << 4,
|
||||
|
||||
/// <summary>
|
||||
/// Ability to control teh server like restart it or change the round type.
|
||||
/// </summary>
|
||||
Server = 1 << 5,
|
||||
|
||||
/// <summary>
|
||||
/// Ability to spawn stuff in.
|
||||
/// </summary>
|
||||
Spawn = 1 << 6,
|
||||
|
||||
/// <summary>
|
||||
/// Ability to use VV.
|
||||
/// </summary>
|
||||
VarEdit = 1 << 7,
|
||||
|
||||
/// <summary>
|
||||
/// Large mapping operations.
|
||||
/// </summary>
|
||||
Mapping = 1 << 8,
|
||||
|
||||
/// <summary>
|
||||
/// Makes you british.
|
||||
/// </summary>
|
||||
Piss = 1 << 9,
|
||||
|
||||
/// <summary>
|
||||
/// Dangerous host permissions like scsi.
|
||||
/// </summary>
|
||||
Host = 1u << 31,
|
||||
}
|
||||
}
|
||||
73
Content.Shared/Administration/AdminFlagsExt.cs
Normal file
73
Content.Shared/Administration/AdminFlagsExt.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Content.Shared.Administration
|
||||
{
|
||||
public static class AdminFlagsExt
|
||||
{
|
||||
private static readonly Dictionary<string, AdminFlags> NameFlagsMap = new Dictionary<string, AdminFlags>();
|
||||
private static readonly string[] FlagsNameMap = new string[32];
|
||||
|
||||
public static readonly AdminFlags Everything;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public static AdminFlags NamesToFlags(IEnumerable<string> names)
|
||||
{
|
||||
var flags = AdminFlags.None;
|
||||
foreach (var name in names)
|
||||
{
|
||||
if (!NameFlagsMap.TryGetValue(name, out var value))
|
||||
{
|
||||
throw new ArgumentException($"Invalid admin flag name: {name}");
|
||||
}
|
||||
|
||||
flags |= value;
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
public static AdminFlags NameToFlag(string name)
|
||||
{
|
||||
return NameFlagsMap[name];
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user