Split the service and server functions

This commit is contained in:
Cyberboss
2017-11-12 23:48:54 -05:00
parent 6e54f622de
commit 1372f2daea
55 changed files with 1112 additions and 1129 deletions
+45
View File
@@ -0,0 +1,45 @@
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 ServerInstance 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);
}
}
}