diff --git a/Libraries/SPTarkov.Server.Core/Helpers/HttpServerHelper.cs b/Libraries/SPTarkov.Server.Core/Helpers/HttpServerHelper.cs index 0efbf267..a6316c5c 100644 --- a/Libraries/SPTarkov.Server.Core/Helpers/HttpServerHelper.cs +++ b/Libraries/SPTarkov.Server.Core/Helpers/HttpServerHelper.cs @@ -58,30 +58,6 @@ public class HttpServerHelper(ConfigServer configServer) return $"wss://{BuildUrl()}"; } - /// - /// Method to determine if another version of the server is already running - /// - /// bool isAlreadyRunning - public bool IsAlreadyRunning() - { - TcpListener? listener = null; - - try - { - listener = new(IPAddress.Parse(_httpConfig.Ip), _httpConfig.Port); - listener.Start(); - return false; - } - catch (Exception) - { - return true; - } - finally - { - listener?.Stop(); - } - } - public void SendTextJson(HttpResponse resp, object output) { resp.Headers.Append("Content-Type", mime["json"]); diff --git a/Libraries/SPTarkov.Server.Core/Utils/App.cs b/Libraries/SPTarkov.Server.Core/Utils/App.cs index 2ebc205c..c7e05a20 100644 --- a/Libraries/SPTarkov.Server.Core/Utils/App.cs +++ b/Libraries/SPTarkov.Server.Core/Utils/App.cs @@ -35,13 +35,6 @@ public class App( { ServiceLocator.SetServiceProvider(_serviceProvider); - var isAlreadyRunning = _httpServerHelper.IsAlreadyRunning(); - if (isAlreadyRunning) - { - _logger.Critical(_serverLocalisationService.GetText("webserver_already_running")); - await Task.Delay(Timeout.Infinite); - } - if (_logger.IsLogEnabled(LogLevel.Debug)) { _logger.Debug( diff --git a/SPTarkov.Server/Program.cs b/SPTarkov.Server/Program.cs index e8482b78..52ef8479 100644 --- a/SPTarkov.Server/Program.cs +++ b/SPTarkov.Server/Program.cs @@ -1,5 +1,5 @@ using System.Net; -using System.Runtime; +using System.Net.Sockets; using System.Runtime.InteropServices; using System.Security.Authentication; using System.Text; @@ -126,6 +126,20 @@ public static class Program var httpConfig = options .ApplicationServices.GetService() ?.GetConfig()!; + + // Probe the http ip and port to see if its being used, this method will throw an exception and crash + // the server if the IP/Port combination is already in use + TcpListener? listener = null; + try + { + listener = new TcpListener(IPAddress.Parse(httpConfig.Ip), httpConfig.Port); + listener.Start(); + } + finally + { + listener?.Stop(); + } + var certHelper = options.ApplicationServices.GetService()!; options.Listen( IPAddress.Parse(httpConfig.Ip),