using Microsoft.AspNetCore.Mvc; using RadicadeServer.DB; using RadicadeServer.Extensions; using RadicadeServer.RecNet; using RadicadeServer.Utils; namespace RadicadeServer.CDN.Config { [Route("cdn/config")] public class CDNConfigAPI : Controller { RecDBContext db; public CDNConfigAPI(RecDBContext context) { this.db = context; } [HttpGet("LoadingScreenTipData")] public List GetLoadingScreenTipData() { var official = LoadingScreenImages.Tips; var officialNames = new HashSet(LoadingScreenImages.Names, StringComparer.OrdinalIgnoreCase); var loadingScreens = db.ServerConfig.FirstOrDefault(x => x.Key == "LoadingScreenTipData"); var stored = string.IsNullOrWhiteSpace(loadingScreens?.Value) || loadingScreens.Value == "[]" ? new List() : loadingScreens.Value.FromJson>() ?? new List(); var byImage = new Dictionary(StringComparer.OrdinalIgnoreCase); foreach (var tip in stored) { if (!string.IsNullOrWhiteSpace(tip.ImageName)) byImage.TryAdd(tip.ImageName, tip); } var adopted = stored.FirstOrDefault(tip => !officialNames.Contains(tip.ImageName ?? string.Empty) && !(tip.Title == "radicade" && tip.Message == "yum")); var tips = new List(official.Count); for (var i = 0; i < official.Count; i++) { var image = official[i].ImageName; var text = byImage.TryGetValue(image, out var storedTip) ? storedTip : i == 0 && adopted != null ? adopted : official[i]; tips.Add(new LoadingScreenTip { ImageName = image, Title = string.IsNullOrWhiteSpace(text.Title) ? official[i].Title : text.Title, Message = string.IsNullOrWhiteSpace(text.Message) ? official[i].Message : text.Message, RoomNames = text.RoomNames ?? new List(), PlatformMask = text.PlatformMask }); } return tips; } } }