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: convert TrainingDate for pre-U19.5 clients (#3831)

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

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

代码差异

3 个文件 +18 -16
Modified src/controllers/api/inventoryController.ts +1 -0
@@ -695,6 +695,7 @@ export const getInventoryResponse = async (
695 695 for (const pr of inventoryResponse.PendingRecipes) {
696 696 pr.CompletionDate = toMongoDate2(fromMongoDate(pr.CompletionDate), buildLabel);
697 697 }
698 inventoryResponse.TrainingDate = toMongoDate2(inventory.TrainingDate, buildLabel);
698 699 inventoryResponse.NextRefill = toMongoDate2(inventory.NextRefill!, buildLabel);
699 700
700 701 if (version_compare(buildLabel, "2014.02.05.00.00") < 0) {
Modified src/controllers/api/trainingResultController.ts +16 -15
@@ -1,28 +1,31 @@
1 import { getAccountIdForRequest } from "../../services/loginService.ts";
1 import { getAccountForRequest, type TAccountDocument } from "../../services/loginService.ts";
2 2 import { getJSONfromString } from "../../helpers/stringHelpers.ts";
3 3 import { getInventory } from "../../services/inventoryService.ts";
4 import type { IMongoDate } from "../../types/commonTypes.ts";
4 import type { IMongoDateWithLegacySupport } from "../../types/commonTypes.ts";
5 5 import type { RequestHandler } from "express";
6 6 import { unixTimesInMs } from "../../constants/timeConstants.ts";
7 7 import type { IInventoryChanges } from "../../types/purchaseTypes.ts";
8 8 import { createMessage } from "../../services/inboxService.ts";
9 import type { Types } from "mongoose";
9 import { toMongoDate2 } from "../../helpers/inventoryHelpers.ts";
10 10
11 11 interface ITrainingResultsRequest {
12 12 numLevelsGained: number;
13 13 }
14 14
15 15 interface ITrainingResultsResponse {
16 NewTrainingDate: IMongoDate;
16 NewTrainingDate: IMongoDateWithLegacySupport;
17 17 NewLevel: number;
18 18 InventoryChanges: IInventoryChanges;
19 19 }
20 20
21 21 const handleTrainingProgress = async (
22 accountId: string | Types.ObjectId,
22 account: TAccountDocument,
23 23 numLevelsGained: number
24 24 ): Promise<ITrainingResultsResponse> => {
25 const inventory = await getInventory(accountId, "TrainingDate PlayerLevel TradesRemaining noMasteryRankUpCooldown");
25 const inventory = await getInventory(
26 account._id,
27 "TrainingDate PlayerLevel TradesRemaining noMasteryRankUpCooldown"
28 );
26 29
27 30 if (numLevelsGained === 1) {
28 31 let time = Date.now();
@@ -35,7 +38,7 @@ const handleTrainingProgress = async (
35 38 inventory.TradesRemaining += 1;
36 39
37 40 if (inventory.PlayerLevel == 2) {
38 await createMessage(accountId, [
41 await createMessage(account._id, [
39 42 {
40 43 sndr: "/Lotus/Language/Game/Maroo",
41 44 msg: "/Lotus/Language/Clan/MarooClanSearchDesc",
@@ -45,7 +48,7 @@ const handleTrainingProgress = async (
45 48 ]);
46 49 }
47 50
48 await createMessage(accountId, [
51 await createMessage(account._id, [
49 52 {
50 53 sndr: "/Lotus/Language/Menu/Mailbox_WarframeSender",
51 54 msg: "/Lotus/Language/Inbox/MasteryRewardMsg",
@@ -68,26 +71,24 @@ const handleTrainingProgress = async (
68 71 const changedinventory = await inventory.save();
69 72
70 73 return {
71 NewTrainingDate: {
72 $date: { $numberLong: changedinventory.TrainingDate.getTime().toString() }
73 },
74 NewTrainingDate: toMongoDate2(changedinventory.TrainingDate, account.BuildLabel),
74 75 NewLevel: numLevelsGained == 1 ? changedinventory.PlayerLevel : inventory.PlayerLevel,
75 76 InventoryChanges: {}
76 77 };
77 78 };
78 79
79 80 export const trainingResultPostController: RequestHandler = async (req, res): Promise<void> => {
80 const accountId = await getAccountIdForRequest(req);
81 const account = await getAccountForRequest(req);
81 82 const { numLevelsGained } = getJSONfromString<ITrainingResultsRequest>(String(req.body));
82 83
83 const response = await handleTrainingProgress(accountId, numLevelsGained);
84 const response = await handleTrainingProgress(account, numLevelsGained);
84 85 res.json(response satisfies ITrainingResultsResponse);
85 86 };
86 87
87 88 export const trainingResultGetController: RequestHandler = async (req, res): Promise<void> => {
88 const accountId = await getAccountIdForRequest(req);
89 const account = await getAccountForRequest(req);
89 90 const numLevelsGained = Number(req.query.numLevelsGained ?? 0);
90 91
91 const response = await handleTrainingProgress(accountId, numLevelsGained);
92 const response = await handleTrainingProgress(account, numLevelsGained);
92 93 res.json(response satisfies ITrainingResultsResponse);
93 94 };
Modified src/types/inventoryTypes/inventoryTypes.ts +1 -1
@@ -390,7 +390,7 @@ export interface IInventoryClient
390 390 Recipes: ITypeCount[];
391 391 WeaponSkins: IWeaponSkinClient[];
392 392 PendingRecipes: IPendingRecipeClient[];
393 TrainingDate: IMongoDate;
393 TrainingDate: IMongoDateWithLegacySupport;
394 394 PlayerLevel: number;
395 395 Counselor?: boolean;
396 396 Upgrades: IUpgradeClient[];