From 9f696fdd7f4a1c2a28fd0cf121587c2095599b56 Mon Sep 17 00:00:00 2001 From: CommonLoon102 Date: Fri, 24 Jan 2020 12:23:40 +0100 Subject: [PATCH] no need for nblood exe path --- Supervisor/Program.cs | 7 ++----- Supervisor/PublicServerManager.cs | 15 +++++++++------ WebInterface/Startup.cs | 10 +--------- WebInterface/appsettings.json | 3 +-- 4 files changed, 13 insertions(+), 22 deletions(-) diff --git a/Supervisor/Program.cs b/Supervisor/Program.cs index 79b8b17..27acac4 100644 --- a/Supervisor/Program.cs +++ b/Supervisor/Program.cs @@ -8,14 +8,11 @@ namespace Supervisor { public static readonly State State = new State(); - public static void Main(string[] args) + public static void Main() { NBloodServerListener.StartListening(); WebApiListener.StartListening(); - - if (args.Length > 0) - PublicServerManager.Start(args[0]); - + PublicServerManager.Start(); PrivateServerManager.Start(); while (true) diff --git a/Supervisor/PublicServerManager.cs b/Supervisor/PublicServerManager.cs index f4ab4b5..7f93ec9 100644 --- a/Supervisor/PublicServerManager.cs +++ b/Supervisor/PublicServerManager.cs @@ -1,10 +1,9 @@ using Common; using Model; using System; -using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Text; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; @@ -12,7 +11,7 @@ namespace Supervisor { class PublicServerManager { - public static void Start(string nbloodPath) + public static void Start() { Thread.Sleep(TimeSpan.FromSeconds(2)); KillOrphanedServers(); @@ -20,7 +19,7 @@ namespace Supervisor { while (true) { - LaunchNewServersWhenNeeded(nbloodPath); + LaunchNewServersWhenNeeded(); Thread.Sleep(TimeSpan.FromSeconds(1)); } }); @@ -37,7 +36,7 @@ namespace Supervisor } } - private static void LaunchNewServersWhenNeeded(string nbloodPath) + private static void LaunchNewServersWhenNeeded() { const int maxPlayers = 8; @@ -46,7 +45,11 @@ namespace Supervisor if (IsNewServerNeeded(i)) { int port = PortUtils.GetPort(); - var process = Process.Start(nbloodPath, $"-server {i} -port {port}"); + string nbloodServer = "nblood_server"; + bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + if (isWindows) + nbloodServer += ".exe"; + var process = Process.Start(nbloodServer, $"-server {i} -port {port}"); Program.State.Servers.AddOrUpdate(port, new Server() { Port = port, diff --git a/WebInterface/Startup.cs b/WebInterface/Startup.cs index a1898e2..480dbf9 100644 --- a/WebInterface/Startup.cs +++ b/WebInterface/Startup.cs @@ -1,17 +1,12 @@ using System; -using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Linq; using System.Runtime.InteropServices; -using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; namespace WebInterface { @@ -25,16 +20,13 @@ namespace WebInterface private void StartSupervisor() { - string nbloodPath = Configuration.GetValue("NBloodPath"); bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); string supervisor = "Supervisor"; if (isWindows) supervisor += ".exe"; - if (!File.Exists(nbloodPath)) - throw new Exception($"Couldn't find nblood_server at {nbloodPath}"); if (!File.Exists(supervisor)) throw new Exception($"Couldn't find {supervisor} in {Directory.GetCurrentDirectory()}"); - Process.Start(supervisor, nbloodPath); + Process.Start(supervisor); } public IConfiguration Configuration { get; } diff --git a/WebInterface/appsettings.json b/WebInterface/appsettings.json index eb4345b..e10280b 100644 --- a/WebInterface/appsettings.json +++ b/WebInterface/appsettings.json @@ -8,6 +8,5 @@ }, "AllowedHosts": "*", "MaximumServers": 20, - "NBloodPath": "\\path\\to\\nblood_server", - "ApiKey": "!!! CHANGE ME !!!" + "ApiKey": "CHANGEME" }