Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions Torch.Server/Managers/ConsoleCommandManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Torch.API;
using Torch.API.Managers;
using Torch.Commands;
using Torch.Managers;

namespace Torch.Server.Managers
{
internal class ConsoleCommandManager : Manager
{
private static readonly ILogger Log = LogManager.GetCurrentClassLogger();

[Dependency]
private readonly CommandManager _commandManager;

public ConsoleCommandManager(ITorchBase torchInstance) : base(torchInstance)
{
}

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);
}
}
}
3 changes: 2 additions & 1 deletion Torch.Server/Torch.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
<Compile Include="Commands\WhitelistCommands.cs" />
<Compile Include="FlowDocumentTarget.cs" />
<Compile Include="ListBoxExtensions.cs" />
<Compile Include="Managers\ConsoleCommandManager.cs" />
<Compile Include="Managers\EntityControlManager.cs" />
<Compile Include="Managers\GameUpdateManager.cs" />
<Compile Include="Managers\MultiplayerManagerDedicated.cs" />
Expand Down Expand Up @@ -538,4 +539,4 @@
<PropertyGroup>
<PostBuildEvent>copy "$(SolutionDir)NLog.config" "$(TargetDir)" &amp; copy "$(SolutionDir)NLog-user.config" "$(TargetDir)"</PostBuildEvent>
</PropertyGroup>
</Project>
</Project>
1 change: 1 addition & 0 deletions Torch.Server/TorchServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public TorchServer(TorchConfig config) : base(config)

var sessionManager = Managers.GetManager<ITorchSessionManager>();
sessionManager.AddFactory(x => new MultiplayerManagerDedicated(this));
sessionManager.AddFactory(x => new ConsoleCommandManager(this));

// Needs to be done at some point after MyVRageWindows.Init
// where the debug listeners are registered
Expand Down