This commit is contained in:
bgoulard 2026-01-12 14:26:36 +01:00 committed by Nigel
parent 152d5e9578
commit fd572707ff
4 changed files with 19 additions and 24 deletions

View file

@ -21,6 +21,7 @@ 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 { PongGameId } from '@shared/database/mixin/pong';
declare const __SERVICE_NAME: string;
@ -216,10 +217,9 @@ async function onReady(fastify: FastifyInstance) {
socket.on('inviteGame', async (data: string) => {
const clientName: string = clientChat.get(socket.id)?.user || '';
const profilInvite: ClientProfil = JSON.parse(data) || '';
const linkGame: Response | undefined = await setGameLink(fastify, data);
const linkGame: PongGameId | undefined = await setGameLink(fastify, data);
if (!linkGame) return;
const tmp: inviteUserTOGame = await linkGame?.json() as inviteUserTOGame;
const link: string = `<a href="https://localhost:8888/app/pong?game=${tmp.gameId}" style="color: blue; text-decoration: underline; cursor: pointer;">Click me</a>`;
const link: string = `<a href="https://localhost:8888/app/pong?game=${linkGame}" style="color: blue; text-decoration: underline; cursor: pointer;">Click me</a>`;
const inviteHtml: string = 'invites you to a game ' + link;
if (clientName !== null) {
sendInvite(fastify, inviteHtml, profilInvite);

View file

@ -1,9 +1,9 @@
import { FastifyInstance } from 'fastify';
import type { ClientProfil } from './chat_types';
import { PongGameId } from '@shared/database/mixin/pong';
export async function setGameLink(fastify: FastifyInstance, data: string): Promise<Response | undefined> {
export async function setGameLink(fastify: FastifyInstance, data: string): Promise<PongGameId | undefined> {
const profilInvite: ClientProfil = JSON.parse(data) || '';
const payload = { 'user1': `'${profilInvite.SenderID}'`, 'user2':`'${profilInvite.userID}'` };
@ -14,12 +14,17 @@ 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');
}
return resp;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const json = await resp.json() as any;
fastify.log.info(json);
return json.payload.gameId;
}
// disable eslint for err catching
// eslint-disable-next-line @typescript-eslint/no-explicit-any

View file

@ -4,21 +4,7 @@ import fastify, { FastifyInstance } from 'fastify';
import app from './app';
const start = async () => {
const envToLogger = {
development: {
transport: {
target: 'pino-pretty',
options: {
translateTime: 'HH:MM:ss Z',
ignore: 'pid,hostname',
},
},
},
production: true,
test: false,
};
const f: FastifyInstance = fastify({ logger: envToLogger.development });
const f: FastifyInstance = fastify({ logger: true });
try {
process.on('SIGTERM', () => {
f.log.info('Requested to shutdown');

View file

@ -223,9 +223,13 @@ class StateI {
}
public newPausedGame(suid1: string, suid2: string): GameId | undefined {
if (!this.fastify.db.getUser(suid1) || !this.fastify.db.getUser(suid2)) {
return 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 paused start');
const uid1: UserId = suid1 as UserId;
const uid2: UserId = suid2 as UserId;
const g = new Pong(uid1, uid2);