From 8a0f99f573715790aaea51230801ec7e9ac373bc Mon Sep 17 00:00:00 2001 From: VoltPrime Date: Fri, 14 Nov 2025 01:50:03 -0800 Subject: [PATCH] fix: selling items in old builds (#3023) I'm not sure exactly which build the sell request changed in, but this solution seems to be catch-all. Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3023 Reviewed-by: Sainan <63328889+sainan@users.noreply.github.com> Co-authored-by: VoltPrime Co-committed-by: VoltPrime --- src/controllers/api/sellController.ts | 40 +++++++++++++++++++-------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/controllers/api/sellController.ts b/src/controllers/api/sellController.ts index b32d2aa4..4b33e4be 100644 --- a/src/controllers/api/sellController.ts +++ b/src/controllers/api/sellController.ts @@ -25,11 +25,24 @@ export const sellController: RequestHandler = async (req, res) => { //console.log(JSON.stringify(payload, null, 2)); const accountId = await getAccountIdForRequest(req); const requiredFields = new Set(); - if (payload.SellCurrency == "SC_RegularCredits") { + let sellCurrency = "SC_RegularCredits"; + if (payload.SellCurrency) { + sellCurrency = payload.SellCurrency; + } else { + if (payload.SellForFusionPoints || payload.SellForPrimeBucks) { + if (payload.SellForFusionPoints) { + sellCurrency = "SC_FusionPoints"; + } + if (payload.SellForPrimeBucks) { + sellCurrency = "SC_PrimeBucks"; + } + } + } + if (sellCurrency == "SC_RegularCredits") { requiredFields.add("RegularCredits"); - } else if (payload.SellCurrency == "SC_FusionPoints") { + } else if (sellCurrency == "SC_FusionPoints") { requiredFields.add("FusionPoints"); - } else if (payload.SellCurrency == "SC_CrewShipFusionPoints") { + } else if (sellCurrency == "SC_CrewShipFusionPoints") { requiredFields.add("CrewShipFusionPoints"); } else { requiredFields.add("MiscItems"); @@ -83,27 +96,27 @@ export const sellController: RequestHandler = async (req, res) => { const inventory = await getInventory(accountId, Array.from(requiredFields).join(" ")); // Give currency - if (payload.SellCurrency == "SC_RegularCredits") { + if (sellCurrency == "SC_RegularCredits") { inventory.RegularCredits += payload.SellPrice; - } else if (payload.SellCurrency == "SC_FusionPoints") { + } else if (sellCurrency == "SC_FusionPoints") { addFusionPoints(inventory, payload.SellPrice); - } else if (payload.SellCurrency == "SC_CrewShipFusionPoints") { + } else if (sellCurrency == "SC_CrewShipFusionPoints") { addCrewShipFusionPoints(inventory, payload.SellPrice); - } else if (payload.SellCurrency == "SC_PrimeBucks") { + } else if (sellCurrency == "SC_PrimeBucks") { addMiscItems(inventory, [ { ItemType: "/Lotus/Types/Items/MiscItems/PrimeBucks", ItemCount: payload.SellPrice } ]); - } else if (payload.SellCurrency == "SC_DistillPoints") { + } else if (sellCurrency == "SC_DistillPoints") { addMiscItems(inventory, [ { ItemType: "/Lotus/Types/Items/MiscItems/DistillPoints", ItemCount: payload.SellPrice } ]); - } else if (payload.SellCurrency == "SC_Resources") { + } else if (sellCurrency == "SC_Resources") { // Will add appropriate MiscItems from CrewShipWeapons or CrewShipWeaponSkins } else { throw new Error("Unknown SellCurrency: " + payload.SellCurrency); @@ -218,7 +231,7 @@ export const sellController: RequestHandler = async (req, res) => { } else { const index = inventory.CrewShipWeapons.findIndex(x => x._id.equals(sellItem.String)); if (index != -1) { - if (payload.SellCurrency == "SC_Resources") { + if (sellCurrency == "SC_Resources") { refundPartialBuildCosts(inventory, inventory.CrewShipWeapons[index].ItemType, inventoryChanges); } inventory.CrewShipWeapons.splice(index, 1); @@ -241,7 +254,7 @@ export const sellController: RequestHandler = async (req, res) => { } else { const index = inventory.CrewShipWeaponSkins.findIndex(x => x._id.equals(sellItem.String)); if (index != -1) { - if (payload.SellCurrency == "SC_Resources") { + if (sellCurrency == "SC_Resources") { refundPartialBuildCosts( inventory, inventory.CrewShipWeaponSkins[index].ItemType, @@ -346,7 +359,7 @@ interface ISellRequest { WeaponSkins?: ISellItem[]; // SNS specific field }; SellPrice: number; - SellCurrency: + SellCurrency?: | "SC_RegularCredits" | "SC_PrimeBucks" | "SC_FusionPoints" @@ -355,6 +368,9 @@ interface ISellRequest { | "SC_Resources" | "somethingelsewemightnotknowabout"; buildLabel: string; + // These are used in old builds (undetermined where it changed) instead of SellCurrency + SellForPrimeBucks?: boolean; + SellForFusionPoints?: boolean; } interface ISellItem {