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: more work on clans (#214)

Co-authored-by: Sainan <Sainan@users.noreply.github.com>

63712121
Sainan <sainan@calamity.gg>
提交于

代码差异

9 个文件 +183 -15
Modified src/controllers/api/createGuildController.ts +3 -3
@@ -2,7 +2,7 @@ import { RequestHandler } from "express";
2 2 import { getJSONfromString } from "@/src/helpers/stringHelpers";
3 3 import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
4 4 import { Guild } from "@/src/models/guildModel";
5 import { IGuild, ICreateGuildRequest } from "@/src/types/guildTypes";
5 import { ICreateGuildRequest } from "@/src/types/guildTypes";
6 6
7 7 const createGuildController: RequestHandler = async (req, res) => {
8 8 const payload: ICreateGuildRequest = getJSONfromString(req.body.toString());
@@ -10,7 +10,7 @@ const createGuildController: RequestHandler = async (req, res) => {
10 10 // Create guild on database
11 11 const guild = new Guild({
12 12 Name: payload.guildName
13 } satisfies IGuild);
13 });
14 14 await guild.save();
15 15
16 16 // Update inventory
@@ -19,7 +19,7 @@ const createGuildController: RequestHandler = async (req, res) => {
19 19 // Set GuildId
20 20 inventory.GuildId = guild._id;
21 21
22 // Give clan key
22 // Give clan key (TODO: This should only be a blueprint)
23 23 inventory.LevelKeys ??= [];
24 24 inventory.LevelKeys.push({
25 25 ItemType: "/Lotus/Types/Keys/DojoKey",
Added src/controllers/api/dojoController.ts +5 -0
@@ -0,0 +1,5 @@
1 import { RequestHandler } from "express";
2
3 export const dojoController: RequestHandler = (_req, res) => {
4 res.json("-1"); // Tell client to use authorised request.
5 };
Modified src/controllers/api/getGuildController.ts +51 -1
@@ -1,6 +1,7 @@
1 1 import { RequestHandler } from "express";
2 2 import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
3 3 import { Guild } from "@/src/models/guildModel";
4 import { toOid } from "@/src/helpers/inventoryHelpers";
4 5
5 6 const getGuildController: RequestHandler = async (req, res) => {
6 7 if (!req.query.accountId) {
@@ -15,7 +16,56 @@ const getGuildController: RequestHandler = async (req, res) => {
15 16 if (inventory.GuildId) {
16 17 const guild = await Guild.findOne({ _id: inventory.GuildId });
17 18 if (guild) {
18 res.json(guild);
19 res.json({
20 _id: toOid(guild._id),
21 Name: guild.Name,
22 Members: [
23 {
24 _id: { $oid: req.query.accountId },
25 Rank: 0,
26 Status: 0
27 }
28 ],
29 Ranks: [
30 {
31 Name: "/Lotus/Language/Game/Rank_Creator",
32 Permissions: 16351
33 },
34 {
35 Name: "/Lotus/Language/Game/Rank_Warlord",
36 Permissions: 14303
37 },
38 {
39 Name: "/Lotus/Language/Game/Rank_General",
40 Permissions: 4318
41 },
42 {
43 Name: "/Lotus/Language/Game/Rank_Officer",
44 Permissions: 4314
45 },
46 {
47 Name: "/Lotus/Language/Game/Rank_Leader",
48 Permissions: 4106
49 },
50 {
51 Name: "/Lotus/Language/Game/Rank_Sage",
52 Permissions: 4304
53 },
54 {
55 Name: "/Lotus/Language/Game/Rank_Soldier",
56 Permissions: 4098
57 },
58 {
59 Name: "/Lotus/Language/Game/Rank_Initiate",
60 Permissions: 4096
61 },
62 {
63 Name: "/Lotus/Language/Game/Rank_Utility",
64 Permissions: 4096
65 }
66 ],
67 Tier: 1
68 });
19 69 return;
20 70 }
21 71 }
Added src/controllers/api/getGuildDojoController.ts +51 -0
@@ -0,0 +1,51 @@
1 import { RequestHandler } from "express";
2 import { Types } from "mongoose";
3 import { Guild } from "@/src/models/guildModel";
4 import { IDojoClient } from "@/src/types/guildTypes";
5 import { toOid, toMongoDate } from "@/src/helpers/inventoryHelpers";
6
7 export const getGuildDojoController: RequestHandler = async (req, res) => {
8 const guildId = req.query.guildId as string;
9
10 const guild = await Guild.findOne({ _id: guildId });
11 if (!guild) {
12 res.status(404).end();
13 return;
14 }
15
16 // Populate dojo info if not present
17 if (!guild.DojoComponents || guild.DojoComponents.length == 0) {
18 guild.DojoComponents = [
19 {
20 _id: new Types.ObjectId(),
21 pf: "/Lotus/Levels/ClanDojo/DojoHall.level",
22 ppf: "",
23 CompletionTime: new Date(Date.now())
24 }
25 ];
26 guild.save();
27 }
28
29 const dojo: IDojoClient = {
30 _id: { $oid: guildId },
31 Name: guild.Name,
32 Tier: 1,
33 FixedContributions: true,
34 DojoRevision: 1,
35 RevisionTime: Math.round(Date.now() / 1000),
36 Energy: 5,
37 Capacity: 100,
38 DojoRequestStatus: 0,
39 DojoComponents: []
40 };
41 guild.DojoComponents.forEach(dojoComponent => {
42 dojo.DojoComponents.push({
43 id: toOid(dojoComponent._id),
44 pf: dojoComponent.pf,
45 ppf: dojoComponent.ppf,
46 CompletionTime: toMongoDate(dojoComponent.CompletionTime),
47 DecoCapacity: 600
48 });
49 });
50 res.json(dojo);
51 };
Added src/controllers/api/getGuildLogController.ts +11 -0
@@ -0,0 +1,11 @@
1 import { RequestHandler } from "express";
2
3 export const getGuildLogController: RequestHandler = (_req, res) => {
4 res.json({
5 RoomChanges: [],
6 TechChanges: [],
7 RosterActivity: [],
8 StandingsUpdates: [],
9 ClassChanges: []
10 });
11 };
Added src/controllers/api/guildTechController.ts +5 -0
@@ -0,0 +1,5 @@
1 import { RequestHandler } from "express";
2
3 export const guildTechController: RequestHandler = (_req, res) => {
4 res.status(500).end(); // This is what I got for a fresh clan.
5 };
Modified src/models/guildModel.ts +13 -11
@@ -1,16 +1,18 @@
1 import { IGuild } from "@/src/types/guildTypes";
1 import { IGuildDatabase, IDojoComponentDatabase } from "@/src/types/guildTypes";
2 2 import { model, Schema } from "mongoose";
3 import { toOid } from "@/src/helpers/inventoryHelpers";
4 3
5 const guildSchema = new Schema<IGuild>({
6 Name: { type: String, required: true }
4 const dojoComponentSchema = new Schema<IDojoComponentDatabase>({
5 pf: { type: String, required: true },
6 ppf: String,
7 CompletionTime: Date
7 8 });
8 9
9 guildSchema.set("toJSON", {
10 virtuals: true,
11 transform(_document, guild) {
12 guild._id = toOid(guild._id);
13 }
14 });
10 const guildSchema = new Schema<IGuildDatabase>(
11 {
12 Name: { type: String, required: true },
13 DojoComponents: [dojoComponentSchema]
14 },
15 { id: false }
16 );
15 17
16 export const Guild = model<IGuild>("Guild", guildSchema);
18 export const Guild = model<IGuildDatabase>("Guild", guildSchema);
Modified src/routes/api.ts +8 -0
@@ -48,6 +48,10 @@ import { sellController } from "@/src/controllers/api/sellController";
48 48 import { upgradesController } from "@/src/controllers/api/upgradesController";
49 49 import { setSupportedSyndicateController } from "@/src/controllers/api/setSupportedSyndicateController";
50 50 import { getDailyDealStockLevelsController } from "@/src/controllers/api/getDailyDealStockLevelsController";
51 import { getGuildLogController } from "../controllers/api/getGuildLogController";
52 import { guildTechController } from "../controllers/api/guildTechController";
53 import { dojoController } from "@/src/controllers/api/dojoController";
54 import { getGuildDojoController } from "@/src/controllers/api/getGuildDojoController";
51 55
52 56 const apiRouter = express.Router();
53 57
@@ -77,6 +81,9 @@ apiRouter.get("/setActiveShip.php", setActiveShipController);
77 81 apiRouter.get("/getGuild.php", getGuildController);
78 82 apiRouter.get("/setSupportedSyndicate.php", setSupportedSyndicateController);
79 83 apiRouter.get("/getDailyDealStockLevels.php", getDailyDealStockLevelsController);
84 apiRouter.get("/getGuildLog.php", getGuildLogController);
85 apiRouter.get("/dojo", dojoController);
86 apiRouter.get("/getGuildDojo.php", getGuildDojoController);
80 87
81 88 // post
82 89 // eslint-disable-next-line @typescript-eslint/no-misused-promises
@@ -106,5 +113,6 @@ apiRouter.post("/addFriendImage.php", addFriendImageController);
106 113 apiRouter.post("/createGuild.php", createGuildController);
107 114 apiRouter.post("/sell.php", sellController);
108 115 apiRouter.post("/upgrades.php", upgradesController);
116 apiRouter.post("/guildTech.php", guildTechController);
109 117
110 118 export { apiRouter };
Modified src/types/guildTypes.ts +36 -0
@@ -1,7 +1,43 @@
1 import { Types } from "mongoose";
2 import { IOid, IMongoDate } from "@/src/types/commonTypes";
3
1 4 export interface IGuild {
2 5 Name: string;
3 6 }
4 7
8 export interface IGuildDatabase extends IGuild {
9 _id: Types.ObjectId;
10 DojoComponents?: IDojoComponentDatabase[];
11 }
12
5 13 export interface ICreateGuildRequest {
6 14 guildName: string;
7 15 }
16
17 export interface IDojoClient {
18 _id: IOid; // ID of the guild
19 Name: string;
20 Tier: number;
21 FixedContributions: boolean;
22 DojoRevision: number;
23 RevisionTime: number;
24 Energy: number;
25 Capacity: number;
26 DojoRequestStatus: number;
27 DojoComponents: IDojoComponentClient[];
28 }
29
30 export interface IDojoComponentClient {
31 id: IOid;
32 pf: string;
33 ppf: string;
34 CompletionTime: IMongoDate;
35 DecoCapacity: number;
36 }
37
38 export interface IDojoComponentDatabase {
39 _id: Types.ObjectId;
40 pf: string;
41 ppf: string;
42 CompletionTime: Date;
43 }