Release Healer Man 0.1.6
This commit is contained in:
+58
-1
@@ -3,6 +3,7 @@ import { createServer } from "node:http";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { GameDatabaseError, openGameDatabase } from "./database.mjs";
|
||||
import { createOnlineSessionManager } from "./online-session.mjs";
|
||||
|
||||
const MIME_TYPES = new Map([
|
||||
[".css", "text/css; charset=utf-8"], [".glb", "model/gltf-binary"],
|
||||
@@ -148,6 +149,7 @@ export function createGameServer(options = {}) {
|
||||
const bodyLimit = Math.max(1024, Number(options.bodyLimit ?? process.env.MAX_JSON_BODY_BYTES ?? 5 * 1024 * 1024));
|
||||
const trustProxy = String(options.trustProxy ?? process.env.TRUST_PROXY ?? "").toLowerCase() === "true";
|
||||
const gameDatabase = options.database ?? openGameDatabase(options);
|
||||
const onlineSessions = createOnlineSessionManager();
|
||||
const allowAuthRequest = createAuthLimiter();
|
||||
gameDatabase.pruneExpiredSessions();
|
||||
|
||||
@@ -209,6 +211,58 @@ export function createGameServer(options = {}) {
|
||||
json(response, 200, gameDatabase.putCloudSave(account.id, body.data));
|
||||
return;
|
||||
}
|
||||
if (url.pathname === "/api/online-group" && request.method === "GET") {
|
||||
const account = gameDatabase.authenticate(bearerToken(request));
|
||||
json(response, 200, gameDatabase.onlineGroupState(account.id));
|
||||
return;
|
||||
}
|
||||
if (url.pathname === "/api/online-group/invite" && request.method === "POST") {
|
||||
const account = gameDatabase.authenticate(bearerToken(request));
|
||||
const body = await readJson(request, 64 * 1024);
|
||||
json(response, 201, gameDatabase.inviteOnlineGroupMember(account, body.username));
|
||||
return;
|
||||
}
|
||||
if (url.pathname === "/api/online-group/invite/respond" && request.method === "POST") {
|
||||
const account = gameDatabase.authenticate(bearerToken(request));
|
||||
const body = await readJson(request, 64 * 1024);
|
||||
json(response, 200, gameDatabase.respondToOnlineGroupInvite(account.id, body.inviteId, body.accept === true));
|
||||
return;
|
||||
}
|
||||
if (url.pathname === "/api/online-group/leave" && request.method === "POST") {
|
||||
const account = gameDatabase.authenticate(bearerToken(request));
|
||||
json(response, 200, gameDatabase.leaveOnlineGroup(account.id));
|
||||
return;
|
||||
}
|
||||
if (url.pathname === "/api/online-group/remove" && request.method === "POST") {
|
||||
const account = gameDatabase.authenticate(bearerToken(request));
|
||||
const body = await readJson(request, 64 * 1024);
|
||||
json(response, 200, gameDatabase.removeOnlineGroupMember(account.id, body.accountId));
|
||||
return;
|
||||
}
|
||||
if (url.pathname === "/api/online-group/member" && request.method === "PUT") {
|
||||
const account = gameDatabase.authenticate(bearerToken(request));
|
||||
const body = await readJson(request, 64 * 1024);
|
||||
json(response, 200, gameDatabase.updateOnlineGroupMember(account.id, body.character, body.role));
|
||||
return;
|
||||
}
|
||||
if (url.pathname === "/api/online-group/activity" && request.method === "POST") {
|
||||
const account = gameDatabase.authenticate(bearerToken(request));
|
||||
const body = await readJson(request, 64 * 1024);
|
||||
json(response, 200, gameDatabase.startOnlineGroupActivity(account.id, body));
|
||||
return;
|
||||
}
|
||||
if (url.pathname === "/api/online-group/activity/clear" && request.method === "POST") {
|
||||
const account = gameDatabase.authenticate(bearerToken(request));
|
||||
json(response, 200, gameDatabase.clearOnlineGroupActivity(account.id));
|
||||
return;
|
||||
}
|
||||
if (url.pathname === "/api/online-session/sync" && request.method === "POST") {
|
||||
const account = gameDatabase.authenticate(bearerToken(request));
|
||||
const body = await readJson(request, bodyLimit);
|
||||
const groupSnapshot = gameDatabase.onlineGroupState(account.id);
|
||||
json(response, 200, onlineSessions.sync(account, groupSnapshot, body));
|
||||
return;
|
||||
}
|
||||
if (url.pathname === "/api/manastorm-config" && request.method === "GET") {
|
||||
const current = gameDatabase.getManastormConfig();
|
||||
json(response, 200, {
|
||||
@@ -259,7 +313,10 @@ export function createGameServer(options = {}) {
|
||||
}
|
||||
});
|
||||
|
||||
server.on("close", () => gameDatabase.close());
|
||||
server.on("close", () => {
|
||||
onlineSessions.clear();
|
||||
gameDatabase.close();
|
||||
});
|
||||
return { server, database: gameDatabase, staticDir, contentDir };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user