Files
tbd-station-14/Content.Server/Info/ShowRulesCommand.cs
Pieter-Jan Briers 68ce53ae17 Random spontaneous cleanup PR (#25131)
* Use new Subs.CVar helper

Removes manual config OnValueChanged calls, removes need to remember to manually unsubscribe.

This both reduces boilerplate and fixes many issues where subscriptions weren't removed on entity system shutdown.

* Fix a bunch of warnings

* More warning fixes

* Use new DateTime serializer to get rid of ISerializationHooks in changelog code.

* Get rid of some more ISerializationHooks for enums

* And a little more

* Apply suggestions from code review

Co-authored-by: 0x6273 <0x40@keemail.me>

---------

Co-authored-by: 0x6273 <0x40@keemail.me>
2024-02-13 16:48:39 -05:00

67 lines
2.0 KiB
C#

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.Network;
namespace Content.Server.Info;
[AdminCommand(AdminFlags.Admin)]
public sealed class ShowRulesCommand : IConsoleCommand
{
public string Command => "showrules";
public string Description => "Opens the rules popup for the specified player.";
public string Help => "showrules <username> [seconds]";
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))
{
shell.WriteError($"{args[1]} is not a valid amount of seconds.\n{Help}");
return;
}
target = args[0];
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 netManager = IoCManager.Resolve<INetManager>();
var message = new SharedRulesManager.ShowRulesPopupMessage();
message.PopupTime = seconds;
var player = IoCManager.Resolve<IPlayerManager>().GetSessionById(located.UserId);
netManager.ServerSendMessage(message, player.Channel);
}
}