chore: cap FusionPoints balance at 2147483647 (#1797)
Same idea as with typeCountSchema. The game needs to be able to store these safely in an i32 on the C++ side. Reviewed-on: OpenWF/SpaceNinjaServer#1797 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									26d644a982
								
							
						
					
					
						commit
						7a8b12b372
					
				@ -1,4 +1,4 @@
 | 
			
		||||
import { getInventory } from "@/src/services/inventoryService";
 | 
			
		||||
import { addFusionPoints, getInventory } from "@/src/services/inventoryService";
 | 
			
		||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
			
		||||
import { RequestHandler } from "express";
 | 
			
		||||
 | 
			
		||||
@ -17,7 +17,7 @@ export const claimLibraryDailyTaskRewardController: RequestHandler = async (req,
 | 
			
		||||
    }
 | 
			
		||||
    syndicate.Standing += rewardStanding;
 | 
			
		||||
 | 
			
		||||
    inventory.FusionPoints += 80 * rewardQuantity;
 | 
			
		||||
    addFusionPoints(inventory, 80 * rewardQuantity);
 | 
			
		||||
    await inventory.save();
 | 
			
		||||
 | 
			
		||||
    res.json({
 | 
			
		||||
 | 
			
		||||
@ -2,7 +2,7 @@ import { toMongoDate } from "@/src/helpers/inventoryHelpers";
 | 
			
		||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
			
		||||
import { Guild } from "@/src/models/guildModel";
 | 
			
		||||
import { checkClanAscensionHasRequiredContributors } from "@/src/services/guildService";
 | 
			
		||||
import { getInventory } from "@/src/services/inventoryService";
 | 
			
		||||
import { addFusionPoints, getInventory } from "@/src/services/inventoryService";
 | 
			
		||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
			
		||||
import { RequestHandler } from "express";
 | 
			
		||||
import { Types } from "mongoose";
 | 
			
		||||
@ -36,7 +36,7 @@ export const contributeGuildClassController: RequestHandler = async (req, res) =
 | 
			
		||||
 | 
			
		||||
    // Either way, endo is given to the contributor.
 | 
			
		||||
    const inventory = await getInventory(accountId, "FusionPoints");
 | 
			
		||||
    inventory.FusionPoints += guild.CeremonyEndo!;
 | 
			
		||||
    addFusionPoints(inventory, guild.CeremonyEndo!);
 | 
			
		||||
    await inventory.save();
 | 
			
		||||
 | 
			
		||||
    res.json({
 | 
			
		||||
 | 
			
		||||
@ -8,7 +8,8 @@ import {
 | 
			
		||||
    addConsumables,
 | 
			
		||||
    freeUpSlot,
 | 
			
		||||
    combineInventoryChanges,
 | 
			
		||||
    addCrewShipRawSalvage
 | 
			
		||||
    addCrewShipRawSalvage,
 | 
			
		||||
    addFusionPoints
 | 
			
		||||
} from "@/src/services/inventoryService";
 | 
			
		||||
import { InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
			
		||||
import { ExportDojoRecipes } from "warframe-public-export-plus";
 | 
			
		||||
@ -69,7 +70,7 @@ export const sellController: RequestHandler = async (req, res) => {
 | 
			
		||||
    if (payload.SellCurrency == "SC_RegularCredits") {
 | 
			
		||||
        inventory.RegularCredits += payload.SellPrice;
 | 
			
		||||
    } else if (payload.SellCurrency == "SC_FusionPoints") {
 | 
			
		||||
        inventory.FusionPoints += payload.SellPrice;
 | 
			
		||||
        addFusionPoints(inventory, payload.SellPrice);
 | 
			
		||||
    } else if (payload.SellCurrency == "SC_PrimeBucks") {
 | 
			
		||||
        addMiscItems(inventory, [
 | 
			
		||||
            {
 | 
			
		||||
 | 
			
		||||
@ -1,12 +1,16 @@
 | 
			
		||||
import { RequestHandler } from "express";
 | 
			
		||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
			
		||||
import { getInventory } from "@/src/services/inventoryService";
 | 
			
		||||
import { addFusionPoints, getInventory } from "@/src/services/inventoryService";
 | 
			
		||||
 | 
			
		||||
export const addCurrencyController: RequestHandler = async (req, res) => {
 | 
			
		||||
    const accountId = await getAccountIdForRequest(req);
 | 
			
		||||
    const inventory = await getInventory(accountId);
 | 
			
		||||
    const request = req.body as IAddCurrencyRequest;
 | 
			
		||||
    const inventory = await getInventory(accountId, request.currency);
 | 
			
		||||
    if (request.currency == "FusionPoints") {
 | 
			
		||||
        addFusionPoints(inventory, request.delta);
 | 
			
		||||
    } else {
 | 
			
		||||
        inventory[request.currency] += request.delta;
 | 
			
		||||
    }
 | 
			
		||||
    await inventory.save();
 | 
			
		||||
    res.end();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -580,7 +580,7 @@ export const addItem = async (
 | 
			
		||||
    }
 | 
			
		||||
    if (typeName in ExportFusionBundles) {
 | 
			
		||||
        const fusionPointsTotal = ExportFusionBundles[typeName].fusionPoints * quantity;
 | 
			
		||||
        inventory.FusionPoints += fusionPointsTotal;
 | 
			
		||||
        addFusionPoints(inventory, fusionPointsTotal);
 | 
			
		||||
        return {
 | 
			
		||||
            FusionPoints: fusionPointsTotal
 | 
			
		||||
        };
 | 
			
		||||
@ -1069,6 +1069,15 @@ export const updateCurrency = (
 | 
			
		||||
    return currencyChanges;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const addFusionPoints = (inventory: TInventoryDatabaseDocument, add: number): number => {
 | 
			
		||||
    if (inventory.FusionPoints + add > 2147483647) {
 | 
			
		||||
        logger.warn(`capping FusionPoints balance at 2147483647`);
 | 
			
		||||
        add = 2147483647 - inventory.FusionPoints;
 | 
			
		||||
    }
 | 
			
		||||
    inventory.FusionPoints += add;
 | 
			
		||||
    return add;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const standingLimitBinToInventoryKey: Record<
 | 
			
		||||
    Exclude<TStandingLimitBin, "STANDING_LIMIT_BIN_NONE">,
 | 
			
		||||
    keyof IDailyAffiliations
 | 
			
		||||
 | 
			
		||||
@ -19,6 +19,7 @@ import {
 | 
			
		||||
    addCrewShipRawSalvage,
 | 
			
		||||
    addEmailItem,
 | 
			
		||||
    addFocusXpIncreases,
 | 
			
		||||
    addFusionPoints,
 | 
			
		||||
    addFusionTreasures,
 | 
			
		||||
    addGearExpByCategory,
 | 
			
		||||
    addItem,
 | 
			
		||||
@ -287,14 +288,14 @@ export const addMissionInventoryUpdates = async (
 | 
			
		||||
                addShipDecorations(inventory, value);
 | 
			
		||||
                break;
 | 
			
		||||
            case "FusionBundles": {
 | 
			
		||||
                let fusionPoints = 0;
 | 
			
		||||
                let fusionPointsDelta = 0;
 | 
			
		||||
                for (const fusionBundle of value) {
 | 
			
		||||
                    const fusionPointsTotal =
 | 
			
		||||
                        ExportFusionBundles[fusionBundle.ItemType].fusionPoints * fusionBundle.ItemCount;
 | 
			
		||||
                    inventory.FusionPoints += fusionPointsTotal;
 | 
			
		||||
                    fusionPoints += fusionPointsTotal;
 | 
			
		||||
                    fusionPointsDelta += addFusionPoints(
 | 
			
		||||
                        inventory,
 | 
			
		||||
                        ExportFusionBundles[fusionBundle.ItemType].fusionPoints * fusionBundle.ItemCount
 | 
			
		||||
                    );
 | 
			
		||||
                }
 | 
			
		||||
                inventoryChanges.FusionPoints = fusionPoints;
 | 
			
		||||
                inventoryChanges.FusionPoints = fusionPointsDelta;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
            case "EmailItems": {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user