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

feat: daily reset for syndicate standing (#582)

d9c94664
Sainan <sainan@calamity.inc>
提交于

代码差异

7 个文件 +40 -9
Modified src/controllers/api/inventoryController.ts +27 -4
@@ -1,5 +1,5 @@
1 1 import { RequestHandler } from "express";
2 import { getAccountIdForRequest } from "@/src/services/loginService";
2 import { getAccountForRequest } from "@/src/services/loginService";
3 3 import { toInventoryResponse } from "@/src/helpers/inventoryHelpers";
4 4 import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
5 5 import { config } from "@/src/services/configService";
@@ -11,15 +11,15 @@ import { ExportCustoms, ExportFlavour, ExportKeys, ExportRegions, ExportResource
11 11
12 12 // eslint-disable-next-line @typescript-eslint/no-misused-promises
13 13 const inventoryController: RequestHandler = async (request, response) => {
14 let accountId;
14 let account;
15 15 try {
16 accountId = await getAccountIdForRequest(request);
16 account = await getAccountForRequest(request);
17 17 } catch (e) {
18 18 response.status(400).send("Log-in expired");
19 19 return;
20 20 }
21 21
22 const inventory = await Inventory.findOne({ accountOwnerId: accountId })
22 const inventory = await Inventory.findOne({ accountOwnerId: account._id.toString() })
23 23 .populate<{ LoadOutPresets: ILoadoutDatabase }>("LoadOutPresets")
24 24 .populate<{ Ships: IShipInventory }>("Ships", "-ShipInteriorColors");
25 25
@@ -28,6 +28,29 @@ const inventoryController: RequestHandler = async (request, response) => {
28 28 return;
29 29 }
30 30
31 // Handle daily reset
32 const today: number = Math.trunc(new Date().getTime() / 86400000);
33 if (account.LastLoginDay != today) {
34 account.LastLoginDay = today;
35 await account.save();
36
37 inventory.DailyAffiliation = 16000;
38 inventory.DailyAffiliationPvp = 16000;
39 inventory.DailyAffiliationLibrary = 16000;
40 inventory.DailyAffiliationCetus = 16000;
41 inventory.DailyAffiliationQuills = 16000;
42 inventory.DailyAffiliationSolaris = 16000;
43 inventory.DailyAffiliationVentkids = 16000;
44 inventory.DailyAffiliationVox = 16000;
45 inventory.DailyAffiliationEntrati = 16000;
46 inventory.DailyAffiliationNecraloid = 16000;
47 inventory.DailyAffiliationZariman = 16000;
48 inventory.DailyAffiliationKahl = 16000;
49 inventory.DailyAffiliationCavia = 16000;
50 inventory.DailyAffiliationHex = 16000;
51 await inventory.save();
52 }
53
31 54 //TODO: make a function that converts from database representation to client
32 55 const inventoryJSON = inventory.toJSON();
33 56
Modified src/controllers/api/loginController.ts +2 -2
@@ -41,7 +41,7 @@ const loginController: RequestHandler = async (request, response) => {
41 41 });
42 42 logger.debug("created new account");
43 43 // eslint-disable-next-line @typescript-eslint/no-unused-vars
44 const { email, password, ...databaseAccount } = newAccount;
44 const { email, password, LastLoginDay, ...databaseAccount } = newAccount;
45 45 const newLoginResponse: ILoginResponse = {
46 46 ...databaseAccount,
47 47 Groups: groups,
@@ -77,7 +77,7 @@ const loginController: RequestHandler = async (request, response) => {
77 77 }
78 78 await account.save();
79 79
80 const { email, password, ...databaseAccount } = account.toJSON();
80 const { email, password, LastLoginDay, ...databaseAccount } = account.toJSON();
81 81 const newLoginResponse: ILoginResponse = {
82 82 ...databaseAccount,
83 83 Groups: groups,
Modified src/models/inventoryModels/inventoryModel.ts +1 -0
@@ -635,6 +635,7 @@ const inventorySchema = new Schema<IInventoryDatabase, InventoryDocumentProps>(
635 635 DailyAffiliationZariman: Number,
636 636 DailyAffiliationKahl: Number,
637 637 DailyAffiliationCavia: Number,
638 DailyAffiliationHex: Number,
638 639
639 640 //Daily Focus limit
640 641 DailyFocus: Number,
Modified src/models/loginModel.ts +2 -1
@@ -33,7 +33,8 @@ const databaseAccountSchema = new Schema<IDatabaseAccountDocument>(
33 33 AmazonRefreshToken: { type: String },
34 34 ConsentNeeded: { type: Boolean, required: true },
35 35 TrackedSettings: { type: [String], default: [] },
36 Nonce: { type: Number, default: 0 }
36 Nonce: { type: Number, default: 0 },
37 LastLoginDay: { type: Number }
37 38 },
38 39 opts
39 40 );
Modified src/services/loginService.ts +6 -2
@@ -44,7 +44,7 @@ export const createPersonalRooms = async (accountId: Types.ObjectId, shipId: Typ
44 44 await personalRooms.save();
45 45 };
46 46
47 export const getAccountIdForRequest = async (req: Request): Promise<string> => {
47 export const getAccountForRequest = async (req: Request) => {
48 48 if (!req.query.accountId) {
49 49 throw new Error("Request is missing accountId parameter");
50 50 }
@@ -61,5 +61,9 @@ export const getAccountIdForRequest = async (req: Request): Promise<string> => {
61 61 if (!account) {
62 62 throw new Error("Invalid accountId-nonce pair");
63 63 }
64 return account._id.toString();
64 return account;
65 };
66
67 export const getAccountIdForRequest = async (req: Request): Promise<string> => {
68 return (await getAccountForRequest(req))._id.toString();
65 69 };
Modified src/types/inventoryTypes/inventoryTypes.ts +1 -0
@@ -283,6 +283,7 @@ export interface IInventoryResponse {
283 283 NemesisAbandonedRewards: string[];
284 284 DailyAffiliationKahl: number;
285 285 DailyAffiliationCavia: number;
286 DailyAffiliationHex?: number;
286 287 LastInventorySync: IOid;
287 288 NextRefill: IMongoDate; // Next time argon crystals will have a decay tick
288 289 FoundToday?: IMiscItem[]; // for Argon Crystals
Modified src/types/loginTypes.ts +1 -0
@@ -32,6 +32,7 @@ export interface IDatabaseAccount {
32 32 ConsentNeeded: boolean;
33 33 TrackedSettings: string[];
34 34 Nonce: number;
35 LastLoginDay?: number;
35 36 }
36 37
37 38 export interface ILoginRequest {