From 669c2e38db2df5cfe3f3d45c7a209d385d5e4c59 Mon Sep 17 00:00:00 2001 From: thenamelessdev Date: Thu, 8 Jan 2026 13:33:10 +0100 Subject: [PATCH 1/8] added delete room button --- src/index.ts | 5 +++++ views/projects/typeword/game.ejs | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 869c2dd..d935d3e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -158,6 +158,11 @@ io.on("connection", async (socket) => { typeWordRooms[data.room].winner = data.player; io.emit("typewordwinner", {"room": data.room, "player": data.player}); }); + + socket.on("typeworddelete", (data) => { + delete typeWordRooms[data.room]; + io.emit("typeworddelete", {"room": data.room}); + }); }); server.listen({port, host: "0.0.0.0"}); \ No newline at end of file diff --git a/views/projects/typeword/game.ejs b/views/projects/typeword/game.ejs index 61b0c9d..9a7b4ed 100644 --- a/views/projects/typeword/game.ejs +++ b/views/projects/typeword/game.ejs @@ -26,8 +26,10 @@
-
+

Controls (host only):

+
+
From c43f431edb31b1d19912540c41a274b1fa7a1fa9 Mon Sep 17 00:00:00 2001 From: Nameless <132124594+thenamelessdev@users.noreply.github.com> Date: Fri, 9 Jan 2026 21:54:55 +0100 Subject: [PATCH 2/8] added winner text for winner's time and username --- src/index.ts | 2 +- views/projects/typeword/game.ejs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index d935d3e..8b54104 100644 --- a/src/index.ts +++ b/src/index.ts @@ -156,7 +156,7 @@ io.on("connection", async (socket) => { socket.on("typewordfinish", (data) => { typeWordRooms[data.room].winner = data.player; - io.emit("typewordwinner", {"room": data.room, "player": data.player}); + io.emit("typewordwinner", {"room": data.room, "player": data.player, "time": data.time}); }); socket.on("typeworddelete", (data) => { diff --git a/views/projects/typeword/game.ejs b/views/projects/typeword/game.ejs index 9a7b4ed..eeb43df 100644 --- a/views/projects/typeword/game.ejs +++ b/views/projects/typeword/game.ejs @@ -22,6 +22,7 @@

Time: 0s

+


@@ -43,6 +44,7 @@ const timeText = document.getElementById("timeText"); const wordInp = document.getElementById("wordInp"); const deleteRoomBtn = document.getElementById("deleteRoomBtn"); + const winnerText = document.getElementById("winnerText"); let word; let time = 0; @@ -88,7 +90,7 @@ if(data.room = room){ word = undefined; time = 0; - timeText.textContent = `Winner: ${data.player}`; + winnerText.textContent = `${data.player} won with ${data.time.toFixed(2)}`; } }); From 889d734d31ee65d398df08e4c96bb98d55e2097f Mon Sep 17 00:00:00 2001 From: Nameless <132124594+thenamelessdev@users.noreply.github.com> Date: Fri, 9 Jan 2026 21:57:23 +0100 Subject: [PATCH 3/8] made word text unselectable --- views/projects/typeword/game.ejs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/projects/typeword/game.ejs b/views/projects/typeword/game.ejs index eeb43df..1798352 100644 --- a/views/projects/typeword/game.ejs +++ b/views/projects/typeword/game.ejs @@ -16,7 +16,7 @@

Word:

-

+

From 0303b2c9c763f4421e277ad51da48d458349d1a3 Mon Sep 17 00:00:00 2001 From: Nameless <132124594+thenamelessdev@users.noreply.github.com> Date: Fri, 9 Jan 2026 22:06:59 +0100 Subject: [PATCH 4/8] bug fix --- views/projects/typeword/game.ejs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/projects/typeword/game.ejs b/views/projects/typeword/game.ejs index 1798352..b168663 100644 --- a/views/projects/typeword/game.ejs +++ b/views/projects/typeword/game.ejs @@ -87,7 +87,7 @@ }); socket.on("typewordwinner", (data) => { - if(data.room = room){ + if(data.room == room){ word = undefined; time = 0; winnerText.textContent = `${data.player} won with ${data.time.toFixed(2)}`; From 8cc9d5c9b064aa9c0dc57f2f1a76915f392374bf Mon Sep 17 00:00:00 2001 From: Nameless <132124594+thenamelessdev@users.noreply.github.com> Date: Fri, 9 Jan 2026 22:09:23 +0100 Subject: [PATCH 5/8] bug fix (final) --- views/projects/typeword/game.ejs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/views/projects/typeword/game.ejs b/views/projects/typeword/game.ejs index b168663..882f39c 100644 --- a/views/projects/typeword/game.ejs +++ b/views/projects/typeword/game.ejs @@ -60,7 +60,8 @@ function checkWord(){ if(wordInp.value == word){ const finishTime = time; - time = undefined; + word = undefined; + time = 0; socket.emit("typewordfinish", {"room": room, "time": finishTime, "player": you}); } } From 86876a032b59fceb3c8b2468766dc24a62e44929 Mon Sep 17 00:00:00 2001 From: Nameless <132124594+thenamelessdev@users.noreply.github.com> Date: Sat, 10 Jan 2026 10:58:11 +0100 Subject: [PATCH 6/8] made the word and the input word lower case for mobile users --- src/index.ts | 2 +- views/projects/typeword/game.ejs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 8b54104..f6a38ff 100644 --- a/src/index.ts +++ b/src/index.ts @@ -143,7 +143,7 @@ io.on("connection", async (socket) => { const response = await fetch("https://random-word-api.herokuapp.com/word"); const json = await response.json(); if(response.ok){ - io.emit("typewordstart", {"room": data.room, "word": json[0]}); + io.emit("typewordstart", {"room": data.room, "word": json[0].toLowerCase()}); } else{ io.emit("typewordstart", {"room": data.room, "word": "error"}); diff --git a/views/projects/typeword/game.ejs b/views/projects/typeword/game.ejs index 882f39c..5c39d63 100644 --- a/views/projects/typeword/game.ejs +++ b/views/projects/typeword/game.ejs @@ -58,7 +58,7 @@ } function checkWord(){ - if(wordInp.value == word){ + if(wordInp.value.toLowerCase() == word){ const finishTime = time; word = undefined; time = 0; From 8c776765630fe9d9798b5b595fb65444ce334dd1 Mon Sep 17 00:00:00 2001 From: Nameless <132124594+thenamelessdev@users.noreply.github.com> Date: Sat, 10 Jan 2026 11:01:06 +0100 Subject: [PATCH 7/8] made it so that the players username cannot be the same with the host's --- changelog.txt | 2 +- src/routes/typeword.ts | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/changelog.txt b/changelog.txt index 90ad678..03c135b 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1 +1 @@ -New mayor project: TypeWord. Check it out in the projects tab \ No newline at end of file +TypeWord bug fixes \ No newline at end of file diff --git a/src/routes/typeword.ts b/src/routes/typeword.ts index a53ebbe..ff32438 100644 --- a/src/routes/typeword.ts +++ b/src/routes/typeword.ts @@ -47,9 +47,14 @@ router.post("/join", async (req: Request, res: Response) => { if(username && room){ if(await verify(req)){ if(typeWordRooms[room]){ - typeWordRooms[room].player = username; - io.emit("typewordjoin", {"room": room, "username": username}); - res.render("projects/typeword/game", { room: room, user: username, host: typeWordRooms[room].host, player: username }); + if(username != typeWordRooms[room].host){ + typeWordRooms[room].player = username; + io.emit("typewordjoin", {"room": room, "username": username}); + res.render("projects/typeword/game", { room: room, user: username, host: typeWordRooms[room].host, player: username }); + } + else{ + res.render("error", { error: "Username cannot be the host's username" }); + } } else{ res.status(404).render("error", { error: "Room doesn't exists" }) From f1f104d9e30861cccfc2134df69115a19dabd052 Mon Sep 17 00:00:00 2001 From: Nameless <132124594+thenamelessdev@users.noreply.github.com> Date: Sat, 10 Jan 2026 11:16:18 +0100 Subject: [PATCH 8/8] made typeword room api endpoint --- changelog.txt | 2 +- src/routes/api/v1/authed.ts | 31 +++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/changelog.txt b/changelog.txt index 03c135b..76a876f 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1 +1 @@ -TypeWord bug fixes \ No newline at end of file +Make TypeWord room api endpoint \ No newline at end of file diff --git a/src/routes/api/v1/authed.ts b/src/routes/api/v1/authed.ts index f3a389b..e59875d 100644 --- a/src/routes/api/v1/authed.ts +++ b/src/routes/api/v1/authed.ts @@ -2,7 +2,7 @@ import express, { Request, Response, NextFunction } from "express"; const router = express.Router(); import { getClicks, verifyKey } from "../../../functions.js"; import { rooms } from "../../ttt.js"; -import { time } from "console"; +import { typeWordRooms } from "../../typeword.js"; router.use(async (req: Request, res: Response, next: NextFunction) => { const { auth } = req.headers; @@ -38,7 +38,7 @@ router.get("/clicks", async (req: Request, res: Response) => { }); }); -router.get("/rooms", (req: Request, res: Response) => { +router.get("/ttt/rooms", (req: Request, res: Response) => { const { room } = req.query; if(room){ @@ -117,4 +117,31 @@ router.post("/decode", (req: Request, res: Response) => { }); }); +router.get("/typeword/rooms", (req: Request, res: Response) => { + const room = req.query.room; + + if(room){ + if(typeWordRooms[String(room)]){ + res.json({ + room: { + name: typeWordRooms[String(room)].name, + host: typeWordRooms[String(room)].host, + player: typeWordRooms[String(room)].player || "no player", + winner: typeWordRooms[String(room)].winner || "no winner yet" + } + }) + } + else{ + res.status(404).json({ + error: "Room not found" + }) + } + } + else{ + res.status(400).json({ + error: "Missing room" + }) + } +}); + export default router; \ No newline at end of file