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

chore: update hubBlessingController (#3140)

Fixed the cooldown and applied some changes I noticed in newer versions. Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3140 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

60fc6e34
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

1 个文件 +36 -11
Modified src/controllers/api/hubBlessingController.ts +36 -11
@@ -1,18 +1,21 @@
1 import { unixTimesInMs } from "../../constants/timeConstants.ts";
1 2 import { getJSONfromString } from "../../helpers/stringHelpers.ts";
2 3 import { addBooster, getInventory } from "../../services/inventoryService.ts";
3 4 import { getAccountIdForRequest } from "../../services/loginService.ts";
4 5 import { getRandomInt } from "../../services/rngService.ts";
5 6 import type { RequestHandler } from "express";
6 7 import { ExportBoosters } from "warframe-public-export-plus";
8 import type { IOid } from "../../types/commonTypes.ts";
7 9
8 10 export const hubBlessingController: RequestHandler = async (req, res) => {
9 11 const accountId = await getAccountIdForRequest(req);
10 12 const data = getJSONfromString<IHubBlessingRequest>(String(req.body));
11 const boosterType = ExportBoosters[data.booster].typeName;
12 13 if (req.query.mode == "send") {
14 const boosterType = ExportBoosters[data.booster!].typeName;
15
13 16 const inventory = await getInventory(accountId, "BlessingCooldown Boosters");
14 inventory.BlessingCooldown = new Date(Date.now() + 86400000);
15 addBooster(boosterType, 3 * 3600, inventory); // unfaithful, but current HUB server does not handle broadcasting, so this way users can bless themselves.
17 inventory.BlessingCooldown = new Date(Date.now() + 23 * unixTimesInMs.hour);
18 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.
16 19 await inventory.save();
17 20
18 21 let token = "";
@@ -23,23 +26,45 @@ export const hubBlessingController: RequestHandler = async (req, res) => {
23 26 res.json({
24 27 BlessingCooldown: inventory.BlessingCooldown,
25 28 SendTime: Math.trunc(Date.now() / 1000).toString(),
29 Expiry: Math.trunc(Date.now() / 1000 + 3 * 3600).toString(), // added in 38.6.0
26 30 Token: token
27 31 });
28 32 } else {
29 const inventory = await getInventory(accountId, "Boosters");
30 addBooster(boosterType, 3 * 3600, inventory);
31 await inventory.save();
33 if (data.booster) {
34 // < U41
35 const boosterType = ExportBoosters[data.booster].typeName;
32 36
33 res.json({
34 BoosterType: data.booster,
35 Sender: data.senderId
36 });
37 const inventory = await getInventory(accountId, "Boosters");
38 addBooster(boosterType, 3 * 3600, inventory);
39 await inventory.save();
40
41 res.json({
42 BoosterType: data.booster,
43 Sender: data.senderId
44 });
45 } else {
46 // >= U41
47 const inventory = await getInventory(accountId, "Boosters");
48 for (const blessing of data.PendingHubBlessings!) {
49 const boosterType = ExportBoosters[blessing.booster].typeName;
50 // TODO: Maybe respect sendTime?
51 addBooster(boosterType, 3 * 3600, inventory);
52 }
53 await inventory.save();
54 res.end();
55 }
37 56 }
38 57 };
39 58
40 59 interface IHubBlessingRequest {
41 booster: string;
60 booster?: string;
42 61 senderId?: string; // mode=request
43 62 sendTime?: string; // mode=request
44 63 token?: string; // mode=request
64 PendingHubBlessings?: {
65 booster: string;
66 senderId: IOid;
67 sendTime: string;
68 token: string;
69 }[];
45 70 }