diff options
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/ts/api/saveGameBoard.ts | 13 | ||||
| -rw-r--r-- | backend/ts/gameBoard.ts | 80 | ||||
| -rw-r--r-- | backend/ts/index.ts | 9 | ||||
| -rw-r--r-- | backend/ts/startGame.ts | 1 |
4 files changed, 56 insertions, 47 deletions
diff --git a/backend/ts/api/saveGameBoard.ts b/backend/ts/api/saveGameBoard.ts index 551c185..da31bdf 100644 --- a/backend/ts/api/saveGameBoard.ts +++ b/backend/ts/api/saveGameBoard.ts @@ -1,16 +1,17 @@ import { Request, Response } from "express"; -import { API_RES, makeQuery } from "../../../helpers/helpersBack"; +import { API_RES, makeQuery, nextTurnEndsAt } from "../../../helpers/helpersBack"; export default async function saveGameBoard(req: Request, res: Response) { - if(req.session === undefined || req.body.gameBoard === undefined) { + if (req.session === undefined || req.body.gameBoard === undefined) { res.status(400); res.send(API_RES.failure); return; } - await makeQuery("UPDATE `fia` SET `gameBoard` = ? WHERE `id` = ? ", [ - req.body.gameBoard, req.session.gid - ]); + let query = "UPDATE `fia` SET `currentPlayer` = IF(`currentPlayer` + 1 = `playersCount`, 0, `currentPlayer` + 1), " + + "`gameBoard` = ?, `timeTillTurnEnd` = ? WHERE `id` = ?" + await makeQuery(query, [req.body.gameBoard, nextTurnEndsAt(), req.session.gid]); res.send(API_RES.success); -}
\ No newline at end of file +} +//UPDATE `fia` SET `currentPlayer` = IF( `currentPlayer` + 1 = `playersCount`, 0, `currentPlayer` + 1 ) WHERE `id` = 169
\ No newline at end of file diff --git a/backend/ts/gameBoard.ts b/backend/ts/gameBoard.ts index 89a8902..314c874 100644 --- a/backend/ts/gameBoard.ts +++ b/backend/ts/gameBoard.ts @@ -1,46 +1,46 @@ import { Color, GameBoard } from '../../helpers/helpersBack'; export const gameBoard: GameBoard = { map: [ - { y: 0, x: 4, chequers: [], start: Color.red }, - { y: 1, x: 4, chequers: [], start: -1 }, - { y: 2, x: 4, chequers: [], start: -1 }, - { y: 3, x: 4, chequers: [], start: -1 }, - { y: 4, x: 4, chequers: [], start: -1 }, - { y: 4, x: 3, chequers: [], start: -1 }, - { y: 4, x: 2, chequers: [], start: -1 }, - { y: 4, x: 1, chequers: [], start: -1 }, - { y: 4, x: 0, chequers: [], start: -1 }, - { y: 5, x: 0, chequers: [], start: -1 }, - { y: 6, x: 0, chequers: [], start: Color.blue }, - { y: 6, x: 1, chequers: [], start: -1 }, - { y: 6, x: 2, chequers: [], start: -1 }, - { y: 6, x: 3, chequers: [], start: -1 }, - { y: 6, x: 4, chequers: [], start: -1 }, - { y: 7, x: 4, chequers: [], start: -1 }, - { y: 8, x: 4, chequers: [], start: -1 }, - { y: 9, x: 4, chequers: [], start: -1 }, - { y: 10, x: 4, chequers: [], start: -1 }, - { y: 10, x: 5, chequers: [], start: -1 }, - { y: 10, x: 6, chequers: [], start: Color.green }, - { y: 9, x: 6, chequers: [], start: -1 }, - { y: 8, x: 6, chequers: [], start: -1 }, - { y: 7, x: 6, chequers: [], start: -1 }, - { y: 6, x: 6, chequers: [], start: -1 }, - { y: 6, x: 7, chequers: [], start: -1 }, - { y: 6, x: 8, chequers: [], start: -1 }, - { y: 6, x: 9, chequers: [], start: -1 }, - { y: 6, x: 10, chequers: [], start: -1 }, - { y: 5, x: 10, chequers: [], start: -1 }, - { y: 4, x: 10, chequers: [], start: Color.yellow }, - { y: 4, x: 9, chequers: [], start: -1 }, - { y: 4, x: 8, chequers: [], start: -1 }, - { y: 4, x: 7, chequers: [], start: -1 }, - { y: 4, x: 6, chequers: [], start: -1 }, - { y: 3, x: 6, chequers: [], start: -1 }, - { y: 2, x: 6, chequers: [], start: -1 }, - { y: 1, x: 6, chequers: [], start: -1 }, - { y: 0, x: 6, chequers: [], start: -1 }, - { y: 0, x: 5, chequers: [], start: -1 }, + { x: 0, y: 4, chequers: [], start: Color.red }, + { x: 1, y: 4, chequers: [], start: -1 }, + { x: 2, y: 4, chequers: [], start: -1 }, + { x: 3, y: 4, chequers: [], start: -1 }, + { x: 4, y: 4, chequers: [], start: -1 }, + { x: 4, y: 3, chequers: [], start: -1 }, + { x: 4, y: 2, chequers: [], start: -1 }, + { x: 4, y: 1, chequers: [], start: -1 }, + { x: 4, y: 0, chequers: [], start: -1 }, + { x: 5, y: 0, chequers: [], start: -1 }, + { x: 6, y: 0, chequers: [], start: Color.blue }, + { x: 6, y: 1, chequers: [], start: -1 }, + { x: 6, y: 2, chequers: [], start: -1 }, + { x: 6, y: 3, chequers: [], start: -1 }, + { x: 6, y: 4, chequers: [], start: -1 }, + { x: 7, y: 4, chequers: [], start: -1 }, + { x: 8, y: 4, chequers: [], start: -1 }, + { x: 9, y: 4, chequers: [], start: -1 }, + { x: 10, y: 4, chequers: [], start: -1 }, + { x: 10, y: 5, chequers: [], start: -1 }, + { x: 10, y: 6, chequers: [], start: Color.green }, + { x: 9, y: 6, chequers: [], start: -1 }, + { x: 8, y: 6, chequers: [], start: -1 }, + { x: 7, y: 6, chequers: [], start: -1 }, + { x: 6, y: 6, chequers: [], start: -1 }, + { x: 6, y: 7, chequers: [], start: -1 }, + { x: 6, y: 8, chequers: [], start: -1 }, + { x: 6, y: 9, chequers: [], start: -1 }, + { x: 6, y: 10, chequers: [], start: -1 }, + { x: 5, y: 10, chequers: [], start: -1 }, + { x: 4, y: 10, chequers: [], start: Color.yellow }, + { x: 4, y: 9, chequers: [], start: -1 }, + { x: 4, y: 8, chequers: [], start: -1 }, + { x: 4, y: 7, chequers: [], start: -1 }, + { x: 4, y: 6, chequers: [], start: -1 }, + { x: 3, y: 6, chequers: [], start: -1 }, + { x: 2, y: 6, chequers: [], start: -1 }, + { x: 1, y: 6, chequers: [], start: -1 }, + { x: 0, y: 6, chequers: [], start: -1 }, + { x: 0, y: 5, chequers: [], start: -1 }, ], // @ts-ignore bases: { diff --git a/backend/ts/index.ts b/backend/ts/index.ts index e4ec5ee..32ac644 100644 --- a/backend/ts/index.ts +++ b/backend/ts/index.ts @@ -17,7 +17,14 @@ const PORT = 8000; if (!process.env.SESSION_KEY) throw Error("SESSION_KEY is undefined"); -app.use(session({ secret: process.env.SESSION_KEY, cookie: { maxAge: 60000 } })); +app.use(session({ + secret: process.env.SESSION_KEY, + saveUninitialized: true, + resave: true, + cookie: { + expires: new Date(Date.now() + 3600000), + } +})); app.use(express.json()); app.use("/", express.static("./public")); diff --git a/backend/ts/startGame.ts b/backend/ts/startGame.ts index eb19bc0..c4d7131 100644 --- a/backend/ts/startGame.ts +++ b/backend/ts/startGame.ts @@ -6,6 +6,7 @@ export default async function startGame(gid: number) { (await makeQuery("SELECT `gameBoard`, `data` FROM `fia` WHERE `id` = ?", [gid]))[0]; for (let player of dbRes.data) { + player.ready = true; for(let square of dbRes.gameBoard.bases[player.color as keyof HomesOrBases]) { square.chequer = player.color; } |
