Add ShowRules commmand (#5908)
This commit is contained in:
67
Content.Server/Info/ShowRulesCommand.cs
Normal file
67
Content.Server/Info/ShowRulesCommand.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Info;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Network;
|
||||
|
||||
namespace Content.Server.Info;
|
||||
|
||||
[AdminCommand(AdminFlags.Admin)]
|
||||
public class ShowRulesCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "showrules";
|
||||
public string Description => "Opens the rules popup for the specified player.";
|
||||
public string Help => "showrules <username> [time]";
|
||||
public async void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
string target;
|
||||
float seconds;
|
||||
|
||||
switch (args.Length)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
target = args[0];
|
||||
var configurationManager = IoCManager.Resolve<IConfigurationManager>();
|
||||
seconds = configurationManager.GetCVar(CCVars.RulesWaitTime);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
if (float.TryParse(args[1], out seconds))
|
||||
return;
|
||||
|
||||
target = args[0];
|
||||
shell.WriteLine($"{args[1]} is not a valid amount of minutes.\n{Help}");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
shell.WriteLine(Help);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var locator = IoCManager.Resolve<IPlayerLocator>();
|
||||
var located = await locator.LookupIdByNameOrIdAsync(target);
|
||||
if (located == null)
|
||||
{
|
||||
shell.WriteError("Unable to find a player with that name.");
|
||||
return;
|
||||
}
|
||||
|
||||
var message = new SharedRulesManager.ShowRulesPopupMessage
|
||||
{
|
||||
PopupTime = seconds
|
||||
};
|
||||
|
||||
var player = IoCManager.Resolve<IPlayerManager>()
|
||||
.GetSessionByUserId(located.UserId);
|
||||
IoCManager.Resolve<INetManager>()
|
||||
.ServerSendMessage(message, player.ConnectedClient);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user