feat: more work on clans (#214)

Co-authored-by: Sainan <Sainan@users.noreply.github.com>
This commit is contained in:
Sainan 2024-05-16 01:34:38 +02:00 committed by GitHub
parent 6dd5ceabde
commit 63712121af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 183 additions and 15 deletions

View File

@ -2,7 +2,7 @@ import { RequestHandler } from "express";
import { getJSONfromString } from "@/src/helpers/stringHelpers";
import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
import { Guild } from "@/src/models/guildModel";
import { IGuild, ICreateGuildRequest } from "@/src/types/guildTypes";
import { ICreateGuildRequest } from "@/src/types/guildTypes";
const createGuildController: RequestHandler = async (req, res) => {
const payload: ICreateGuildRequest = getJSONfromString(req.body.toString());
@ -10,7 +10,7 @@ const createGuildController: RequestHandler = async (req, res) => {
// Create guild on database
const guild = new Guild({
Name: payload.guildName
} satisfies IGuild);
});
await guild.save();
// Update inventory
@ -19,7 +19,7 @@ const createGuildController: RequestHandler = async (req, res) => {
// Set GuildId
inventory.GuildId = guild._id;
// Give clan key
// Give clan key (TODO: This should only be a blueprint)
inventory.LevelKeys ??= [];
inventory.LevelKeys.push({
ItemType: "/Lotus/Types/Keys/DojoKey",

View File

@ -0,0 +1,5 @@
import { RequestHandler } from "express";
export const dojoController: RequestHandler = (_req, res) => {
res.json("-1"); // Tell client to use authorised request.
};

View File

@ -1,6 +1,7 @@
import { RequestHandler } from "express";
import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
import { Guild } from "@/src/models/guildModel";
import { toOid } from "@/src/helpers/inventoryHelpers";
const getGuildController: RequestHandler = async (req, res) => {
if (!req.query.accountId) {
@ -15,7 +16,56 @@ const getGuildController: RequestHandler = async (req, res) => {
if (inventory.GuildId) {
const guild = await Guild.findOne({ _id: inventory.GuildId });
if (guild) {
res.json(guild);
res.json({
_id: toOid(guild._id),
Name: guild.Name,
Members: [
{
_id: { $oid: req.query.accountId },
Rank: 0,
Status: 0
}
],
Ranks: [
{
Name: "/Lotus/Language/Game/Rank_Creator",
Permissions: 16351
},
{
Name: "/Lotus/Language/Game/Rank_Warlord",
Permissions: 14303
},
{
Name: "/Lotus/Language/Game/Rank_General",
Permissions: 4318
},
{
Name: "/Lotus/Language/Game/Rank_Officer",
Permissions: 4314
},
{
Name: "/Lotus/Language/Game/Rank_Leader",
Permissions: 4106
},
{
Name: "/Lotus/Language/Game/Rank_Sage",
Permissions: 4304
},
{
Name: "/Lotus/Language/Game/Rank_Soldier",
Permissions: 4098
},
{
Name: "/Lotus/Language/Game/Rank_Initiate",
Permissions: 4096
},
{
Name: "/Lotus/Language/Game/Rank_Utility",
Permissions: 4096
}
],
Tier: 1
});
return;
}
}

View File

@ -0,0 +1,51 @@
import { RequestHandler } from "express";
import { Types } from "mongoose";
import { Guild } from "@/src/models/guildModel";
import { IDojoClient } from "@/src/types/guildTypes";
import { toOid, toMongoDate } from "@/src/helpers/inventoryHelpers";
export const getGuildDojoController: RequestHandler = async (req, res) => {
const guildId = req.query.guildId as string;
const guild = await Guild.findOne({ _id: guildId });
if (!guild) {
res.status(404).end();
return;
}
// Populate dojo info if not present
if (!guild.DojoComponents || guild.DojoComponents.length == 0) {
guild.DojoComponents = [
{
_id: new Types.ObjectId(),
pf: "/Lotus/Levels/ClanDojo/DojoHall.level",
ppf: "",
CompletionTime: new Date(Date.now())
}
];
guild.save();
}
const dojo: IDojoClient = {
_id: { $oid: guildId },
Name: guild.Name,
Tier: 1,
FixedContributions: true,
DojoRevision: 1,
RevisionTime: Math.round(Date.now() / 1000),
Energy: 5,
Capacity: 100,
DojoRequestStatus: 0,
DojoComponents: []
};
guild.DojoComponents.forEach(dojoComponent => {
dojo.DojoComponents.push({
id: toOid(dojoComponent._id),
pf: dojoComponent.pf,
ppf: dojoComponent.ppf,
CompletionTime: toMongoDate(dojoComponent.CompletionTime),
DecoCapacity: 600
});
});
res.json(dojo);
};

View File

@ -0,0 +1,11 @@
import { RequestHandler } from "express";
export const getGuildLogController: RequestHandler = (_req, res) => {
res.json({
RoomChanges: [],
TechChanges: [],
RosterActivity: [],
StandingsUpdates: [],
ClassChanges: []
});
};

View File

@ -0,0 +1,5 @@
import { RequestHandler } from "express";
export const guildTechController: RequestHandler = (_req, res) => {
res.status(500).end(); // This is what I got for a fresh clan.
};

View File

@ -1,16 +1,18 @@
import { IGuild } from "@/src/types/guildTypes";
import { IGuildDatabase, IDojoComponentDatabase } from "@/src/types/guildTypes";
import { model, Schema } from "mongoose";
import { toOid } from "@/src/helpers/inventoryHelpers";
const guildSchema = new Schema<IGuild>({
Name: { type: String, required: true }
const dojoComponentSchema = new Schema<IDojoComponentDatabase>({
pf: { type: String, required: true },
ppf: String,
CompletionTime: Date
});
guildSchema.set("toJSON", {
virtuals: true,
transform(_document, guild) {
guild._id = toOid(guild._id);
}
});
const guildSchema = new Schema<IGuildDatabase>(
{
Name: { type: String, required: true },
DojoComponents: [dojoComponentSchema]
},
{ id: false }
);
export const Guild = model<IGuild>("Guild", guildSchema);
export const Guild = model<IGuildDatabase>("Guild", guildSchema);

View File

@ -48,6 +48,10 @@ import { sellController } from "@/src/controllers/api/sellController";
import { upgradesController } from "@/src/controllers/api/upgradesController";
import { setSupportedSyndicateController } from "@/src/controllers/api/setSupportedSyndicateController";
import { getDailyDealStockLevelsController } from "@/src/controllers/api/getDailyDealStockLevelsController";
import { getGuildLogController } from "../controllers/api/getGuildLogController";
import { guildTechController } from "../controllers/api/guildTechController";
import { dojoController } from "@/src/controllers/api/dojoController";
import { getGuildDojoController } from "@/src/controllers/api/getGuildDojoController";
const apiRouter = express.Router();
@ -77,6 +81,9 @@ apiRouter.get("/setActiveShip.php", setActiveShipController);
apiRouter.get("/getGuild.php", getGuildController);
apiRouter.get("/setSupportedSyndicate.php", setSupportedSyndicateController);
apiRouter.get("/getDailyDealStockLevels.php", getDailyDealStockLevelsController);
apiRouter.get("/getGuildLog.php", getGuildLogController);
apiRouter.get("/dojo", dojoController);
apiRouter.get("/getGuildDojo.php", getGuildDojoController);
// post
// eslint-disable-next-line @typescript-eslint/no-misused-promises
@ -106,5 +113,6 @@ apiRouter.post("/addFriendImage.php", addFriendImageController);
apiRouter.post("/createGuild.php", createGuildController);
apiRouter.post("/sell.php", sellController);
apiRouter.post("/upgrades.php", upgradesController);
apiRouter.post("/guildTech.php", guildTechController);
export { apiRouter };

View File

@ -1,7 +1,43 @@
import { Types } from "mongoose";
import { IOid, IMongoDate } from "@/src/types/commonTypes";
export interface IGuild {
Name: string;
}
export interface IGuildDatabase extends IGuild {
_id: Types.ObjectId;
DojoComponents?: IDojoComponentDatabase[];
}
export interface ICreateGuildRequest {
guildName: string;
}
export interface IDojoClient {
_id: IOid; // ID of the guild
Name: string;
Tier: number;
FixedContributions: boolean;
DojoRevision: number;
RevisionTime: number;
Energy: number;
Capacity: number;
DojoRequestStatus: number;
DojoComponents: IDojoComponentClient[];
}
export interface IDojoComponentClient {
id: IOid;
pf: string;
ppf: string;
CompletionTime: IMongoDate;
DecoCapacity: number;
}
export interface IDojoComponentDatabase {
_id: Types.ObjectId;
pf: string;
ppf: string;
CompletionTime: Date;
}