feat: overhaul Web with new arbiter code
This commit is contained in:
parent
1e0648a005
commit
9e4cb6bfce
|
|
@ -111,7 +111,7 @@ public class Bootstrapper : Interfaces.IBootstrapper
|
|||
}
|
||||
}
|
||||
|
||||
var clientRelease = await Http.GetJson<ClientRelease>(Web.Url($"/api/setup/{Arguments["Version"]}"));
|
||||
var clientRelease = await Http.GetJson<ClientRelease>(Web.FormatUrl($"/api/setup/{Arguments["Version"]}"));
|
||||
bool clientUpToDate = true;
|
||||
bool createStudioShortcut = false;
|
||||
|
||||
|
|
@ -226,7 +226,7 @@ public class Bootstrapper : Interfaces.IBootstrapper
|
|||
StartInfo = new()
|
||||
{
|
||||
FileName = Path.Combine(Paths.Versions, Arguments["Version"], $"{Constants.PROJECT_NAME}.Player.exe"),
|
||||
Arguments = $"-a \"{Web.Url("/Login/Negotiate.ashx")}\" -t \"{Arguments["Ticket"]}\" -j \"{Arguments["JoinScript"]}\"",
|
||||
Arguments = $"-a \"{Web.FormatUrl("/Login/Negotiate.ashx")}\" -t \"{Arguments["Ticket"]}\" -j \"{Arguments["JoinScript"]}\"",
|
||||
UseShellExecute = true,
|
||||
}
|
||||
};
|
||||
|
|
@ -446,7 +446,7 @@ public class Bootstrapper : Interfaces.IBootstrapper
|
|||
}
|
||||
|
||||
// Load the license...
|
||||
while (!Web.LoadLicense(File.ReadAllText(Paths.License)))
|
||||
while (!Web.License(File.ReadAllText(Paths.License)))
|
||||
{
|
||||
// ...and if it's corrupt, keep asking for a new one.
|
||||
File.Delete(Paths.License);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
namespace Kiseki.Launcher.Enums;
|
||||
|
||||
public enum HealthCheckStatus
|
||||
{
|
||||
Failure,
|
||||
Maintenance,
|
||||
Success
|
||||
}
|
||||
|
|
@ -1,9 +1,7 @@
|
|||
namespace Kiseki.Launcher.Models;
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
public class HealthCheck
|
||||
{
|
||||
[JsonPropertyName("status")]
|
||||
public int Status { get; set; } = -1;
|
||||
public HealthCheckStatus Status { get; set; }
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
namespace Kiseki.Launcher.Models;
|
||||
|
||||
public readonly struct WebResponse
|
||||
{
|
||||
public WebResponse(int status, object? data)
|
||||
{
|
||||
Status = status;
|
||||
Data = data;
|
||||
}
|
||||
|
||||
public int Status { get; }
|
||||
public object? Data { get; }
|
||||
}
|
||||
|
|
@ -1,51 +1,33 @@
|
|||
namespace Kiseki.Launcher;
|
||||
|
||||
using System.Text.Json;
|
||||
|
||||
public static class Web
|
||||
{
|
||||
public const int RESPONSE_FAILURE = -1;
|
||||
public const int RESPONSE_SUCCESS = 0;
|
||||
public const int RESPONSE_MAINTENANCE = 1;
|
||||
|
||||
public static string CurrentUrl { get; private set; } = "";
|
||||
public static string? CurrentUrl { get; private set; } = null;
|
||||
public static bool IsConnected { get; private set; } = false;
|
||||
public static bool IsInMaintenance { get; private set; } = false;
|
||||
|
||||
public static readonly HttpClient HttpClient = new();
|
||||
|
||||
public static bool Initialize()
|
||||
public static async void Initialize()
|
||||
{
|
||||
CurrentUrl = IsInMaintenance ? $"{Constants.MAINTENANCE_DOMAIN}.{Constants.BASE_URL}" : Constants.BASE_URL;
|
||||
|
||||
// Synchronous block is intentional
|
||||
Task<Models.WebResponse> task = CheckHealth();
|
||||
task.Wait();
|
||||
|
||||
int response = task.Result.Status;
|
||||
|
||||
if (response != RESPONSE_SUCCESS)
|
||||
HealthCheckStatus status = await GetHealthStatus();
|
||||
if (status != HealthCheckStatus.Success)
|
||||
{
|
||||
if (response == RESPONSE_MAINTENANCE) IsInMaintenance = true;
|
||||
if (status == HealthCheckStatus.Maintenance)
|
||||
{
|
||||
IsInMaintenance = true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
return true;
|
||||
IsConnected = true;
|
||||
}
|
||||
|
||||
public static string Url(string path) => $"https://{CurrentUrl}{path}";
|
||||
|
||||
public static async Task<Models.WebResponse> CheckHealth()
|
||||
public static bool License(string license)
|
||||
{
|
||||
var response = await Utilities.Http.GetJson<Models.HealthCheck>(Url("/api/health"));
|
||||
|
||||
return new Models.WebResponse(response?.Status ?? RESPONSE_FAILURE, response);
|
||||
}
|
||||
|
||||
public static bool LoadLicense(string license)
|
||||
{
|
||||
// The license is just headers required to access the website in a JSON document
|
||||
|
||||
Dictionary<string, string> headers;
|
||||
|
||||
try
|
||||
|
|
@ -64,4 +46,23 @@ public static class Web
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static async Task<HealthCheckStatus> GetHealthStatus()
|
||||
{
|
||||
var response = await Http.GetJson<HealthCheck>(FormatUrl("/health-check"));
|
||||
|
||||
return response?.Status ?? HealthCheckStatus.Failure;
|
||||
}
|
||||
|
||||
public static string FormatUrl(string path, string? subdomain = null)
|
||||
{
|
||||
string scheme = "https";
|
||||
string url = subdomain == null ? CurrentUrl! : $"{subdomain!}.{CurrentUrl!}";
|
||||
|
||||
#if DEBUG
|
||||
scheme = "http";
|
||||
#endif
|
||||
|
||||
return $"{scheme}://{url}{path}";
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue