|
|
@@ -4,7 +4,9 @@ using System.Linq; |
|
|
|
using System.Reflection; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using IllusionPlugin; |
|
|
|
using TechbloxModdingAPI.App; |
|
|
|
using TechbloxModdingAPI.Commands; |
|
|
|
using TechbloxModdingAPI.Utility; |
|
|
|
using UnityEngine; |
|
|
|
|
|
|
|
namespace TBConsole |
|
|
@@ -19,8 +21,19 @@ namespace TBConsole |
|
|
|
public override void OnApplicationStart() |
|
|
|
{ |
|
|
|
TechbloxModdingAPI.Main.Init(); |
|
|
|
_server = new WebServer(CommandReceived, GetCommandList); |
|
|
|
_server.Start(); |
|
|
|
Game.Enter += async (sender, e) => |
|
|
|
{ |
|
|
|
while (_server?.Running ?? false) |
|
|
|
{ |
|
|
|
Logging.LogWarning("A previous web server is still running"); |
|
|
|
_server?.Stop(); |
|
|
|
await Task.Delay(500); |
|
|
|
} |
|
|
|
|
|
|
|
_server = new WebServer(CommandReceived, GetCommandList); |
|
|
|
_server.Start(); |
|
|
|
}; |
|
|
|
Game.Exit += (sender, e) => _server?.Stop(); |
|
|
|
} |
|
|
|
|
|
|
|
private string CommandReceived(string command) |
|
|
@@ -42,8 +55,6 @@ namespace TBConsole |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//Console.WriteLine("Command parts: " + cmdparts.Aggregate((a, b) => a + ", " + b)); |
|
|
|
|
|
|
|
switch (cmdparts.Count) |
|
|
|
{ |
|
|
|
case 1: |
|
|
@@ -74,7 +85,7 @@ namespace TBConsole |
|
|
|
|
|
|
|
public override void OnApplicationQuit() |
|
|
|
{ |
|
|
|
_server.Stop(); |
|
|
|
_server?.Stop(); |
|
|
|
TechbloxModdingAPI.Main.Shutdown(); |
|
|
|
} |
|
|
|
|
|
|
|