using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using Newtonsoft.Json.Linq;
using XFEWarframe.Core.Data;
namespace XFEWarframe.Core.Services;
public sealed partial class CustomApi
{
private JObject ItemLists(string language)
{
if (!PublicExportApi.Languages.Contains(language)) language = "en";
var dict = (JObject)Assets.Json("export/dict." + language + ".json"); var result = new JObject();
foreach (var category in Inventory.EquipmentKeys.Concat(["ModularParts", "miscitems", "Syndicates", "QuestKeys", "mods", "Boosters", "VarziaOffers", "Abilities", "TechProjects", "VaultDecoRecipes", "FlavourItems", "ShipDecorations", "WeaponSkins", "MissionTypes", "Nodes", "NightwaveTags", "AdditionalDict"])) result[category] = new JArray();
var eligibleVault = new HashSet<string>(); foreach (var group in new[] { "research", "fabrications", "rooms", "decos" }) foreach (var recipe in ((JObject?)GameData.Table("DojoRecipes")[group] ?? new()).Properties()) foreach (var item in recipe.Value["ingredients"] as JArray ?? []) eligibleVault.Add(item.Value<string>("ItemType")!);
string Name(string key) => dict.Value<string>(key) ?? key.Split('/').Last();
var evolution = WorldData.Get("evolutionWeapons").Values<string>().ToHashSet(); var permanent = WorldData.Get("permanentEvolutionWeapons").Values<string>().ToHashSet();
var metadata = catalog.Entries.ToDictionary(x => x.Type, x => x.Meta, StringComparer.Ordinal);
foreach (var (type, category, meta) in catalog.Entries)
{
if (category is "SpecialItems" or "CreditBundles" or "FusionBundles" or "Bundles" or "EmailItems" or "BoosterPacks" || meta.Value<string>("productCategory") == "SupplyDrop") continue;
var target = category switch { "RawUpgrades" => "mods", "Recipes" or "MiscItems" or "Consumables" or "FusionTreasures" or "CrewShipRawSalvage" => "miscitems", "LevelKeys" => meta["chainStages"] is JArray ? "QuestKeys" : "miscitems", _ => category };
var listed = new JObject { ["uniqueName"] = category == "Boosters" ? meta.Value<string>("typeName") ?? type : type, ["name"] = Name(meta.Value<string>("name") ?? type) };
foreach (var property in new[] { "fusionLimit", "exalted", "partType", "alwaysAvailable", "maxLevelCap", "parentName" }) if (meta[property] is JToken value) listed[property] = value.DeepClone();
if (category == "Recipes" && meta.Value<string>("resultType") is string product)
{
var productName = metadata.GetValueOrDefault(product)?.Value<string>("name"); if (productName is not null) listed["name"] = Name(productName) + " " + Name("/Lotus/Language/Items/Blueprint");
}
if (eligibleVault.Contains(type)) listed["eligibleForVault"] = true;
if (meta["chainStages"] is JArray stages) listed["chainLength"] = stages.Count;
if (meta.Value<string>("type") == "PARAZON") listed["parazon"] = true;
if (meta.Value<bool>("isStarter")) listed["badReason"] = "starter"; else if (meta.Value<bool>("isFrivolous")) listed["badReason"] = "frivolous"; else if (meta["upgradeEntries"] is not null || meta["bayonetOtherWeaponType"] is not null && meta.Value<bool>("excludeFromMarket")) listed["badReason"] = "notraw";
if (evolution.Contains(type) || evolution.Contains(meta.Value<string>("parentName"))) listed["evolutionWeapon"] = true; if (evolution.Contains(type)) listed["baseEvolutionWeapon"] = true; if (permanent.Contains(type)) listed["permanentEvolutionWeapon"] = true;
result.Array(target).Add(listed); if (meta["partType"] is not null) result.Array("ModularParts").Add(listed.DeepClone());
}
foreach (var (table, category) in new[] { ("Syndicates", "Syndicates"), ("Abilities", "Abilities"), ("MissionTypes", "MissionTypes"), ("Regions", "Nodes") }) foreach (var entry in GameData.Table(table).Properties()) result.Array(category).Add(new JObject { ["uniqueName"] = entry.Name, ["name"] = Name(entry.Value.Value<string>("name") ?? entry.Name) });
foreach (var suit in GameData.Table("Warframes").Properties()) foreach (var ability in (suit.Value["abilities"] as JArray ?? []).OfType<JObject>()) if (!result.Array("Abilities").Any(x => x.Value<string>("uniqueName") == ability.Value<string>("uniqueName"))) result.Array("Abilities").Add(new JObject { ["uniqueName"] = ability["uniqueName"]!.DeepClone(), ["name"] = Name(ability.Value<string>("name") ?? ability.RequiredString("uniqueName")) });
foreach (var recipe in ((JObject)GameData.Table("DojoRecipes")["research"]!).Properties()) result.Array("TechProjects").Add(new JObject { ["uniqueName"] = recipe.Name, ["name"] = Name(recipe.Value.Value<string>("name") ?? recipe.Name) });
foreach (var recipe in ((JObject)GameData.Table("DojoRecipes")["decos"]!).Properties().Where(x => x.Value.Value<bool>("requiredInVault"))) result.Array("VaultDecoRecipes").Add(new JObject { ["uniqueName"] = recipe.Name, ["name"] = Name(recipe.Value.Value<string>("name") ?? recipe.Name) });
foreach (var pack in ((JObject)WorldData.Get("varzia")["primeDualPacks"]!).Properties()) result.Array("VarziaOffers").Add(new JObject { ["uniqueName"] = pack.Name, ["name"] = Name(pack.Name) });
foreach (var tag in ((JObject)WorldData.Get("nightwaveTagToSeasonName")).Properties()) result.Array("NightwaveTags").Add(new JObject { ["uniqueName"] = tag.Name, ["name"] = Name(tag.Value.ToString()) });
result["blueprintAndItem"] = Name("/Lotus/Language/Items/BlueprintAndItem"); return result;
}
private JObject Tunables(JObject state)
{
var address = new Uri(options.PublicUrl).Host; var config = state.Obj("config"); var tunables = config["tunables"] as JObject ?? new();
var result = new JObject { ["nrs"] = (options.NrsAddresses.FirstOrDefault() ?? address).Replace("%THIS_MACHINE%", address, StringComparison.Ordinal) };
if (options.GetIrcAddresses().FirstOrDefault() is string irc) result["irc"] = irc;
foreach (var (setting, field) in new[] { ("prohibitSkipMissionStartTimer", "prohibit_skip_mission_start_timer"), ("prohibitDisableProfanityFilter", "prohibit_disable_profanity_filter"), ("prohibitFovOverride", "prohibit_fov_override"), ("prohibitFreecam", "prohibit_freecam"), ("prohibitTeleport", "prohibit_teleport"), ("prohibitScripts", "prohibit_scripts") }) if (tunables.Value<bool>(setting)) result[field] = true;
if (tunables.Value<string>("motd") is string motd) result["motd"] = motd; if (tunables.Value<string>("udpProxyUpstream") is string proxy) result["udp_proxy_upstream"] = proxy.Replace("%THIS_MACHINE%", address, StringComparison.Ordinal); return result;
}
private ApiResponse Config(JObject state, JObject account, ApiRequest request)
{
RequireAdmin(state, account, request); var getting = request.Path.EndsWith("/getConfig", StringComparison.Ordinal); var result = new JObject();
var updates = getting ? new JObject((JToken.Parse(request.Body) as JArray ?? throw new ApiException(400, "Expected setting IDs")).Select(x => new JProperty(x.ToString(), JValue.CreateNull()))) : request.ObjectBody();
if (updates.Count > 200) throw new ApiException(400, "Too many settings");
foreach (var property in updates.Properties())
{
var path = property.Name.Split('.'); if (path.Length > 5 || path.Any(x => !Regex.IsMatch(x, "^[A-Za-z][A-Za-z0-9_]{0,80}$")) || path.Any(x => x.Contains("password", StringComparison.OrdinalIgnoreCase) || x.Contains("secret", StringComparison.OrdinalIgnoreCase) || x.Contains("token", StringComparison.OrdinalIgnoreCase))) throw new ApiException(400, "Setting is not exposed through this API");
var root = path[0] == "worldState" ? state.Obj("worldState") : state.Obj("config"); var parts = path[0] == "worldState" ? path.Skip(1).ToArray() : path; if (parts.Length == 0) throw new ApiException(400, "Specify a setting name");
if (getting) { JToken? current = root; foreach (var part in parts) current = (current as JObject)?[part]; result[property.Name] = current?.DeepClone() ?? JValue.CreateNull(); continue; }
if (ServerSettingsEditor.Knows(property.Name)) { ServerSettingsEditor.Set(state, property.Name, property.Value, options); continue; }
if (path[0] is not ("worldState" or "tunables" or "administratorNames" or "autoCreateAccount")) throw new ApiException(400, "Edit server.json for this startup setting");
if (path[0] == "autoCreateAccount" && property.Value.Type != JTokenType.Boolean || path[0] == "administratorNames" && (property.Value is not JArray admins || admins.Any(x => x.Type != JTokenType.String))) throw new ApiException(400, "Invalid configuration value");
if (property.Name == "tunables.useLoginToken") throw new ApiException(400, "Login-token bootstrap authentication is not enabled in this host");
var target = root; foreach (var part in parts.SkipLast(1)) target = target.Obj(part); if (property.Value.Type == JTokenType.Null) target.Remove(parts[^1]); else target[parts[^1]] = property.Value.DeepClone();
}
return getting ? ApiResponse.Json(result) : ApiResponse.Text();
}
}
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using Newtonsoft.Json.Linq;
using XFEWarframe.Core.Data;
namespace XFEWarframe.Core.Services;
public sealed partial class CustomApi
{
private JObject ItemLists(string language)
{
if (!PublicExportApi.Languages.Contains(language)) language = "en";
var dict = (JObject)Assets.Json("export/dict." + language + ".json"); var result = new JObject();
foreach (var category in Inventory.EquipmentKeys.Concat(["ModularParts", "miscitems", "Syndicates", "QuestKeys", "mods", "Boosters", "VarziaOffers", "Abilities", "TechProjects", "VaultDecoRecipes", "FlavourItems", "ShipDecorations", "WeaponSkins", "MissionTypes", "Nodes", "NightwaveTags", "AdditionalDict"])) result[category] = new JArray();
var eligibleVault = new HashSet<string>(); foreach (var group in new[] { "research", "fabrications", "rooms", "decos" }) foreach (var recipe in ((JObject?)GameData.Table("DojoRecipes")[group] ?? new()).Properties()) foreach (var item in recipe.Value["ingredients"] as JArray ?? []) eligibleVault.Add(item.Value<string>("ItemType")!);
string Name(string key) => dict.Value<string>(key) ?? key.Split('/').Last();
var evolution = WorldData.Get("evolutionWeapons").Values<string>().ToHashSet(); var permanent = WorldData.Get("permanentEvolutionWeapons").Values<string>().ToHashSet();
var metadata = catalog.Entries.ToDictionary(x => x.Type, x => x.Meta, StringComparer.Ordinal);
foreach (var (type, category, meta) in catalog.Entries)
{
if (category is "SpecialItems" or "CreditBundles" or "FusionBundles" or "Bundles" or "EmailItems" or "BoosterPacks" || meta.Value<string>("productCategory") == "SupplyDrop") continue;
var target = category switch { "RawUpgrades" => "mods", "Recipes" or "MiscItems" or "Consumables" or "FusionTreasures" or "CrewShipRawSalvage" => "miscitems", "LevelKeys" => meta["chainStages"] is JArray ? "QuestKeys" : "miscitems", _ => category };
var listed = new JObject { ["uniqueName"] = category == "Boosters" ? meta.Value<string>("typeName") ?? type : type, ["name"] = Name(meta.Value<string>("name") ?? type) };
foreach (var property in new[] { "fusionLimit", "exalted", "partType", "alwaysAvailable", "maxLevelCap", "parentName" }) if (meta[property] is JToken value) listed[property] = value.DeepClone();
if (category == "Recipes" && meta.Value<string>("resultType") is string product)
{
var productName = metadata.GetValueOrDefault(product)?.Value<string>("name"); if (productName is not null) listed["name"] = Name(productName) + " " + Name("/Lotus/Language/Items/Blueprint");
}
if (eligibleVault.Contains(type)) listed["eligibleForVault"] = true;
if (meta["chainStages"] is JArray stages) listed["chainLength"] = stages.Count;
if (meta.Value<string>("type") == "PARAZON") listed["parazon"] = true;
if (meta.Value<bool>("isStarter")) listed["badReason"] = "starter"; else if (meta.Value<bool>("isFrivolous")) listed["badReason"] = "frivolous"; else if (meta["upgradeEntries"] is not null || meta["bayonetOtherWeaponType"] is not null && meta.Value<bool>("excludeFromMarket")) listed["badReason"] = "notraw";
if (evolution.Contains(type) || evolution.Contains(meta.Value<string>("parentName"))) listed["evolutionWeapon"] = true; if (evolution.Contains(type)) listed["baseEvolutionWeapon"] = true; if (permanent.Contains(type)) listed["permanentEvolutionWeapon"] = true;
result.Array(target).Add(listed); if (meta["partType"] is not null) result.Array("ModularParts").Add(listed.DeepClone());
}
foreach (var (table, category) in new[] { ("Syndicates", "Syndicates"), ("Abilities", "Abilities"), ("MissionTypes", "MissionTypes"), ("Regions", "Nodes") }) foreach (var entry in GameData.Table(table).Properties()) result.Array(category).Add(new JObject { ["uniqueName"] = entry.Name, ["name"] = Name(entry.Value.Value<string>("name") ?? entry.Name) });
foreach (var suit in GameData.Table("Warframes").Properties()) foreach (var ability in (suit.Value["abilities"] as JArray ?? []).OfType<JObject>()) if (!result.Array("Abilities").Any(x => x.Value<string>("uniqueName") == ability.Value<string>("uniqueName"))) result.Array("Abilities").Add(new JObject { ["uniqueName"] = ability["uniqueName"]!.DeepClone(), ["name"] = Name(ability.Value<string>("name") ?? ability.RequiredString("uniqueName")) });
foreach (var recipe in ((JObject)GameData.Table("DojoRecipes")["research"]!).Properties()) result.Array("TechProjects").Add(new JObject { ["uniqueName"] = recipe.Name, ["name"] = Name(recipe.Value.Value<string>("name") ?? recipe.Name) });
foreach (var recipe in ((JObject)GameData.Table("DojoRecipes")["decos"]!).Properties().Where(x => x.Value.Value<bool>("requiredInVault"))) result.Array("VaultDecoRecipes").Add(new JObject { ["uniqueName"] = recipe.Name, ["name"] = Name(recipe.Value.Value<string>("name") ?? recipe.Name) });
foreach (var pack in ((JObject)WorldData.Get("varzia")["primeDualPacks"]!).Properties()) result.Array("VarziaOffers").Add(new JObject { ["uniqueName"] = pack.Name, ["name"] = Name(pack.Name) });
foreach (var tag in ((JObject)WorldData.Get("nightwaveTagToSeasonName")).Properties()) result.Array("NightwaveTags").Add(new JObject { ["uniqueName"] = tag.Name, ["name"] = Name(tag.Value.ToString()) });
result["blueprintAndItem"] = Name("/Lotus/Language/Items/BlueprintAndItem"); return result;
}
private JObject Tunables(JObject state)
{
var address = new Uri(options.PublicUrl).Host; var config = state.Obj("config"); var tunables = config["tunables"] as JObject ?? new();
var result = new JObject { ["nrs"] = (options.NrsAddresses.FirstOrDefault() ?? address).Replace("%THIS_MACHINE%", address, StringComparison.Ordinal) };
if (options.GetIrcAddresses().FirstOrDefault() is string irc) result["irc"] = irc;
foreach (var (setting, field) in new[] { ("prohibitSkipMissionStartTimer", "prohibit_skip_mission_start_timer"), ("prohibitDisableProfanityFilter", "prohibit_disable_profanity_filter"), ("prohibitFovOverride", "prohibit_fov_override"), ("prohibitFreecam", "prohibit_freecam"), ("prohibitTeleport", "prohibit_teleport"), ("prohibitScripts", "prohibit_scripts") }) if (tunables.Value<bool>(setting)) result[field] = true;
if (tunables.Value<string>("motd") is string motd) result["motd"] = motd; if (tunables.Value<string>("udpProxyUpstream") is string proxy) result["udp_proxy_upstream"] = proxy.Replace("%THIS_MACHINE%", address, StringComparison.Ordinal); return result;
}
private ApiResponse Config(JObject state, JObject account, ApiRequest request)
{
RequireAdmin(state, account, request); var getting = request.Path.EndsWith("/getConfig", StringComparison.Ordinal); var result = new JObject();
var updates = getting ? new JObject((JToken.Parse(request.Body) as JArray ?? throw new ApiException(400, "Expected setting IDs")).Select(x => new JProperty(x.ToString(), JValue.CreateNull()))) : request.ObjectBody();
if (updates.Count > 200) throw new ApiException(400, "Too many settings");
foreach (var property in updates.Properties())
{
var path = property.Name.Split('.'); if (path.Length > 5 || path.Any(x => !Regex.IsMatch(x, "^[A-Za-z][A-Za-z0-9_]{0,80}$")) || path.Any(x => x.Contains("password", StringComparison.OrdinalIgnoreCase) || x.Contains("secret", StringComparison.OrdinalIgnoreCase) || x.Contains("token", StringComparison.OrdinalIgnoreCase))) throw new ApiException(400, "Setting is not exposed through this API");
var root = path[0] == "worldState" ? state.Obj("worldState") : state.Obj("config"); var parts = path[0] == "worldState" ? path.Skip(1).ToArray() : path; if (parts.Length == 0) throw new ApiException(400, "Specify a setting name");
if (getting) { JToken? current = root; foreach (var part in parts) current = (current as JObject)?[part]; result[property.Name] = current?.DeepClone() ?? JValue.CreateNull(); continue; }
if (ServerSettingsEditor.Knows(property.Name)) { ServerSettingsEditor.Set(state, property.Name, property.Value, options); continue; }
if (path[0] is not ("worldState" or "tunables" or "administratorNames" or "autoCreateAccount")) throw new ApiException(400, "Edit server.json for this startup setting");
if (path[0] == "autoCreateAccount" && property.Value.Type != JTokenType.Boolean || path[0] == "administratorNames" && (property.Value is not JArray admins || admins.Any(x => x.Type != JTokenType.String))) throw new ApiException(400, "Invalid configuration value");
if (property.Name == "tunables.useLoginToken") throw new ApiException(400, "Login-token bootstrap authentication is not enabled in this host");
var target = root; foreach (var part in parts.SkipLast(1)) target = target.Obj(part); if (property.Value.Type == JTokenType.Null) target.Remove(parts[^1]); else target[parts[^1]] = property.Value.DeepClone();
}
return getting ? ApiResponse.Json(result) : ApiResponse.Text();
}
}