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

XFEWarframe

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

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

namespace XFEWarframe.Core.Services;

public static class InventoryArchive
{
    public static JObject Read(JObject state, JObject account) => new()
    {
        ["version"] = AccountEditor.Version(state, account), ["inventory"] = Inventory.Export(account)
    };

    public static JObject Import(StateStore store, JObject state, JObject account, JObject body, ItemCatalog catalog, TimeProvider clock, bool requireVersion)
    {
        if (requireVersion || body["version"] is not null)
            if (!Wire.SecretEquals(body.RequiredString("version", 64), AccountEditor.Version(state, account)))
                throw new ApiException(409, "存档已更新,请重新读取后检查导入内容。");
        var upload = body["inventory"] as JObject ?? throw new ApiException(400, "缺少库存对象。");
        if (upload.Count == 0) throw new ApiException(400, "导入文件没有可用字段。");
        var before = Inventory.Export(account);
        Inventory.Import(account, upload);
        if (account.Value<bool>("SkipTutorial")) TutorialProgress.Apply(account, catalog, clock);
        var backup = store.BackupInventory(account.RequiredString("id"), before);
        return new JObject { ["imported"] = true, ["backup"] = backup, ["version"] = AccountEditor.Version(state, account) };
    }
}