55 lines
1.3 KiB
C#
55 lines
1.3 KiB
C#
using NLog;
|
|
using System;
|
|
using System.Threading;
|
|
using Torch.API;
|
|
using Torch.API.Managers;
|
|
using Torch.Commands;
|
|
using Torch.Managers;
|
|
|
|
namespace Torch.Server.Managers
|
|
{
|
|
internal class ConsoleCommandManager(ITorchBase torchInstance) : Manager(torchInstance)
|
|
{
|
|
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
[Dependency]
|
|
private CommandManager _commandManager;
|
|
|
|
public override void Attach()
|
|
{
|
|
if (!Torch.Config.NoGui)
|
|
return;
|
|
|
|
Log.Info("Starting console command listener");
|
|
|
|
new Thread(CommandListener)
|
|
{
|
|
Name = "Console Command Listener",
|
|
IsBackground = true,
|
|
}.Start();
|
|
}
|
|
|
|
private void CommandListener()
|
|
{
|
|
while (Torch.GameState < TorchGameState.Unloading)
|
|
{
|
|
var line = Console.ReadLine();
|
|
|
|
if (line == null)
|
|
break;
|
|
|
|
Torch.Invoke(() =>
|
|
{
|
|
if (!_commandManager.HandleCommandFromServer(line, LogResponse))
|
|
Log.Error("Invalid input '{0}'", line);
|
|
});
|
|
}
|
|
}
|
|
|
|
private void LogResponse(TorchChatMessage message)
|
|
{
|
|
Log.Info(message.Message);
|
|
}
|
|
}
|
|
}
|