소스 검색

Only run webserver in game

tags/v1.0.0
NorbiPeti 2 년 전
부모
커밋
5b56d7fd43
3개의 변경된 파일21개의 추가작업 그리고 9개의 파일을 삭제
  1. +1
    -0
      TBConsole/TBConsole.csproj
  2. +16
    -5
      TBConsole/TBConsoleMod.cs
  3. +4
    -4
      TBConsole/WebServer.cs

+ 1
- 0
TBConsole/TBConsole.csproj 파일 보기

@@ -6,6 +6,7 @@
<OutputType>Exe</OutputType>
-->
<TargetFramework>netstandard2.0</TargetFramework>
<Authors>NorbiPeti</Authors>
</PropertyGroup>

<ItemGroup>


+ 16
- 5
TBConsole/TBConsoleMod.cs 파일 보기

@@ -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();
}



+ 4
- 4
TBConsole/WebServer.cs 파일 보기

@@ -7,7 +7,7 @@ namespace TBConsole
{
public class WebServer
{
private bool _running;
public bool Running { get; private set; }
private readonly HttpListener _listener = new HttpListener();
private readonly Func<string, string> _commandReceiver;
private readonly Func<string> _commandsListSender;
@@ -20,13 +20,13 @@ namespace TBConsole

public void Start()
{
_running = true;
Running = true;
KeepListening();
}

public void Stop()
{
_running = false;
Running = false;
_listener.Stop();
}
@@ -34,7 +34,7 @@ namespace TBConsole
{
_listener.Prefixes.Add("http://localhost:8019/");
_listener.Start();
while (_running)
while (Running)
{
try
{


불러오는 중...
취소
저장