返回提交历史
Modified
src/controllers/api/hubBlessingController.ts
+6
-7
Modified
src/services/inventoryService.ts
+13
-0
XFEstudio/XFESpaceNinjaServer
fix: correctly handle getting the same blessing multiple times (#3168)
Closes #3163 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3168 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
6ef6a706
代码差异
2 个文件
+19
-7
@@ -1,6 +1,6 @@
1
1
import { unixTimesInMs } from "../../constants/timeConstants.ts";
2
2
import { getJSONfromString } from "../../helpers/stringHelpers.ts";
3
import { addBooster, getInventory } from "../../services/inventoryService.ts";
3
import { getInventory, setBooster } from "../../services/inventoryService.ts";
4
4
import { getAccountIdForRequest } from "../../services/loginService.ts";
5
5
import { getRandomInt } from "../../services/rngService.ts";
6
6
import type { RequestHandler } from "express";
@@ -16,7 +16,7 @@ export const hubBlessingController: RequestHandler = async (req, res) => {
16
16
17
17
const inventory = await getInventory(accountId, "noBlessingCooldown BlessingCooldown Boosters");
18
18
inventory.BlessingCooldown = new Date(inventory.noBlessingCooldown ? 0 : Date.now() + 23 * unixTimesInMs.hour);
19
addBooster(boosterType, 3 * 3600, inventory); // unfaithful for < U41 but correct for >= U41 afaict. Either way, needed for blessings to work without a (full) HUB server.
19
setBooster(boosterType, Math.trunc(Date.now() / 1000) + 3 * 3600, inventory); // At some point in the past, the blesser requested their own blessings, but now sending it automatically gives it to you.
20
20
await inventory.save();
21
21
22
22
let token = "";
@@ -32,11 +32,11 @@ export const hubBlessingController: RequestHandler = async (req, res) => {
32
32
});
33
33
} else {
34
34
if (data.booster) {
35
// < U41
35
// < 38.6.0 (unsure about the exact version that changed it)
36
36
const boosterType = ExportBoosters[data.booster].typeName;
37
37
38
38
const inventory = await getInventory(accountId, "Boosters");
39
addBooster(boosterType, 3 * 3600, inventory);
39
setBooster(boosterType, Math.trunc(Date.now() / 1000) + 3 * 3600, inventory);
40
40
await inventory.save();
41
41
42
42
res.json({
@@ -44,12 +44,11 @@ export const hubBlessingController: RequestHandler = async (req, res) => {
44
44
Sender: data.senderId
45
45
});
46
46
} else {
47
// >= U41
47
// >= 38.6.0 (unsure about the exact version that changed it)
48
48
const inventory = await getInventory(accountId, "Boosters");
49
49
for (const blessing of data.PendingHubBlessings!) {
50
50
const boosterType = ExportBoosters[blessing.booster].typeName;
51
// TODO: Maybe respect sendTime?
52
addBooster(boosterType, 3 * 3600, inventory);
51
setBooster(boosterType, parseInt(blessing.sendTime) + 3 * 3600, inventory);
53
52
}
54
53
await inventory.save();
55
54
res.end();
@@ -2511,6 +2511,19 @@ export const addBooster = (ItemType: string, timeSecs: number, inventory: TInven
2511
2511
}
2512
2512
};
2513
2513
2514
export const setBooster = (ItemType: string, expiryTimeSecs: number, inventory: TInventoryDatabaseDocument): void => {
2515
const { Boosters } = inventory;
2516
2517
const itemIndex = Boosters.findIndex(booster => booster.ItemType === ItemType);
2518
2519
if (itemIndex !== -1) {
2520
const existingBooster = Boosters[itemIndex];
2521
existingBooster.ExpiryDate = Math.max(existingBooster.ExpiryDate, expiryTimeSecs);
2522
} else {
2523
Boosters.push({ ItemType, ExpiryDate: expiryTimeSecs });
2524
}
2525
};
2526
2514
2527
export const updateSyndicate = (
2515
2528
inventory: TInventoryDatabaseDocument,
2516
2529
syndicateUpdate: IMissionInventoryUpdateRequest["AffiliationChanges"]