From 19cae8ae63f6824cf7e80a0a2851d1ba51591ade Mon Sep 17 00:00:00 2001 From: bgoulard Date: Mon, 12 Jan 2026 15:04:25 +0100 Subject: [PATCH] fix integration with caht service --- src/chat/src/app.ts | 2 +- src/chat/src/setGameLink.ts | 5 ++--- src/pong/src/state.ts | 17 +++++++++-------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/chat/src/app.ts b/src/chat/src/app.ts index 0fcb90c..9fb4a75 100644 --- a/src/chat/src/app.ts +++ b/src/chat/src/app.ts @@ -20,7 +20,7 @@ import { sendProfil } from './chatBackHelperFunctions/sendProfil'; import { setGameLink } from './setGameLink'; import { list_SocketListener } from './chatBackHelperFunctions/list_SocketListener'; import { isUser_BlockedBy_me } from './chatBackHelperFunctions/isUser_BlockedBy_me'; -import type { inviteUserTOGame, ClientInfo, blockedUnBlocked } from './chat_types'; +import type { ClientInfo, blockedUnBlocked } from './chat_types'; import { PongGameId } from '@shared/database/mixin/pong'; diff --git a/src/chat/src/setGameLink.ts b/src/chat/src/setGameLink.ts index 6cd9034..b2b33d6 100644 --- a/src/chat/src/setGameLink.ts +++ b/src/chat/src/setGameLink.ts @@ -6,7 +6,7 @@ import { PongGameId } from '@shared/database/mixin/pong'; export async function setGameLink(fastify: FastifyInstance, data: string): Promise { const profilInvite: ClientProfil = JSON.parse(data) || ''; - const payload = { 'user1': `'${profilInvite.SenderID}'`, 'user2':`'${profilInvite.userID}'` }; + const payload = { 'user1': profilInvite.SenderID, 'user2':profilInvite.userID }; try { const resp = await fetch('http://app-pong/api/pong/createPausedGame', { method: 'POST', @@ -14,13 +14,12 @@ export async function setGameLink(fastify: FastifyInstance, data: string): Promi body: JSON.stringify(payload), }); if (!resp.ok) { - fastify.log.info("HELLO ?"); throw (resp); } else { fastify.log.info('game-end info to chat success'); } - + // eslint-disable-next-line @typescript-eslint/no-explicit-any const json = await resp.json() as any; fastify.log.info(json); diff --git a/src/pong/src/state.ts b/src/pong/src/state.ts index 2f31977..629026f 100644 --- a/src/pong/src/state.ts +++ b/src/pong/src/state.ts @@ -223,12 +223,8 @@ class StateI { } public newPausedGame(suid1: string, suid2: string): GameId | undefined { - - this.fastify.log.info('suid1:' + suid1); - this.fastify.log.info('suid2:' + suid2); - // if (!this.fastify.db.getUser(suid1) || !this.fastify.db.getUser(suid2)) { - // return undefined; - // } + this.fastify.log.info('new game request: suid1: ' + suid1 + '\tsuid2: ' + suid2); + if (!this.fastify.db.getUser(suid1) || !this.fastify.db.getUser(suid2)) { return undefined; } this.fastify.log.info('new paused start'); const uid1: UserId = suid1 as UserId; const uid2: UserId = suid2 as UserId; @@ -380,13 +376,18 @@ class StateI { private tryJoinGame(g_id : string, sock : SSocket) : JoinRes { const game_id : PongGameId = g_id as PongGameId; - if (this.games.has(game_id) === false) { return (JoinRes.no); } + if (this.games.has(game_id) === false) { + this.fastify.log.warn('gameId:' + g_id + ' is unknown!'); + return (JoinRes.no); + } const game : Pong = this.games.get(game_id)!; - if (game.local || (game.userLeft !== sock.authUser.id && game.userRight !== sock.authUser.id)) { + if (game.local === true || (game.userLeft !== sock.authUser.id && game.userRight !== sock.authUser.id)) { + this.fastify.log.warn('user trying to connect to a game he\'s not part of: gameId:' + g_id + ' userId:' + sock.authUser.id); return (JoinRes.no); } game.userOnPage[game.userLeft === sock.authUser.id ? 0 : 1] = true; if (game.userOnPage[0] === game.userOnPage[1]) { + this.fastify.log.info('Paused game start: gameId:' + g_id); this.initGame(game, game_id, game.userLeft, game.userRight); } return (JoinRes.yes);