using Newtonsoft.Json.Linq;
using XFEWarframe.Core.Data;
namespace XFEWarframe.Core.Services;
public static class PlayerPermissions
{
public static bool Currency(JObject state, ServerOptions options) => state.Obj("config").Value<bool?>("allowPlayerCurrencyGrant") ?? options.AllowPlayerCurrencyGrant;
public static bool Items(JObject state, ServerOptions options) => state.Obj("config").Value<bool?>("allowPlayerItemGrant") ?? options.AllowPlayerItemGrant;
// Currency packs, random packs and mail can indirectly grant currency. They are administered separately.
public static bool Grantable(string category) => category is not ("CreditBundles" or "FusionBundles" or "Bundles" or "BoosterPacks" or "EmailItems" or "SpecialItems") &&
(Inventory.EquipmentKeys.Contains(category) || Inventory.CountedKeys.Contains(category) || category is "FlavourItems" or "WeaponSkins" or "Boosters" or "FusionTreasures" or "SlotItems");
public static void CheckItem(ItemCatalog catalog, string type, int depth = 0)
{
if (depth > 8) throw new ApiException(400, "物品附加内容过多。");
var (category, meta) = catalog.Get(type);
if (!Grantable(category) && !(depth > 0 && category == "SpecialItems")) throw new ApiException(403, "此物品需由管理员发放。");
foreach (var key in new[] { "additionalItems", "exalted" })
foreach (var extra in meta[key] as JArray ?? []) CheckItem(catalog, extra.ToString(), depth + 1);
if (meta.Value<string>("defaultWeapon") is string weapon) CheckItem(catalog, weapon, depth + 1);
if (meta.Value<string>("bayonetOtherWeaponType") is string counterpart && !meta.Value<bool>("excludeFromMarket")) CheckItem(catalog, counterpart, depth + 1);
}
}
using Newtonsoft.Json.Linq;
using XFEWarframe.Core.Data;
namespace XFEWarframe.Core.Services;
public static class PlayerPermissions
{
public static bool Currency(JObject state, ServerOptions options) => state.Obj("config").Value<bool?>("allowPlayerCurrencyGrant") ?? options.AllowPlayerCurrencyGrant;
public static bool Items(JObject state, ServerOptions options) => state.Obj("config").Value<bool?>("allowPlayerItemGrant") ?? options.AllowPlayerItemGrant;
// Currency packs, random packs and mail can indirectly grant currency. They are administered separately.
public static bool Grantable(string category) => category is not ("CreditBundles" or "FusionBundles" or "Bundles" or "BoosterPacks" or "EmailItems" or "SpecialItems") &&
(Inventory.EquipmentKeys.Contains(category) || Inventory.CountedKeys.Contains(category) || category is "FlavourItems" or "WeaponSkins" or "Boosters" or "FusionTreasures" or "SlotItems");
public static void CheckItem(ItemCatalog catalog, string type, int depth = 0)
{
if (depth > 8) throw new ApiException(400, "物品附加内容过多。");
var (category, meta) = catalog.Get(type);
if (!Grantable(category) && !(depth > 0 && category == "SpecialItems")) throw new ApiException(403, "此物品需由管理员发放。");
foreach (var key in new[] { "additionalItems", "exalted" })
foreach (var extra in meta[key] as JArray ?? []) CheckItem(catalog, extra.ToString(), depth + 1);
if (meta.Value<string>("defaultWeapon") is string weapon) CheckItem(catalog, weapon, depth + 1);
if (meta.Value<string>("bayonetOtherWeaponType") is string counterpart && !meta.Value<bool>("excludeFromMarket")) CheckItem(catalog, counterpart, depth + 1);
}
}