From 2204f7bb0a595c258b34a26d67547c4b37b5d8be Mon Sep 17 00:00:00 2001 From: Zaprit Date: Mon, 26 May 2025 23:12:12 +0100 Subject: [PATCH] Implement refresh autodiscover --- .../Controllers/AutoDiscoverController.cs | 26 +++++++++++++++++++ .../Types/AutoDiscoverResponse.cs | 19 ++++++++++++++ .../CustomizationConfiguration.cs | 1 + .../Configuration/ServerConfiguration.cs | 2 +- 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 ProjectLighthouse.Servers.Website/Controllers/AutoDiscoverController.cs create mode 100644 ProjectLighthouse.Servers.Website/Types/AutoDiscoverResponse.cs diff --git a/ProjectLighthouse.Servers.Website/Controllers/AutoDiscoverController.cs b/ProjectLighthouse.Servers.Website/Controllers/AutoDiscoverController.cs new file mode 100644 index 00000000..6d90ec13 --- /dev/null +++ b/ProjectLighthouse.Servers.Website/Controllers/AutoDiscoverController.cs @@ -0,0 +1,26 @@ +using LBPUnion.ProjectLighthouse.Configuration; +using LBPUnion.ProjectLighthouse.Servers.Website.Types; +using Microsoft.AspNetCore.Mvc; + +namespace LBPUnion.ProjectLighthouse.Servers.Website.Controllers; + +[ApiController] +public class AutoDiscoverController: ControllerBase +{ + [ResponseCache(Duration = 86400)] + [HttpGet("/autodiscover")] + [Produces("application/json")] + public IActionResult AutoDiscover() + { + AutoDiscoverResponse resp = new() + { + Version = 3, + Url = ServerConfiguration.Instance.GameApiExternalUrl, + ServerBrand = ServerConfiguration.Instance.Customization.ServerName, + UsesCustomDigestKey = false, + BannerImageUrl = null, + ServerDescription = ServerConfiguration.Instance.Customization.ServerDescription, + }; + return this.Ok(resp); + } +} \ No newline at end of file diff --git a/ProjectLighthouse.Servers.Website/Types/AutoDiscoverResponse.cs b/ProjectLighthouse.Servers.Website/Types/AutoDiscoverResponse.cs new file mode 100644 index 00000000..c8a3f5fc --- /dev/null +++ b/ProjectLighthouse.Servers.Website/Types/AutoDiscoverResponse.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; + +namespace LBPUnion.ProjectLighthouse.Servers.Website.Types; + +public record AutoDiscoverResponse +{ + [JsonProperty("version")] + public uint Version { get; set; } + [JsonProperty("serverBrand")] + public string ServerBrand { get; set; } + [JsonProperty("serverDescription")] + public string ServerDescription { get; set; } + [JsonProperty("url")] + public string Url { get; set; } + [JsonProperty("bannerImageUrl")] + public string? BannerImageUrl { get; set; } + [JsonProperty("usesCustomDigestKey")] + public bool UsesCustomDigestKey { get; set; } +} diff --git a/ProjectLighthouse/Configuration/ConfigurationCategories/CustomizationConfiguration.cs b/ProjectLighthouse/Configuration/ConfigurationCategories/CustomizationConfiguration.cs index ee6b17e4..3d026f51 100644 --- a/ProjectLighthouse/Configuration/ConfigurationCategories/CustomizationConfiguration.cs +++ b/ProjectLighthouse/Configuration/ConfigurationCategories/CustomizationConfiguration.cs @@ -4,4 +4,5 @@ public class CustomizationConfiguration { public string ServerName { get; set; } = "Project Lighthouse"; public string EnvironmentName { get; set; } = "project-lighthouse"; + public string ServerDescription { get; set; } = "A Project Lighthouse Server"; } \ No newline at end of file diff --git a/ProjectLighthouse/Configuration/ServerConfiguration.cs b/ProjectLighthouse/Configuration/ServerConfiguration.cs index ba9f7f4a..30e0a74f 100644 --- a/ProjectLighthouse/Configuration/ServerConfiguration.cs +++ b/ProjectLighthouse/Configuration/ServerConfiguration.cs @@ -11,7 +11,7 @@ public class ServerConfiguration : ConfigurationBase // This is so Lighthouse can properly identify outdated configurations and update them with newer settings accordingly. // If you are modifying anything here, this value MUST be incremented. // Thanks for listening~ - public override int ConfigVersion { get; set; } = 27; + public override int ConfigVersion { get; set; } = 28; public override string ConfigName { get; set; } = "lighthouse.yml"; public string WebsiteListenUrl { get; set; } = "http://localhost:10060";