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: clan motd (#1134)

Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1134

0ffa9c6b
Sainan <sainan@calamity.inc>
提交于

代码差异

8 个文件 +77 -1
Modified package-lock.json +12 -0
@@ -10,6 +10,7 @@
10 10 "license": "GNU",
11 11 "dependencies": {
12 12 "copyfiles": "^2.4.1",
13 "crc-32": "^1.2.2",
13 14 "express": "^5",
14 15 "mongoose": "^8.11.0",
15 16 "warframe-public-export-plus": "^0.5.42",
@@ -1249,6 +1250,17 @@
1249 1250 "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==",
1250 1251 "license": "MIT"
1251 1252 },
1253 "node_modules/crc-32": {
1254 "version": "1.2.2",
1255 "resolved": "https://registry.npmjs.org/crc-32/-/crc-32-1.2.2.tgz",
1256 "integrity": "sha512-ROmzCKrTnOwybPcJApAA6WBWij23HVfGVNKqqrZpuyZOHqK2CwHSvpGuyt/UNNvaIjEd8X5IFGp4Mh+Ie1IHJQ==",
1257 "bin": {
1258 "crc32": "bin/crc32.njs"
1259 },
1260 "engines": {
1261 "node": ">=0.8"
1262 }
1263 },
1252 1264 "node_modules/create-require": {
1253 1265 "version": "1.1.1",
1254 1266 "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz",
Modified package.json +1 -0
@@ -17,6 +17,7 @@
17 17 "@types/express": "^5",
18 18 "@types/morgan": "^1.9.9",
19 19 "copyfiles": "^2.4.1",
20 "crc-32": "^1.2.2",
20 21 "express": "^5",
21 22 "mongoose": "^8.11.0",
22 23 "morgan": "^1.10.0",
Modified src/controllers/api/getGuildController.ts +2 -0
@@ -26,6 +26,8 @@ const getGuildController: RequestHandler = async (req, res) => {
26 26 res.json({
27 27 _id: toOid(guild._id),
28 28 Name: guild.Name,
29 MOTD: guild.MOTD,
30 LongMOTD: guild.LongMOTD,
29 31 Members: [
30 32 {
31 33 _id: { $oid: req.query.accountId },
Added src/controllers/api/setGuildMotdController.ts +30 -0
@@ -0,0 +1,30 @@
1 import { Guild } from "@/src/models/guildModel";
2 import { getInventory } from "@/src/services/inventoryService";
3 import { getAccountForRequest, getSuffixedName } from "@/src/services/loginService";
4 import { RequestHandler } from "express";
5
6 export const setGuildMotdController: RequestHandler = async (req, res) => {
7 const account = await getAccountForRequest(req);
8 const inventory = await getInventory(account._id.toString());
9 const guild = (await Guild.findOne({ _id: inventory.GuildId! }))!;
10 // TODO: Check permissions
11
12 const IsLongMOTD = "longMOTD" in req.query;
13 const MOTD = req.body ? String(req.body) : undefined;
14
15 if (IsLongMOTD) {
16 if (MOTD) {
17 guild.LongMOTD = {
18 message: MOTD,
19 authorName: getSuffixedName(account)
20 };
21 } else {
22 guild.LongMOTD = undefined;
23 }
24 } else {
25 guild.MOTD = MOTD ?? "";
26 }
27 await guild.save();
28
29 res.json({ IsLongMOTD, MOTD });
30 };
Modified src/models/guildModel.ts +12 -1
@@ -3,7 +3,8 @@ import {
3 3 IDojoComponentDatabase,
4 4 ITechProjectDatabase,
5 5 ITechProjectClient,
6 IDojoDecoDatabase
6 IDojoDecoDatabase,
7 ILongMOTD
7 8 } from "@/src/types/guildTypes";
8 9 import { Document, Model, model, Schema, Types } from "mongoose";
9 10 import { fusionTreasuresSchema, typeCountSchema } from "./inventoryModels/inventoryModel";
@@ -59,9 +60,19 @@ techProjectSchema.set("toJSON", {
59 60 }
60 61 });
61 62
63 const longMOTDSchema = new Schema<ILongMOTD>(
64 {
65 message: String,
66 authorName: String
67 },
68 { _id: false }
69 );
70
62 71 const guildSchema = new Schema<IGuildDatabase>(
63 72 {
64 73 Name: { type: String, required: true },
74 MOTD: { type: String, default: "" },
75 LongMOTD: { type: longMOTDSchema, default: undefined },
65 76 DojoComponents: { type: [dojoComponentSchema], default: [] },
66 77 DojoCapacity: { type: Number, default: 100 },
67 78 DojoEnergy: { type: Number, default: 5 },
Modified src/routes/api.ts +3 -0
@@ -79,6 +79,7 @@ import { setActiveShipController } from "@/src/controllers/api/setActiveShipCont
79 79 import { setBootLocationController } from "@/src/controllers/api/setBootLocationController";
80 80 import { setDojoComponentMessageController } from "@/src/controllers/api/setDojoComponentMessageController";
81 81 import { setEquippedInstrumentController } from "@/src/controllers/api/setEquippedInstrumentController";
82 import { setGuildMotdController } from "@/src/controllers/api/setGuildMotdController";
82 83 import { setPlacedDecoInfoController } from "@/src/controllers/api/setPlacedDecoInfoController";
83 84 import { setShipCustomizationsController } from "@/src/controllers/api/setShipCustomizationsController";
84 85 import { setShipFavouriteLoadoutController } from "@/src/controllers/api/setShipFavouriteLoadoutController";
@@ -138,6 +139,7 @@ apiRouter.get("/queueDojoComponentDestruction.php", queueDojoComponentDestructio
138 139 apiRouter.get("/setActiveQuest.php", setActiveQuestController);
139 140 apiRouter.get("/setActiveShip.php", setActiveShipController);
140 141 apiRouter.get("/setBootLocation.php", setBootLocationController);
142 apiRouter.get("/setGuildMotd.php", setGuildMotdController);
141 143 apiRouter.get("/setSupportedSyndicate.php", setSupportedSyndicateController);
142 144 apiRouter.get("/startLibraryDailyTask.php", startLibraryDailyTaskController);
143 145 apiRouter.get("/startLibraryPersonalTarget.php", startLibraryPersonalTargetController);
@@ -197,6 +199,7 @@ apiRouter.post("/saveSettings.php", saveSettingsController);
197 199 apiRouter.post("/sell.php", sellController);
198 200 apiRouter.post("/setDojoComponentMessage.php", setDojoComponentMessageController);
199 201 apiRouter.post("/setEquippedInstrument.php", setEquippedInstrumentController);
202 apiRouter.post("/setGuildMotd.php", setGuildMotdController);
200 203 apiRouter.post("/setPlacedDecoInfo.php", setPlacedDecoInfoController);
201 204 apiRouter.post("/setShipCustomizations.php", setShipCustomizationsController);
202 205 apiRouter.post("/setShipFavouriteLoadout.php", setShipFavouriteLoadoutController);
Modified src/services/loginService.ts +9 -0
@@ -8,6 +8,7 @@ import { PersonalRooms } from "@/src/models/personalRoomsModel";
8 8 import { Request } from "express";
9 9 import { config } from "@/src/services/configService";
10 10 import { createStats } from "@/src/services/statsService";
11 import crc32 from "crc-32";
11 12
12 13 export const isCorrectPassword = (requestPassword: string, databasePassword: string): boolean => {
13 14 return requestPassword === databasePassword;
@@ -99,3 +100,11 @@ export const isAdministrator = (account: TAccountDocument): boolean => {
99 100 }
100 101 return !!config.administratorNames.find(x => x == account.DisplayName);
101 102 };
103
104 const platform_magics = [753, 639, 247, 37, 60];
105 export const getSuffixedName = (account: TAccountDocument): string => {
106 const name = account.DisplayName;
107 const platformId = 0;
108 const suffix = ((crc32.str(name.toLowerCase() + "595") >>> 0) + platform_magics[platformId]) % 1000;
109 return name + "#" + suffix.toString().padStart(3, "0");
110 };
Modified src/types/guildTypes.ts +8 -0
@@ -5,6 +5,8 @@ import { IFusionTreasure, IMiscItem, ITypeCount } from "@/src/types/inventoryTyp
5 5 export interface IGuildDatabase {
6 6 _id: Types.ObjectId;
7 7 Name: string;
8 MOTD: string;
9 LongMOTD?: ILongMOTD;
8 10
9 11 DojoComponents: IDojoComponentDatabase[];
10 12 DojoCapacity: number;
@@ -27,6 +29,12 @@ export interface IGuildDatabase {
27 29 CeremonyResetDate?: Date;
28 30 }
29 31
32 export interface ILongMOTD {
33 message: string;
34 authorName: string;
35 //authorGuildName: "";
36 }
37
30 38 export interface IGuildVault {
31 39 DojoRefundRegularCredits?: number;
32 40 DojoRefundMiscItems?: IMiscItem[];