From 173fc6b8a98fefc3aa96b3bfccd30231070a947c Mon Sep 17 00:00:00 2001 From: Chris Adamson Date: Wed, 28 May 2025 13:47:13 -0500 Subject: [PATCH 1/3] I saw a mudcrab the other day. Horrible creatures --- .../Helpers/HttpServerHelper.cs | 22 +++++++++++++++++++ Libraries/SPTarkov.Server.Core/Utils/App.cs | 13 ++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Libraries/SPTarkov.Server.Core/Helpers/HttpServerHelper.cs b/Libraries/SPTarkov.Server.Core/Helpers/HttpServerHelper.cs index a9f09294..ad844256 100644 --- a/Libraries/SPTarkov.Server.Core/Helpers/HttpServerHelper.cs +++ b/Libraries/SPTarkov.Server.Core/Helpers/HttpServerHelper.cs @@ -54,6 +54,28 @@ public class HttpServerHelper(ConfigServer configServer) return $"wss://{BuildUrl()}"; } + /// + /// Method to determine if another version of the server is already running + /// + /// bool isAlreadyRunning + public async Task IsAlreadyRunning() + { + try + { + var handler = new HttpClientHandler() + { + ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator + }; + var http = new HttpClient(handler); + var res = await http.PostAsync($"{GetBackendUrl()}/launcher/ping", null); + return res.IsSuccessStatusCode; + } + catch (Exception ) + { + return false; + } + } + 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 98195eac..31f8a49f 100644 --- a/Libraries/SPTarkov.Server.Core/Utils/App.cs +++ b/Libraries/SPTarkov.Server.Core/Utils/App.cs @@ -1,5 +1,6 @@ using SPTarkov.DI.Annotations; using SPTarkov.Server.Core.DI; +using SPTarkov.Server.Core.Helpers; using SPTarkov.Server.Core.Models.Spt.Config; using SPTarkov.Server.Core.Models.Utils; using SPTarkov.Server.Core.Servers; @@ -17,6 +18,7 @@ public class App protected DatabaseService _databaseService; protected EncodingUtil _encodingUtil; protected HttpServer _httpServer; + protected HttpServerHelper _httpServerHelper; protected LocalisationService _localisationService; protected ISptLogger _logger; @@ -36,7 +38,8 @@ public class App HttpServer httpServer, DatabaseService databaseService, IEnumerable onLoadComponents, - IEnumerable onUpdateComponents + IEnumerable onUpdateComponents, + HttpServerHelper httpServerHelper ) { _logger = logger; @@ -46,6 +49,7 @@ public class App _configServer = configServer; _encodingUtil = encodingUtil; _httpServer = httpServer; + _httpServerHelper = httpServerHelper; _databaseService = databaseService; _onLoad = onLoadComponents; _onUpdate = onUpdateComponents; @@ -58,6 +62,13 @@ public class App // execute onLoad callbacks _logger.Info(_localisationService.GetText("executing_startup_callbacks")); + var isAlreadyRunning = await _httpServerHelper.IsAlreadyRunning(); + if (isAlreadyRunning) + { + _logger.Critical(_localisationService.GetText("webserver_already_running")); + Environment.Exit(1); + } + if (_logger.IsLogEnabled(LogLevel.Debug)) { _logger.Debug($"OS: {Environment.OSVersion.Version} | {Environment.OSVersion.Platform}"); From 7d85c0af223cb36359980ddcd16fb6ffb169f522 Mon Sep 17 00:00:00 2001 From: Chris Adamson Date: Wed, 28 May 2025 14:29:57 -0500 Subject: [PATCH 2/3] added horse armor --- .../Assets/database/locales/server/en.json | 5 +++-- Libraries/SPTarkov.Server.Core/Utils/App.cs | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Libraries/SPTarkov.Server.Assets/Assets/database/locales/server/en.json b/Libraries/SPTarkov.Server.Assets/Assets/database/locales/server/en.json index cc92f3ba..33e408f1 100644 --- a/Libraries/SPTarkov.Server.Assets/Assets/database/locales/server/en.json +++ b/Libraries/SPTarkov.Server.Assets/Assets/database/locales/server/en.json @@ -730,5 +730,6 @@ "chatbot-forced_event_enabled": "%s event has been enabled, restart your game client before starting a raid", "chatbot-added_stash_rows_please_restart": "Added 2 rows to stash, please restart your game to see them", "chatbot-snow_enabled": "Snow is enabled for all subsequent raids until the server is restarted", - "chatbot-summer_enabled": "Summer has been enabled for all subsequent raids until the server is restarted" -} + "chatbot-summer_enabled": "Summer has been enabled for all subsequent raids until the server is restarted", + "webserver_already_running": "Another copy of the webserver is already running. Please shut it down before starting a new one." +} \ No newline at end of file diff --git a/Libraries/SPTarkov.Server.Core/Utils/App.cs b/Libraries/SPTarkov.Server.Core/Utils/App.cs index 31f8a49f..80eb55df 100644 --- a/Libraries/SPTarkov.Server.Core/Utils/App.cs +++ b/Libraries/SPTarkov.Server.Core/Utils/App.cs @@ -66,6 +66,7 @@ public class App if (isAlreadyRunning) { _logger.Critical(_localisationService.GetText("webserver_already_running")); + await Task.Delay(3600 * 60); Environment.Exit(1); } From ccd3498d2c083f8068558709419a8581af95af21 Mon Sep 17 00:00:00 2001 From: Chris Adamson Date: Wed, 28 May 2025 14:38:08 -0500 Subject: [PATCH 3/3] I used have spt dev role but then I took an arrow to the knee --- Libraries/SPTarkov.Server.Core/Utils/App.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Libraries/SPTarkov.Server.Core/Utils/App.cs b/Libraries/SPTarkov.Server.Core/Utils/App.cs index 80eb55df..f20e56cd 100644 --- a/Libraries/SPTarkov.Server.Core/Utils/App.cs +++ b/Libraries/SPTarkov.Server.Core/Utils/App.cs @@ -66,8 +66,7 @@ public class App if (isAlreadyRunning) { _logger.Critical(_localisationService.GetText("webserver_already_running")); - await Task.Delay(3600 * 60); - Environment.Exit(1); + await Task.Delay(Timeout.Infinite); } if (_logger.IsLogEnabled(LogLevel.Debug))