Secure actor-owned game API routes

This commit is contained in:
2026-07-25 08:50:41 +00:00
parent 6889c463fd
commit a9d6541c18
13 changed files with 301 additions and 118 deletions
+11 -3
View File
@@ -1,18 +1,23 @@
import { TRPCError } from '@trpc/server';
import { z } from 'zod';
import type { WorldStateRow } from '../../context.js';
import {
type WorldStateRow,
zWorldStateConfig,
zWorldStateMeta,
} from '../../context.js';
import { procedure, router } from '../../trpc.js';
import { loadWorldMap } from '../../maps/worldMap.js';
import { loadMapLayout } from '../../maps/mapLayout.js';
import { getOwnedGeneral } from '../shared/general.js';
const toWorldStateSnapshot = (row: WorldStateRow) => ({
scenarioCode: row.scenarioCode,
currentYear: row.currentYear,
currentMonth: row.currentMonth,
tickSeconds: row.tickSeconds,
config: row.config,
meta: row.meta,
config: zWorldStateConfig.parse(row.config),
meta: zWorldStateMeta.parse(row.meta),
updatedAt: row.updatedAt.toISOString(),
});
@@ -34,6 +39,9 @@ export const worldRouter = router({
})
)
.query(async ({ ctx, input }) => {
if (input.generalId !== undefined) {
await getOwnedGeneral(ctx, input.generalId);
}
const map = await loadWorldMap(ctx, input);
if (!map) {
throw new TRPCError({