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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,9 @@ namespace Content.Shared
|
||||
public static readonly CVarDef<bool>
|
||||
GamePersistGuests = CVarDef.Create("game.persistguests", true, CVar.ARCHIVE | CVar.SERVERONLY);
|
||||
|
||||
public static readonly CVarDef<bool>
|
||||
ConsoleLoginLocal = CVarDef.Create("console.loginlocal", true, CVar.ARCHIVE);
|
||||
|
||||
|
||||
/*
|
||||
* Database stuff
|
||||
|
||||
73
Content.Shared/Network/NetMessages/MsgUpdateAdminStatus.cs
Normal file
73
Content.Shared/Network/NetMessages/MsgUpdateAdminStatus.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using Content.Shared.Administration;
|
||||
using Lidgren.Network;
|
||||
using Robust.Shared.Interfaces.Network;
|
||||
using Robust.Shared.Network;
|
||||
|
||||
namespace Content.Shared.Network.NetMessages
|
||||
{
|
||||
public sealed class MsgUpdateAdminStatus : NetMessage
|
||||
{
|
||||
#region REQUIRED
|
||||
|
||||
public const MsgGroups GROUP = MsgGroups.Command;
|
||||
public const string NAME = nameof(MsgUpdateAdminStatus);
|
||||
|
||||
public MsgUpdateAdminStatus(INetChannel channel) : base(NAME, GROUP) { }
|
||||
|
||||
#endregion
|
||||
|
||||
public AdminData Admin;
|
||||
public string[] AvailableCommands;
|
||||
|
||||
public override void ReadFromBuffer(NetIncomingMessage buffer)
|
||||
{
|
||||
var count = buffer.ReadVariableInt32();
|
||||
|
||||
AvailableCommands = new string[count];
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
AvailableCommands[i] = buffer.ReadString();
|
||||
}
|
||||
|
||||
if (buffer.ReadBoolean())
|
||||
{
|
||||
var active = buffer.ReadBoolean();
|
||||
buffer.ReadPadBits();
|
||||
var flags = (AdminFlags) buffer.ReadUInt32();
|
||||
var title = buffer.ReadString();
|
||||
|
||||
Admin = new AdminData
|
||||
{
|
||||
Active = active,
|
||||
Title = title,
|
||||
Flags = flags,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override void WriteToBuffer(NetOutgoingMessage buffer)
|
||||
{
|
||||
buffer.WriteVariableInt32(AvailableCommands.Length);
|
||||
|
||||
foreach (var cmd in AvailableCommands)
|
||||
{
|
||||
buffer.Write(cmd);
|
||||
}
|
||||
|
||||
var isAdmin = Admin != null;
|
||||
buffer.Write(isAdmin);
|
||||
|
||||
if (isAdmin)
|
||||
{
|
||||
buffer.Write(Admin.Active);
|
||||
buffer.WritePadBits();
|
||||
buffer.Write((uint) Admin.Flags);
|
||||
buffer.Write(Admin.Title);
|
||||
}
|
||||
}
|
||||
|
||||
public override NetDeliveryMethod DeliveryMethod => NetDeliveryMethod.ReliableOrdered;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user