I saw a mudcrab the other day. Horrible creatures
This commit is contained in:
@@ -54,6 +54,28 @@ public class HttpServerHelper(ConfigServer configServer)
|
||||
return $"wss://{BuildUrl()}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method to determine if another version of the server is already running
|
||||
/// </summary>
|
||||
/// <returns>bool isAlreadyRunning</returns>
|
||||
public async Task<bool> 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"]);
|
||||
|
||||
@@ -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<App> _logger;
|
||||
@@ -36,7 +38,8 @@ public class App
|
||||
HttpServer httpServer,
|
||||
DatabaseService databaseService,
|
||||
IEnumerable<IOnLoad> onLoadComponents,
|
||||
IEnumerable<IOnUpdate> onUpdateComponents
|
||||
IEnumerable<IOnUpdate> 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}");
|
||||
|
||||
Reference in New Issue
Block a user