mirror of
https://github.com/CommonLoon102/NBloodServerSupervisor.git
synced 2025-01-03 16:42:40 +01:00
no need for nblood exe path
This commit is contained in:
parent
6b1351ab0d
commit
9f696fdd7f
@ -8,14 +8,11 @@ namespace Supervisor
|
|||||||
{
|
{
|
||||||
public static readonly State State = new State();
|
public static readonly State State = new State();
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main()
|
||||||
{
|
{
|
||||||
NBloodServerListener.StartListening();
|
NBloodServerListener.StartListening();
|
||||||
WebApiListener.StartListening();
|
WebApiListener.StartListening();
|
||||||
|
PublicServerManager.Start();
|
||||||
if (args.Length > 0)
|
|
||||||
PublicServerManager.Start(args[0]);
|
|
||||||
|
|
||||||
PrivateServerManager.Start();
|
PrivateServerManager.Start();
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
using Common;
|
using Common;
|
||||||
using Model;
|
using Model;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -12,7 +11,7 @@ namespace Supervisor
|
|||||||
{
|
{
|
||||||
class PublicServerManager
|
class PublicServerManager
|
||||||
{
|
{
|
||||||
public static void Start(string nbloodPath)
|
public static void Start()
|
||||||
{
|
{
|
||||||
Thread.Sleep(TimeSpan.FromSeconds(2));
|
Thread.Sleep(TimeSpan.FromSeconds(2));
|
||||||
KillOrphanedServers();
|
KillOrphanedServers();
|
||||||
@ -20,7 +19,7 @@ namespace Supervisor
|
|||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
LaunchNewServersWhenNeeded(nbloodPath);
|
LaunchNewServersWhenNeeded();
|
||||||
Thread.Sleep(TimeSpan.FromSeconds(1));
|
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;
|
const int maxPlayers = 8;
|
||||||
|
|
||||||
@ -46,7 +45,11 @@ namespace Supervisor
|
|||||||
if (IsNewServerNeeded(i))
|
if (IsNewServerNeeded(i))
|
||||||
{
|
{
|
||||||
int port = PortUtils.GetPort();
|
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()
|
Program.State.Servers.AddOrUpdate(port, new Server()
|
||||||
{
|
{
|
||||||
Port = port,
|
Port = port,
|
||||||
|
@ -1,17 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace WebInterface
|
namespace WebInterface
|
||||||
{
|
{
|
||||||
@ -25,16 +20,13 @@ namespace WebInterface
|
|||||||
|
|
||||||
private void StartSupervisor()
|
private void StartSupervisor()
|
||||||
{
|
{
|
||||||
string nbloodPath = Configuration.GetValue<string>("NBloodPath");
|
|
||||||
bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||||
string supervisor = "Supervisor";
|
string supervisor = "Supervisor";
|
||||||
if (isWindows)
|
if (isWindows)
|
||||||
supervisor += ".exe";
|
supervisor += ".exe";
|
||||||
if (!File.Exists(nbloodPath))
|
|
||||||
throw new Exception($"Couldn't find nblood_server at {nbloodPath}");
|
|
||||||
if (!File.Exists(supervisor))
|
if (!File.Exists(supervisor))
|
||||||
throw new Exception($"Couldn't find {supervisor} in {Directory.GetCurrentDirectory()}");
|
throw new Exception($"Couldn't find {supervisor} in {Directory.GetCurrentDirectory()}");
|
||||||
Process.Start(supervisor, nbloodPath);
|
Process.Start(supervisor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IConfiguration Configuration { get; }
|
public IConfiguration Configuration { get; }
|
||||||
|
@ -8,6 +8,5 @@
|
|||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"MaximumServers": 20,
|
"MaximumServers": 20,
|
||||||
"NBloodPath": "\\path\\to\\nblood_server",
|
"ApiKey": "CHANGEME"
|
||||||
"ApiKey": "!!! CHANGE ME !!!"
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user