返回提交历史
Modified
src/controllers/api/inventoryController.ts
+11
-0
Modified
src/models/inventoryModels/inventoryModel.ts
+5
-4
XFEstudio/XFESpaceNinjaServer
chore: clamp ItemCount of RawUpgrades (#3352)
Closes #3333 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3352 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
3581ff64
代码差异
2 个文件
+16
-4
@@ -448,6 +448,17 @@ export const getInventoryResponse = async (
448
448
// Set 2FA enabled so trading post can be used
449
449
inventoryResponse.HWIDProtectEnabled = true;
450
450
451
if (!forWebui) {
452
// Ensure numbers comfortably fit in a 32-bit integer so the client's in-memory value doesn't overflow or underflow.
453
for (const obj of inventory.RawUpgrades) {
454
if (obj.ItemCount > 999_999_999) {
455
obj.ItemCount = 999_999_999;
456
} else if (obj.ItemCount < -999_999_999) {
457
obj.ItemCount = -999_999_999;
458
}
459
}
460
}
461
451
462
if (buildLabel) {
452
463
// Fix nemesis for older versions
453
464
if (
@@ -134,10 +134,11 @@ export const typeCountSchema = new Schema<ITypeCount>({ ItemType: String, ItemCo
134
134
135
135
typeCountSchema.set("toJSON", {
136
136
transform(_doc, obj: Record<string, any>) {
137
if (obj.ItemCount > 2147483647) {
138
obj.ItemCount = 2147483647;
139
} else if (obj.ItemCount < -2147483648) {
140
obj.ItemCount = -2147483648;
137
// Ensure numbers comfortably fit in a 32-bit integer so the client's in-memory value doesn't overflow or underflow.
138
if (obj.ItemCount > 999_999_999) {
139
obj.ItemCount = 999_999_999;
140
} else if (obj.ItemCount < -999_999_999) {
141
obj.ItemCount = -999_999_999;
141
142
}
142
143
}
143
144
});