XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFESpaceNinjaServer

feat: track LastLogin to provide it for friends & clan members (#2013)

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

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

代码差异

7 个文件 +15 -4
Modified src/controllers/api/addPendingFriendController.ts +2 -1
@@ -1,4 +1,4 @@
1 import { toOid } from "@/src/helpers/inventoryHelpers";
1 import { toMongoDate, toOid } from "@/src/helpers/inventoryHelpers";
2 2 import { getJSONfromString } from "@/src/helpers/stringHelpers";
3 3 import { Friendship } from "@/src/models/friendModel";
4 4 import { Account } from "@/src/models/loginModel";
@@ -37,6 +37,7 @@ export const addPendingFriendController: RequestHandler = async (req, res) => {
37 37 const friendInfo: IFriendInfo = {
38 38 _id: toOid(account._id),
39 39 DisplayName: account.DisplayName,
40 LastLogin: toMongoDate(account.LastLogin),
40 41 Note: payload.message
41 42 };
42 43 await addInventoryDataToFriendInfo(friendInfo);
Modified src/controllers/api/addToGuildController.ts +2 -0
@@ -1,3 +1,4 @@
1 import { toMongoDate } from "@/src/helpers/inventoryHelpers";
1 2 import { Guild, GuildMember } from "@/src/models/guildModel";
2 3 import { Account } from "@/src/models/loginModel";
3 4 import { addInventoryDataToFriendInfo, areFriends } from "@/src/services/friendService";
@@ -75,6 +76,7 @@ export const addToGuildController: RequestHandler = async (req, res) => {
75 76 const member: IGuildMemberClient = {
76 77 _id: { $oid: account._id.toString() },
77 78 DisplayName: account.DisplayName,
79 LastLogin: toMongoDate(account.LastLogin),
78 80 Rank: 7,
79 81 Status: 2
80 82 };
Modified src/controllers/api/loginController.ts +3 -1
@@ -48,7 +48,8 @@ export const loginController: RequestHandler = async (request, response) => {
48 48 ConsentNeeded: false,
49 49 TrackedSettings: [],
50 50 Nonce: nonce,
51 BuildLabel: buildLabel
51 BuildLabel: buildLabel,
52 LastLogin: new Date()
52 53 });
53 54 logger.debug("created new account");
54 55 response.json(createLoginResponse(myAddress, newAccount, buildLabel));
@@ -93,6 +94,7 @@ export const loginController: RequestHandler = async (request, response) => {
93 94 account.Nonce = nonce;
94 95 account.CountryCode = loginRequest.lang?.toUpperCase() ?? "EN";
95 96 account.BuildLabel = buildLabel;
97 account.LastLogin = new Date();
96 98 }
97 99 await account.save();
98 100
Modified src/helpers/customHelpers/customHelpers.ts +2 -1
@@ -48,7 +48,8 @@ const toDatabaseAccount = (createAccount: IAccountCreation): IDatabaseAccountReq
48 48 CrossPlatformAllowed: true,
49 49 ForceLogoutVersion: 0,
50 50 TrackedSettings: [],
51 Nonce: 0
51 Nonce: 0,
52 LastLogin: new Date()
52 53 } satisfies IDatabaseAccountRequiredFields;
53 54 };
54 55
Modified src/models/loginModel.ts +1 -0
@@ -22,6 +22,7 @@ const databaseAccountSchema = new Schema<IDatabaseAccountJson>(
22 22 Nonce: { type: Number, default: 0 },
23 23 BuildLabel: String,
24 24 Dropped: Boolean,
25 LastLogin: { type: Date, default: 0 },
25 26 LatestEventMessageDate: { type: Date, default: 0 },
26 27 LastLoginRewardDate: { type: Number, default: 0 },
27 28 LoginDays: { type: Number, default: 1 }
Modified src/services/friendService.ts +4 -1
@@ -4,9 +4,12 @@ import { config } from "./configService";
4 4 import { Account } from "../models/loginModel";
5 5 import { Types } from "mongoose";
6 6 import { Friendship } from "../models/friendModel";
7 import { toMongoDate } from "../helpers/inventoryHelpers";
7 8
8 9 export const addAccountDataToFriendInfo = async (info: IFriendInfo): Promise<void> => {
9 info.DisplayName = (await Account.findById(info._id.$oid, "DisplayName"))!.DisplayName;
10 const account = (await Account.findById(info._id.$oid, "DisplayName LastLogin"))!;
11 info.DisplayName = account.DisplayName;
12 info.LastLogin = toMongoDate(account.LastLogin);
10 13 };
11 14
12 15 export const addInventoryDataToFriendInfo = async (info: IFriendInfo): Promise<void> => {
Modified src/types/loginTypes.ts +1 -0
@@ -17,6 +17,7 @@ export interface IDatabaseAccountRequiredFields extends IAccountAndLoginResponse
17 17 email: string;
18 18 password: string;
19 19 BuildLabel?: string;
20 LastLogin: Date;
20 21 }
21 22
22 23 export interface IDatabaseAccount extends IDatabaseAccountRequiredFields {