Adds promotehost command to make bootstrapping admin privileges easier.

This commit is contained in:
Pieter-Jan Briers
2020-12-23 16:24:05 +01:00
parent 764465f60c
commit a5151af4c1
3 changed files with 48 additions and 2 deletions

View File

@@ -21,6 +21,7 @@ using Robust.Shared.Interfaces.Network;
using Robust.Shared.Interfaces.Resources; using Robust.Shared.Interfaces.Resources;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Network;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using YamlDotNet.RepresentationModel; using YamlDotNet.RepresentationModel;
@@ -40,6 +41,7 @@ namespace Content.Server.Administration
[Dependency] private readonly IChatManager _chat = default!; [Dependency] private readonly IChatManager _chat = default!;
private readonly Dictionary<IPlayerSession, AdminReg> _admins = new(); private readonly Dictionary<IPlayerSession, AdminReg> _admins = new();
private readonly HashSet<NetUserId> _promotedPlayers = new();
public event Action<AdminPermsChangedEventArgs>? OnPermsChanged; public event Action<AdminPermsChangedEventArgs>? OnPermsChanged;
@@ -227,6 +229,13 @@ namespace Content.Server.Administration
} }
} }
public void PromoteHost(IPlayerSession player)
{
_promotedPlayers.Add(player.UserId);
ReloadAdmin(player);
}
void IPostInjectInit.PostInject() void IPostInjectInit.PostInject()
{ {
_playerManager.PlayerStatusChanged += PlayerStatusChanged; _playerManager.PlayerStatusChanged += PlayerStatusChanged;
@@ -309,7 +318,7 @@ namespace Content.Server.Administration
private async Task<(AdminData dat, int? rankId, bool specialLogin)?> LoadAdminData(IPlayerSession session) private async Task<(AdminData dat, int? rankId, bool specialLogin)?> LoadAdminData(IPlayerSession session)
{ {
if (IsLocal(session) && _cfg.GetCVar(CCVars.ConsoleLoginLocal)) if (IsLocal(session) && _cfg.GetCVar(CCVars.ConsoleLoginLocal) || _promotedPlayers.Contains(session.UserId))
{ {
var data = new AdminData var data = new AdminData
{ {
@@ -463,7 +472,7 @@ namespace Content.Server.Administration
public AdminData Data; public AdminData Data;
public int? RankId; public int? RankId;
// Such as console.loginlocal // Such as console.loginlocal or promotehost
public bool IsSpecialLogin; public bool IsSpecialLogin;
public AdminReg(IPlayerSession session, AdminData data) public AdminReg(IPlayerSession session, AdminData data)

View File

@@ -0,0 +1,35 @@
#nullable enable
using JetBrains.Annotations;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.IoC;
namespace Content.Server.Administration.Commands
{
[UsedImplicitly]
public sealed class PromoteHostCommand : IClientCommand
{
public string Command => "promotehost";
public string Description => "Grants client temporary full host admin privileges. Use this to bootstrap admins.";
public string Help => "Usage promotehost <player>";
public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
{
if (args.Length != 1)
{
shell.SendText(player, "Expected exactly one argument.");
return;
}
var plyMgr = IoCManager.Resolve<IPlayerManager>();
if (!plyMgr.TryGetSessionByUsername(args[0], out var targetPlayer))
{
shell.SendText(player, "Unable to find a player by that name.");
return;
}
var adminMgr = IoCManager.Resolve<IAdminManager>();
adminMgr.PromoteHost(targetPlayer);
}
}
}

View File

@@ -72,5 +72,7 @@ namespace Content.Server.Administration
void ReloadAdminsWithRank(int rankId); void ReloadAdminsWithRank(int rankId);
void Initialize(); void Initialize();
void PromoteHost(IPlayerSession player);
} }
} }