XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEWarframe

【WinUI】基于Warframe游戏本体的公开服务器以及安装器

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Collections.Concurrent;
using Newtonsoft.Json.Linq;
using XFEWarframe.Core.Data;

namespace XFEWarframe.Core.Services;

public static class WorldData
{
    public const long Epoch = 1734307200000, Day = 86400000, Week = 604800000, Hour = 3600000;
    private static readonly ConcurrentDictionary<string, Lazy<JToken>> Cache = new(StringComparer.Ordinal);
    // Cached tokens are read-only. Always clone before handing a token to a mutating caller.
    public static JToken Get(string name) => Cache.GetOrAdd(name, key => new(() => Assets.Json("world/" + key + ".json"))).Value;
    public static JToken Fixed(string name) => Cache.GetOrAdd("fixed/" + name, _ => new(() => Assets.Json("fixed_responses/worldState/" + name + ".json"))).Value;
    public static string[] Strings(JToken token) => token.Select(x => x.ToString()).ToArray();
    public static string Id(long start, string suffix) => unchecked((uint)(start / 1000)).ToString("x8") + suffix;
    public static int WeekOf(long now) => (int)((now - Epoch) / Week);
    public static int DayOf(long now) => (int)((now - Epoch) / Day);
    public static long SortieTime(int day)
    {
        var start = Epoch + day * Day;
        return start + (TimeZoneInfo.FindSystemTimeZoneById("America/Toronto").IsDaylightSavingTime(DateTimeOffset.FromUnixTimeMilliseconds(start + 12 * Hour)) ? 16 : 17) * Hour;
    }
    public static JObject Window(long start, long end, string? id = null, long? build = null)
    {
        var result = new JObject { ["Activation"] = build is long b ? GameVersion.Date(start, b) : Wire.Date(start), ["Expiry"] = build is long v ? GameVersion.Date(end, v) : Wire.Date(end) };
        if (id is not null) result["_id"] = build is long bv ? GameVersion.Oid(id, bv) : Wire.Oid(id);
        return result;
    }
}