remove game from activeGames immediately on end

This commit is contained in:
Nathaniel Tampus
2023-04-09 02:41:46 +08:00
parent 5cf4f599a6
commit 24861fec36
3 changed files with 20 additions and 3 deletions

View File

@@ -22,7 +22,15 @@ export const metadata = {
follow: false,
nocache: true,
noarchive: true
}
},
icons: {
icon: [
{ type: "image/png", sizes: "32x32", url: "/favicon-32x32.png" },
{ type: "image/png", sizes: "16x16", url: "/favicon-16x16.png" }
],
apple: { url: "/apple-touch-icon.png", sizes: "180x180" }
},
manifest: "/site.webmanifest"
};
export default function RootLayout({ children }: { children: React.ReactNode }) {

View File

@@ -1,15 +1,18 @@
import { IconUser } from "@tabler/icons-react";
import Link from "next/link";
import ThemeToggle from "./ThemeToggle";
import Image from "next/image";
import icon from "../../public/images/chessu_icon.svg";
export default function Header() {
return (
<header className="navbar mx-1 w-auto justify-center drop-shadow-sm md:mx-16 lg:mx-40">
<div className="flex flex-1 items-center gap-1">
<div className="flex flex-1 items-center gap-2">
<Link
href="/"
className="btn btn-ghost no-animation p-0 text-xl normal-case hover:bg-transparent"
className="btn btn-ghost no-animation gap-1 p-0 text-2xl normal-case hover:bg-transparent"
>
<Image src={icon} alt="chessu icon" height={30} />
chessu
</Link>
<div className="dropdown dropdown-right hover:dropdown-open">

View File

@@ -149,6 +149,9 @@ export async function claimAbandoned(this: Socket, type: "win" | "draw") {
};
io.to(game.code as string).emit("gameOver", gameOver);
if (game.timeout) clearTimeout(game.timeout);
activeGames.splice(activeGames.indexOf(game), 1);
}
export async function getLatestGame(this: Socket) {
@@ -205,6 +208,9 @@ export async function sendMove(this: Socket, m: { from: string; to: string; prom
const { id } = (await GameModel.save(game)) as Game; // save game to db
game.id = id;
io.to(game.code as string).emit("gameOver", { reason, winnerName, winnerSide, id });
if (game.timeout) clearTimeout(game.timeout);
activeGames.splice(activeGames.indexOf(game), 1);
}
} else {
throw new Error("invalid move");