mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-26 22:48:20 +01:00
46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using TGS.Interface;
|
|
|
|
namespace TGS.Server.ChatCommands
|
|
{
|
|
/// <summary>
|
|
/// A command heard by a <see cref="ChatProviders.IChatProvider"/>
|
|
/// </summary>
|
|
abstract class ChatCommand : Command
|
|
{
|
|
/// <summary>
|
|
/// <see cref="CommandInfo"/> for the <see cref="ChatCommand"/>
|
|
/// </summary>
|
|
public static ThreadLocal<CommandInfo> CommandInfo { get; private set; } = new ThreadLocal<CommandInfo>();
|
|
/// <summary>
|
|
/// If set to <see langword="true"/>, the <see cref="ChatCommand"/> cannot be invoked by a non-admin or outside an admin chat channel
|
|
/// </summary>
|
|
public bool RequiresAdmin { get; protected set; }
|
|
/// <summary>
|
|
/// Shorthand for accessing <see cref="CommandInfo.Server"/>
|
|
/// </summary>
|
|
protected Instance Instance { get { return CommandInfo.Value.Server; } }
|
|
|
|
/// <inheritdoc />
|
|
public override ExitCode DoRun(IList<string> parameters)
|
|
{
|
|
if (RequiresAdmin)
|
|
{
|
|
var Info = CommandInfo.Value;
|
|
if (!Info.IsAdmin)
|
|
{
|
|
OutputProc("You are not authorized to use that command!");
|
|
return ExitCode.BadCommand;
|
|
}
|
|
if (!Info.IsAdminChannel)
|
|
{
|
|
OutputProc("Use this command in an admin channel!");
|
|
return ExitCode.BadCommand;
|
|
}
|
|
}
|
|
return base.DoRun(parameters);
|
|
}
|
|
}
|
|
}
|