Custom Rooms + Server global
All checks were successful
Galvanic Corrosion Cross-Compile / build (push) Successful in 49s
All checks were successful
Galvanic Corrosion Cross-Compile / build (push) Successful in 49s
* Added Storage and room saving (will be moved to events later)
* Moved `UnifiedProfile` to new `Server` object, along with `CDN`
- Will move `Rooms` and others to this later
This commit is contained in:
@@ -17,9 +17,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
import { z } from "zod";
|
||||
import { APIUtils, NoBody } from "../../apiutils.ts";
|
||||
import UnifiedProfile from "../../data/profiles.ts";
|
||||
import { AuthType } from "../../data/users.ts";
|
||||
import express from "express";
|
||||
import Server from "../../data/server.ts";
|
||||
|
||||
export const route = APIUtils.createRouter("/playerReputation");
|
||||
|
||||
@@ -35,8 +35,14 @@ route.router.get('/v1/:id',
|
||||
rs.json(APIUtils.genericResponseFormat(true, 'The player ID was invalid.'));
|
||||
return;
|
||||
}
|
||||
|
||||
const profile = Server.UnifiedProfile.get(parsedPlayerId);
|
||||
if (!profile) {
|
||||
rs.status(404).json(APIUtils.genericResponseFormat(true, "Profile not found"));
|
||||
return;
|
||||
}
|
||||
|
||||
rs.json(await UnifiedProfile.get(parsedPlayerId).Reputation.getReputation());
|
||||
rs.json(await profile.Reputation.getReputation());
|
||||
}
|
||||
|
||||
);
|
||||
@@ -61,15 +67,21 @@ route.router.post('/v1/bulk',
|
||||
if (typeof rq.body.Ids == 'object') {
|
||||
const reputations = rq.body.Ids
|
||||
.map(id => parseInt(id)).filter(id => !isNaN(id)) // parse as int[] and filter out non-numbers
|
||||
.map(id => UnifiedProfile.get(id).Reputation.getReputation()); // get all reputations
|
||||
rs.json(await Promise.all(reputations));
|
||||
.map(id => Server.UnifiedProfile.get(id)?.Reputation.getReputation()); // get all reputations
|
||||
rs.json(await Promise.all(reputations.filter(val => val instanceof Promise)));
|
||||
} else {
|
||||
const id = parseInt(rq.body.Ids);
|
||||
if (isNaN(id)) {
|
||||
rs.sendStatus(400);
|
||||
return;
|
||||
}
|
||||
rs.json([await UnifiedProfile.get(id).Reputation.getReputation()]);
|
||||
const profile = Server.UnifiedProfile.get(id);
|
||||
if (!profile) {
|
||||
rs.status(404).json(APIUtils.genericResponseFormat(true, "Profile not found"));
|
||||
return;
|
||||
}
|
||||
|
||||
rs.json([await profile.Reputation.getReputation()]);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -18,9 +18,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
import Logging from "@proxnet/undead-logging";
|
||||
import { APIUtils, NoBody } from "../../apiutils.ts";
|
||||
import express from "express";
|
||||
import UnifiedProfile from "../../data/profiles.ts";
|
||||
import { AuthType } from "../../data/users.ts";
|
||||
import { z } from "zod";
|
||||
import Server from "../../data/server.ts";
|
||||
|
||||
const log = new Logging("ProgressionRoute");
|
||||
|
||||
@@ -40,7 +40,11 @@ route.router.get('/v1/progression/:id',
|
||||
return;
|
||||
}
|
||||
|
||||
const profile = UnifiedProfile.get(parsedPlayerId);
|
||||
const profile = Server.UnifiedProfile.get(parsedPlayerId);
|
||||
if (!profile) {
|
||||
rs.status(404).json(APIUtils.genericResponseFormat(true, "Profile not found"));
|
||||
return;
|
||||
}
|
||||
const res = {
|
||||
PlayerId: profile.getId(),
|
||||
Level: await profile.Progression.getLevel(),
|
||||
@@ -72,15 +76,20 @@ route.router.post('/v1/progression/bulk',
|
||||
if (typeof rq.body.Ids == 'object') {
|
||||
const progressions = rq.body.Ids
|
||||
.map(id => parseInt(id)).filter(id => !isNaN(id)) // filter out non-numbers
|
||||
.map(id => UnifiedProfile.get(id).Progression.export()); // get all progressions
|
||||
rs.json(await Promise.all(progressions));
|
||||
.map(id => Server.UnifiedProfile.get(id)?.Progression.export()); // get all progressions
|
||||
rs.json(await Promise.all(progressions.filter(val => val instanceof Promise)));
|
||||
} else {
|
||||
const id = parseInt(rq.body.Ids);
|
||||
if (isNaN(id)) {
|
||||
rs.sendStatus(400);
|
||||
return;
|
||||
}
|
||||
rs.json([await UnifiedProfile.get(id).Progression.export()]);
|
||||
const profile = Server.UnifiedProfile.get(id);
|
||||
if (!profile) {
|
||||
rs.status(404).json(APIUtils.genericResponseFormat(true, "Profile not found"));
|
||||
return;
|
||||
}
|
||||
rs.json([await profile.Progression.export()]);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -18,10 +18,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
import { z } from "zod";
|
||||
import { APIUtils, NoBody } from "../../apiutils.ts";
|
||||
import Rooms from "../../data/content/rooms.ts";
|
||||
import { RoomDataTypes } from "../../data/content/rooms/DataTypes.ts";
|
||||
import { FactoryMode, RoomDataTypes, WriteMode } from "../../data/content/rooms/DataTypes.ts";
|
||||
import { AuthType } from "../../data/users.ts";
|
||||
import express from "express";
|
||||
import { RoomFactory } from "../../data/content/rooms/RoomFactory.ts";
|
||||
import { SubroomFactory } from "../../data/content/rooms/SubroomFactory.ts";
|
||||
import Logging from "@proxnet/undead-logging";
|
||||
|
||||
const log = new Logging("RoomsRoute");
|
||||
|
||||
export const route = APIUtils.createRouter("/rooms");
|
||||
|
||||
@@ -187,4 +191,69 @@ route.router.post('/v1/clone',
|
||||
|
||||
},
|
||||
|
||||
);
|
||||
|
||||
const CreatorActionContextScheme = z.object({
|
||||
IsTeachableMomentRunning: z.boolean()
|
||||
});
|
||||
const SaveDataScheme = z.object({
|
||||
RoomSceneId: z.number(),
|
||||
RoomDataFilename: z.string().min(6).max(128),
|
||||
InventionUsages: z.array(z.number()),
|
||||
CreatorActionContext: CreatorActionContextScheme,
|
||||
RequestPlayerId: z.number()
|
||||
});
|
||||
interface CreatorActionContextBody {
|
||||
IsTeachableMomentRunning: boolean
|
||||
}
|
||||
interface SaveDataBody {
|
||||
CreatorActionContext: CreatorActionContextBody,
|
||||
InventionUsages: number[],
|
||||
RequestPlayerId: number,
|
||||
RoomDataFilename: string,
|
||||
RoomSceneId: number
|
||||
}
|
||||
route.router.post('/v4/saveData',
|
||||
|
||||
APIUtils.Authentication,
|
||||
APIUtils.AuthenticationType(AuthType.Game),
|
||||
express.json(),
|
||||
APIUtils.validateRequestBody(SaveDataScheme),
|
||||
|
||||
async (rq: express.Request<NoBody, NoBody, SaveDataBody>, rs: express.Response) => {
|
||||
|
||||
log.d(`Request to save: '${rq.body.RoomDataFilename}'`);
|
||||
|
||||
const currentInstance = rs.locals.profile.getInstance();
|
||||
if (!currentInstance) {
|
||||
rs.status(400).json(APIUtils.genericResponseFormat(true, "Player not currently in a room"));
|
||||
return;
|
||||
}
|
||||
|
||||
const subroomFactory = await new SubroomFactory({
|
||||
roomId: currentInstance.roomId,
|
||||
subroomId: rq.body.RoomSceneId,
|
||||
factoryMode: FactoryMode.Write,
|
||||
writeMode: WriteMode.Overwrite
|
||||
}).init();
|
||||
|
||||
const splitFilename = rq.body.RoomDataFilename.split('/');
|
||||
const newFilename = splitFilename[splitFilename.length - 1];
|
||||
if (!newFilename) {
|
||||
rs.sendStatus(400);
|
||||
log.e(`New filename was invalid: '${newFilename}'`);
|
||||
} else {
|
||||
subroomFactory.DataBlobName = newFilename;
|
||||
subroomFactory.addBlobHistory(new Date(), newFilename);
|
||||
|
||||
await subroomFactory.write();
|
||||
|
||||
rs.json(subroomFactory.export());
|
||||
|
||||
currentInstance.dataBlob = newFilename;
|
||||
currentInstance.updatePlayers();
|
||||
Rooms.socketUpdateRoom(currentInstance);
|
||||
}
|
||||
},
|
||||
|
||||
);
|
||||
Reference in New Issue
Block a user