mirror of
https://github.com/db9979/tidefront.git
synced 2026-12-06 12:54:09 +01:00
Andere Spieler und Saison: Rangliste, Spielerübersicht, Nachrichten, Saisonende mit Wertung und Reset
- Tabellen message, season, season_result (Abschnitt am Ende von schema.ts, ohne Migration) - Rangliste aus Kampfberichten und aktuellem Stand (scoring.ts), 30 s zwischengespeichert - Nachrichten mit Ratenlimit, Systemnachrichten, WebSocket-Meldung messages - Saisonende season_end (season.ts): Endstand, Auszeichnungen, Reset in einer Transaktion, Journal ausgeglichen - Oberfläche: Meldungen mit Reitern Berichte, Nachrichten, Rangliste; Ruhmeshalle; Saisonhinweise - SEASON_DAYS in Compose und .env.example, Handbuch, REGELN und BAUAUFTRAG ergänzt
This commit is contained in:
1 parent
ef4da6f3b5
commit
2a79899fb8
25 files changed
+1440
-13
No files matched your search
@@ -24,6 +24,7 @@ import {
|
||||
upgrade,
|
||||
type Engine,
|
||||
} from "@tidefront/engine";
|
||||
import { seasonRouter, socialRouter } from "./routers/social.ts";
|
||||
|
||||
export interface Ctx {
|
||||
engine: Engine;
|
||||
@@ -155,6 +156,9 @@ export const appRouter = t.router({
|
||||
}))
|
||||
.mutation(({ ctx, input }) => trade(ctx.engine, ctx.player.id, input.key, input)),
|
||||
}),
|
||||
|
||||
social: socialRouter,
|
||||
season: seasonRouter,
|
||||
});
|
||||
|
||||
export type AppRouter = typeof appRouter;
|
||||
@@ -0,0 +1,61 @@
|
||||
// Router für Rangliste, Spielerübersicht, Nachrichten und Saison. Eingehängt in router.ts.
|
||||
import { initTRPC, TRPCError } from "@trpc/server";
|
||||
import { z } from "zod";
|
||||
import {
|
||||
GameError,
|
||||
hallOfFame,
|
||||
inbox,
|
||||
markRead,
|
||||
MESSAGE_MAX,
|
||||
rankingView,
|
||||
seasonView,
|
||||
sendMessage,
|
||||
sentMessages,
|
||||
SUBJECT_MAX,
|
||||
unreadCount,
|
||||
} from "@tidefront/engine";
|
||||
import type { Ctx } from "../router.ts";
|
||||
|
||||
const t = initTRPC.context<Ctx>().create();
|
||||
|
||||
const authed = t.procedure.use(async ({ ctx, next }) => {
|
||||
if (!ctx.player) throw new TRPCError({ code: "UNAUTHORIZED" });
|
||||
if (!(await ctx.rateLimit(`cmd:${ctx.player.id}`, 120, 60))) throw new TRPCError({ code: "TOO_MANY_REQUESTS" });
|
||||
return next({ ctx: { ...ctx, player: ctx.player } });
|
||||
});
|
||||
|
||||
/** Nachrichten je Spieler: höchstens so viele in diesem Fenster. */
|
||||
const MSG_LIMIT = 10;
|
||||
const MSG_WINDOW_SEC = 600;
|
||||
|
||||
export const socialRouter = t.router({
|
||||
ranking: authed.query(({ ctx }) => rankingView(ctx.engine, ctx.player.id)),
|
||||
messages: t.router({
|
||||
inbox: authed.query(({ ctx }) => inbox(ctx.engine, ctx.player.id)),
|
||||
sent: authed.query(({ ctx }) => sentMessages(ctx.engine, ctx.player.id)),
|
||||
unread: authed.query(async ({ ctx }) => ({ count: await unreadCount(ctx.engine, ctx.player.id) })),
|
||||
read: authed
|
||||
.input(z.object({ id: z.number().int().min(1) }))
|
||||
.mutation(({ ctx, input }) => markRead(ctx.engine, ctx.player.id, input.id)),
|
||||
send: authed
|
||||
.input(z.object({
|
||||
toPlayerId: z.number().int().min(1),
|
||||
subject: z.string().trim().max(SUBJECT_MAX).optional(),
|
||||
body: z.string().trim().min(1).max(MESSAGE_MAX),
|
||||
}))
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
if (!(await ctx.rateLimit(`msg:${ctx.player.id}`, MSG_LIMIT, MSG_WINDOW_SEC))) return { ok: false as const, code: "rate" };
|
||||
try {
|
||||
return await sendMessage(ctx.engine, ctx.player.id, input);
|
||||
} catch (err) {
|
||||
if (err instanceof GameError) return { ok: false as const, code: err.code };
|
||||
throw err;
|
||||
}
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
export const seasonRouter = t.router({
|
||||
current: authed.query(({ ctx }) => seasonView(ctx.engine.db, ctx.player.id)),
|
||||
hall: authed.query(({ ctx }) => hallOfFame(ctx.engine.db, ctx.player.id)),
|
||||
});
|
||||
Reference in new issue
Block a user