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

XFEWarframe

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

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Globalization;
using System.Text.RegularExpressions;
using Newtonsoft.Json.Linq;

namespace XFEWarframe.Core.Data;

public static partial class GameVersion
{
    public const long August2026 = 202608191106;
    private static readonly Lazy<JObject> Versions = new(() => (JObject)Assets.Json("world/gameToBuildVersion.json"));
    public static long Parse(string? label)
    {
        var match = BuildPattern().Match(label ?? "2026.05.13.13.07");
        if (!match.Success) throw new ApiException(400, "Invalid build label");
        return long.Parse(string.Concat(match.Groups.Cast<Group>().Skip(1).Select(x => x.Value)), CultureInfo.InvariantCulture);
    }
    public static long Of(string gameVersion) => Parse(Versions.Value.Value<string>(gameVersion) ?? throw new ArgumentException("Unknown game version"));
    public static long For(JObject account) => Parse(account.Value<string>("BuildLabel"));
    public static JObject Oid(string id, long build) => new() { [build <= Of("19.5.3") ? "$id" : "$oid"] = id };
    public static JObject Date(long ms, long build) => build <= Of("19.5.3") ? new JObject { ["sec"] = ms / 1000, ["usec"] = ms % 1000 * 1000 } : Wire.Date(ms);
    public static bool RegionAvailable(string id, JObject region, long build) => (id != "SolNode307" || build >= Of("32.2.0")) && (id != "SolNode308" || build >= Of("25.7.0")) && (region.Value<int>("systemIndex") != 18 || build >= Of("19.0.1"));
    [GeneratedRegex(@"^(\d{4})\.(\d{2})\.(\d{2})\.(\d{2})\.(\d{2})", RegexOptions.CultureInvariant)] private static partial Regex BuildPattern();
}