mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-26 07:29:00 -07:00
62 lines
1.9 KiB
C#
62 lines
1.9 KiB
C#
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<LoadingScreenTip> GetLoadingScreenTipData()
|
|
{
|
|
var official = LoadingScreenImages.Tips;
|
|
var officialNames = new HashSet<string>(LoadingScreenImages.Names, StringComparer.OrdinalIgnoreCase);
|
|
|
|
var loadingScreens = db.ServerConfig.FirstOrDefault(x => x.Key == "LoadingScreenTipData");
|
|
var stored = string.IsNullOrWhiteSpace(loadingScreens?.Value) || loadingScreens.Value == "[]"
|
|
? new List<LoadingScreenTip>()
|
|
: loadingScreens.Value.FromJson<List<LoadingScreenTip>>() ?? new List<LoadingScreenTip>();
|
|
|
|
var byImage = new Dictionary<string, LoadingScreenTip>(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<LoadingScreenTip>(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<string>(),
|
|
PlatformMask = text.PlatformMask
|
|
});
|
|
}
|
|
|
|
return tips;
|
|
}
|
|
}
|
|
}
|