feature: Add console command listener for nogui scenarios
This commit is contained in:
54
Torch.Server/Managers/ConsoleCommandManager.cs
Normal file
54
Torch.Server/Managers/ConsoleCommandManager.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -59,6 +59,7 @@ namespace Torch.Server
|
||||
|
||||
var sessionManager = Managers.GetManager<ITorchSessionManager>();
|
||||
sessionManager.AddFactory(_ => new MultiplayerManagerDedicated(this));
|
||||
sessionManager.AddFactory(_ => new ConsoleCommandManager(this));
|
||||
sessionManager.SessionStateChanged += OnSessionStateChanged;
|
||||
|
||||
// Needs to be done at some point after MyVRageWindows.Init
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using Torch.API;
|
||||
using Torch.API.Managers;
|
||||
|
||||
@@ -25,6 +26,7 @@ namespace Torch.Managers
|
||||
/// </code>
|
||||
/// </example>
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
[MeansImplicitUse(ImplicitUseKindFlags.Assign)]
|
||||
public class DependencyAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
|
Reference in New Issue
Block a user