-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathConsoleCommandManager.cs
More file actions
62 lines (52 loc) · 1.52 KB
/
ConsoleCommandManager.cs
File metadata and controls
62 lines (52 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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);
}
}
}