Skip to content

Commit 0bf7fa5

Browse files
tknkaaCopilot
andcommitted
Prevent stale win resubmits
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 93f41e8 commit 0bf7fa5

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

app/routes/api.agari.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { eq } from "drizzle-orm";
12
import { redirect } from "react-router";
23
import { getAuth } from "~/lib/auth";
34
import { getDB } from "~/lib/db";
5+
import { gameState } from "~/lib/db/schema";
46
import { getGameState, recordKyoku, restartGame } from "~/lib/game-service";
57
import judgeAgari from "~/lib/hai/agari";
68
import { sortTehai } from "~/lib/hai/types";
@@ -46,6 +48,7 @@ export async function action({ context, request }: Route.ActionArgs) {
4648
const { isGameOver } = await restartGame(db, userId);
4749

4850
if (isGameOver) {
51+
await db.delete(gameState).where(eq(gameState.userId, userId));
4952
return redirect("/gameover");
5053
}
5154

app/routes/api.ryukyoku.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { eq } from "drizzle-orm";
12
import { redirect } from "react-router";
23
import { getAuth } from "~/lib/auth";
34
import { getDB } from "~/lib/db";
5+
import { gameState } from "~/lib/db/schema";
46
import { getGameState, recordKyoku, restartGame } from "~/lib/game-service";
57
import { calculateShanten } from "~/lib/hai/shanten";
68
import type { Route } from "./+types/api.ryukyoku";
@@ -45,6 +47,7 @@ export async function action({ context, request }: Route.ActionArgs) {
4547
const { isGameOver } = await restartGame(db, userId);
4648

4749
if (isGameOver) {
50+
await db.delete(gameState).where(eq(gameState.userId, userId));
4851
return redirect("/gameover");
4952
}
5053

0 commit comments

Comments
 (0)