XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

SpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 1 Star 0
返回提交历史

XFEstudio/SpaceNinjaServer

fix: ensure helminth shard operations don't produce a null shard (#2176)

Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2176 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

01e49076
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

2 个文件 +10 -9
Modified src/controllers/api/infestedFoundryController.ts +5 -3
@@ -30,8 +30,9 @@ export const infestedFoundryController: RequestHandler = async (req, res) => {
30 30 const request = getJSONfromString<IShardInstallRequest>(String(req.body));
31 31 const inventory = await getInventory(account._id.toString());
32 32 const suit = inventory.Suits.id(request.SuitId.$oid)!;
33 if (!suit.ArchonCrystalUpgrades || suit.ArchonCrystalUpgrades.length != 5) {
34 suit.ArchonCrystalUpgrades = [{}, {}, {}, {}, {}];
33 suit.ArchonCrystalUpgrades ??= [];
34 while (suit.ArchonCrystalUpgrades.length < request.Slot) {
35 suit.ArchonCrystalUpgrades.push({});
35 36 }
36 37 suit.ArchonCrystalUpgrades[request.Slot] = {
37 38 UpgradeType: request.UpgradeType,
@@ -92,7 +93,8 @@ export const infestedFoundryController: RequestHandler = async (req, res) => {
92 93 }
93 94
94 95 // remove from suit
95 suit.ArchonCrystalUpgrades![request.Slot] = {};
96 suit.ArchonCrystalUpgrades![request.Slot].UpgradeType = undefined;
97 suit.ArchonCrystalUpgrades![request.Slot].Color = undefined;
96 98
97 99 await inventory.save();
98 100
Modified src/models/inventoryModels/inventoryModel.ts +5 -6
@@ -251,12 +251,6 @@ const ArchonCrystalUpgradeSchema = new Schema<IArchonCrystalUpgrade>(
251 251 { _id: false }
252 252 );
253 253
254 ArchonCrystalUpgradeSchema.set("toJSON", {
255 transform(_document, returnedObject) {
256 delete returnedObject.__v;
257 }
258 });
259
260 254 const boosterSchema = new Schema<IBooster>(
261 255 {
262 256 ExpiryDate: Number,
@@ -1079,6 +1073,11 @@ EquipmentSchema.set("toJSON", {
1079 1073 if (db.UmbraDate) {
1080 1074 client.UmbraDate = toMongoDate(db.UmbraDate);
1081 1075 }
1076
1077 if (client.ArchonCrystalUpgrades) {
1078 // For some reason, mongoose turns empty objects here into nulls, so we have to fix it.
1079 client.ArchonCrystalUpgrades = client.ArchonCrystalUpgrades.map(x => (x as unknown) ?? {});
1080 }
1082 1081 }
1083 1082 });
1084 1083