SpaceNinjaServer/src/controllers/custom/pushArchonCrystalUpgradeController.ts
Sainan 0d388b4b0f feat: support websocket connections from game client (#2735)
For bootstrapper v0.11.11, out now.

Reviewed-on: OpenWF/SpaceNinjaServer#2735
Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com>
Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
2025-09-10 00:00:09 -07:00

25 lines
1012 B
TypeScript

import type { RequestHandler } from "express";
import { getAccountIdForRequest } from "../../services/loginService.ts";
import { getInventory } from "../../services/inventoryService.ts";
import { broadcastInventoryUpdate } from "../../services/wsService.ts";
export const pushArchonCrystalUpgradeController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId);
const suit = inventory.Suits.id(req.query.oid as string);
if (suit) {
suit.ArchonCrystalUpgrades ??= [];
const count = (req.query.count as number | undefined) ?? 1;
if (count >= 1 && count <= 10000) {
for (let i = 0; i != count; ++i) {
suit.ArchonCrystalUpgrades.push({ UpgradeType: req.query.type as string });
}
await inventory.save();
res.end();
broadcastInventoryUpdate(req);
return;
}
}
res.status(400).end();
};