Merge pull request #138 from Maix0/nigel/merde

Nigel/merde
This commit is contained in:
G.C.L. Baptiste 2026-01-12 13:46:10 +01:00 committed by GitHub
commit a435afb48f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 66 additions and 73 deletions

View file

@ -43,6 +43,14 @@ declare module "ft_state" {
} }
} }
class DivPrivate extends HTMLElement {
constructor() {
super();
}
}
customElements.define("div-private", DivPrivate);
export function getSocket(): Socket { export function getSocket(): Socket {
if (window.__state.chatSock === undefined) if (window.__state.chatSock === undefined)
window.__state.chatSock = io(window.location.host, { window.__state.chatSock = io(window.location.host, {

View file

@ -13,6 +13,5 @@ import { addMessage } from './addMessage';
export function inviteToPlayPong(profil: ClientProfil, senderSocket: Socket) { export function inviteToPlayPong(profil: ClientProfil, senderSocket: Socket) {
profil.SenderName = getUser()?.name ?? ''; profil.SenderName = getUser()?.name ?? '';
if (profil.SenderName === profil.user) return; if (profil.SenderName === profil.user) return;
addMessage(`You invited to play: ${profil.user}🏓`)
senderSocket.emit('inviteGame', JSON.stringify(profil)); senderSocket.emit('inviteGame', JSON.stringify(profil));
}; };

View file

@ -235,7 +235,7 @@ if (!window.__state._routingHandler) {
if (sameOrigin) { if (sameOrigin) {
e.preventDefault(); e.preventDefault();
navigateTo(url.pathname); navigateTo(`${url.pathname}${url.search}`);
} }
}); });

View file

@ -1,5 +1,5 @@
/** /**
* {{#lambda.indented_star_1}}{{{unescapedDescription}}}{{/lambda.indented_star_1}} * {{#lambda.indented_star_1}}{{{unedDescription}}}{{/lambda.indented_star_1}}
* @export * @export
* @interface {{classname}} * @interface {{classname}}
*/ */
@ -9,7 +9,7 @@ export interface {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{
{{/additionalPropertiesType}} {{/additionalPropertiesType}}
{{#vars}} {{#vars}}
/** /**
* {{#lambda.indented_star_4}}{{{unescapedDescription}}}{{/lambda.indented_star_4}} * {{#lambda.indented_star_4}}{{{unedDescription}}}{{/lambda.indented_star_4}}
* @type {{=<% %>=}}{<%&datatype%>}<%={{ }}=%> * @type {{=<% %>=}}{<%&datatype%>}<%={{ }}=%>
* @memberof {{classname}} * @memberof {{classname}}
{{#deprecated}} {{#deprecated}}

View file

@ -143,7 +143,7 @@ export function isNullish<T>(v: T | undefined | null): v is null | undefined {
return v === null || v === undefined; return v === null || v === undefined;
} }
export function escape(s: string): string { export function e(s: string): string {
return s.replace( return s.replace(
/[^0-9A-Za-z ]/g, /[^0-9A-Za-z ]/g,
c => '&#' + c.charCodeAt(0) + ';', c => '&#' + c.charCodeAt(0) + ';',

View file

@ -18,10 +18,9 @@ import { makeProfil } from './chatBackHelperFunctions/makeProfil';
import { isBlocked } from './chatBackHelperFunctions/isBlocked'; import { isBlocked } from './chatBackHelperFunctions/isBlocked';
import { sendProfil } from './chatBackHelperFunctions/sendProfil'; import { sendProfil } from './chatBackHelperFunctions/sendProfil';
import { setGameLink } from './setGameLink'; import { setGameLink } from './setGameLink';
import { nextGame_SocketListener } from './nextGame_SocketListener';
import { list_SocketListener } from './chatBackHelperFunctions/list_SocketListener'; import { list_SocketListener } from './chatBackHelperFunctions/list_SocketListener';
import { isUser_BlockedBy_me } from './chatBackHelperFunctions/isUser_BlockedBy_me'; import { isUser_BlockedBy_me } from './chatBackHelperFunctions/isUser_BlockedBy_me';
import type { ClientInfo, blockedUnBlocked } from './chat_types'; import type { inviteUserTOGame, ClientInfo, blockedUnBlocked } from './chat_types';
declare const __SERVICE_NAME: string; declare const __SERVICE_NAME: string;
@ -103,7 +102,7 @@ async function onReady(fastify: FastifyInstance) {
broadcast(fastify, obj, obj.SenderWindowID); broadcast(fastify, obj, obj.SenderWindowID);
fastify.log.info(`Client connected: ${socket.id}`); fastify.log.info(`Client connected: ${socket.id}`);
}); });
nextGame_SocketListener(fastify, socket);
list_SocketListener(fastify, socket); list_SocketListener(fastify, socket);
socket.on('updateClientName', (object) => { socket.on('updateClientName', (object) => {
@ -217,8 +216,11 @@ async function onReady(fastify: FastifyInstance) {
socket.on('inviteGame', async (data: string) => { socket.on('inviteGame', async (data: string) => {
const clientName: string = clientChat.get(socket.id)?.user || ''; const clientName: string = clientChat.get(socket.id)?.user || '';
const profilInvite: ClientProfil = JSON.parse(data) || ''; const profilInvite: ClientProfil = JSON.parse(data) || '';
const linkGame: Response | undefined = await setGameLink(fastify, data);
const inviteHtml: string = 'invites you to a game ' + setGameLink(''); 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 inviteHtml: string = 'invites you to a game ' + link;
if (clientName !== null) { if (clientName !== null) {
sendInvite(fastify, inviteHtml, profilInvite); sendInvite(fastify, inviteHtml, profilInvite);
} }

View file

@ -3,7 +3,7 @@ import type { ClientProfil } from '../chat_types';
import type { User } from '@shared/database/mixin/user'; import type { User } from '@shared/database/mixin/user';
import { getUserByName } from './getUserByName'; import { getUserByName } from './getUserByName';
import { Socket } from 'socket.io'; import { Socket } from 'socket.io';
import { escape } from '@shared/utils'; import { e } from '@shared/utils';
/** /**
* function makeProfil - translates the Users[] to a one user looking by name * function makeProfil - translates the Users[] to a one user looking by name
@ -32,7 +32,7 @@ export async function makeProfil(fastify: FastifyInstance, user: string, socket:
user: `${allUsers.name}`, user: `${allUsers.name}`,
loginName: loginState, loginName: loginState,
userID: `${allUsers?.id ?? ''}`, userID: `${allUsers?.id ?? ''}`,
text: escape(allUsers.desc), text: e(allUsers.desc),
timestamp: Date.now(), timestamp: Date.now(),
SenderWindowID: socket.id, SenderWindowID: socket.id,
SenderName: '', SenderName: '',

View file

@ -26,7 +26,7 @@ export async function sendInvite(fastify: FastifyInstance, innerHtml: string, pr
const sockets = await fastify.io.fetchSockets(); const sockets = await fastify.io.fetchSockets();
let targetSocket; let targetSocket;
for (const socket of sockets) { for (const socket of sockets) {
const clientInfo: string = clientChat.get(socket.id)?.user || ''; const clientInfo: string | undefined = clientChat.get(socket.id)?.user || undefined;
targetSocket = socket || null; targetSocket = socket || null;
if (!targetSocket) continue; if (!targetSocket) continue;
if (clientInfo === profil.user) { if (clientInfo === profil.user) {
@ -36,12 +36,12 @@ export async function sendInvite(fastify: FastifyInstance, innerHtml: string, pr
command: `@${clientInfo}`, command: `@${clientInfo}`,
destination: 'inviteMsg', destination: 'inviteMsg',
type: 'chat', type: 'chat',
user: profil.SenderName, user: profil.user,
token: '', token: '',
text: getGameNumber(), text: getGameNumber(),
timestamp: Date.now(), timestamp: Date.now(),
SenderWindowID: socket.id, SenderWindowID: socket.id,
userID: '', userID: profil.userID,
frontendUserName: '', frontendUserName: '',
frontendUser: '', frontendUser: '',
SenderUserName: profil.SenderName, SenderUserName: profil.SenderName,

View file

@ -27,7 +27,7 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess
for (const socket of sockets) { for (const socket of sockets) {
if (socket.id === sender) continue; if (socket.id === sender) continue;
const UserID = getUserByName(allUsers, data.user)?.id ?? ''; const UserID: string = getUserByName(allUsers, data.user as string)?.id as string ?? undefined;
const list:BlockRelation[] = whoBlockedMe(fastify, UserID); const list:BlockRelation[] = whoBlockedMe(fastify, UserID);
const clientInfo = clientChat.get(socket.id); const clientInfo = clientChat.get(socket.id);
if (!clientInfo) continue; if (!clientInfo) continue;

View file

@ -16,7 +16,6 @@ export type ClientMessage = {
innerHtml?: string, innerHtml?: string,
}; };
export type ClientProfil = { export type ClientProfil = {
command: string, command: string,
destination: string, destination: string,
@ -35,7 +34,6 @@ export type ClientProfil = {
}; };
export interface ClientInfo { export interface ClientInfo {
user: string; user: string;
socket: string socket: string
@ -49,21 +47,11 @@ export type blockedUnBlocked =
by: string, by: string,
}; };
export type inviteUserTOGame = {
// export type obj = user1: string,
// { user2: string,
// command: string, gameId: string
// destination: string, }
// type: string,
// user: string,
// frontendUserName: string,
// frontendUser: string,
// token: string,
// text: string,
// timestamp: number,
// SenderWindowID: string,
// Sendertext: string,
// };
export type BlockRelation = { export type BlockRelation = {
blocked: string; blocked: string;

View file

@ -1,6 +0,0 @@
/**
/* TODO find the description info for profil / or profil game link and return
**/
export function createNextGame() {
return '<a href=\'https://localhost:8888/app/\' style=\'color: blue; text-decoration: underline; cursor: pointer;\'>The next Game is Starting click here to watch</a>';
};

View file

@ -1,20 +0,0 @@
import type { FastifyInstance } from 'fastify';
import { broadcastNextGame } from './broadcastNextGame';
import { Socket } from 'socket.io';
import { createNextGame } from './createNextGame';
import { sendGameLinkToChatService } from './sendGameLinkToChatService';
/**
* function listens to the socket for a nextGame emit
* once triggered it broadcasts the pop up
* TODO plug this into backend of the game Chat
* @param fastify
* @param socket
*/
export function nextGame_SocketListener(fastify: FastifyInstance, socket: Socket) {
socket.on('nextGame', () => {
const link: string = createNextGame();
const game: Promise<string> = sendGameLinkToChatService(link);
broadcastNextGame(fastify, game);
});
}

View file

@ -1,6 +1,29 @@
export function setGameLink(link: string): string { import { FastifyInstance } from 'fastify';
if (!link) { import type { ClientProfil } from './chat_types';
link = '<a href=\'https://google.com\' style=\'color: blue; text-decoration: underline; cursor: pointer;\'>Click me</a>';
export async function setGameLink(fastify: FastifyInstance, data: string): Promise<Response | undefined> {
const profilInvite: ClientProfil = JSON.parse(data) || '';
const payload = { 'user1': `'${profilInvite.SenderID}'`, 'user2':`'${profilInvite.userID}'` };
try {
const resp = await fetch('http://app-pong/api/pong/createPausedGame', {
method: 'POST',
headers: { 'Content-type': 'application/json' },
body: JSON.stringify(payload),
});
if (!resp.ok) {
throw (resp);
}
else {
fastify.log.info('game-end info to chat success');
}
return resp;
}
// disable eslint for err catching
// eslint-disable-next-line @typescript-eslint/no-explicit-any
catch (e: any) {
fastify.log.error(`game-end info to chat failed: ${e}`);
} }
return link;
}; };

View file

@ -22,20 +22,19 @@ type CreatePausedGameResponse = MakeStaticResponse<typeof CreatePausedGameRespon
const route: FastifyPluginAsync = async (fastify): Promise<void> => { const route: FastifyPluginAsync = async (fastify): Promise<void> => {
fastify.post<{ Body: CreatePausedGameParam }>( fastify.post<{ Body: CreatePausedGameParam }>(
'/createPausedGame', '/api/pong/createPausedGame',
{ {
schema: { schema: {
body: CreatePausedGameParam, body: CreatePausedGameParam,
response: CreatePausedGameResponse, response: CreatePausedGameResponse,
operationId: 'pongCreatePauseGame', operationId: 'createPauseGame',
}, },
}, },
async function(req, res) { async function(req, res) {
const resp = State.newPausedGame(req.body.user1 as UserId, req.body.user2 as UserId); const resp = State.newPausedGame(req.body.user1 as UserId, req.body.user2 as UserId);
if (isNullish(resp)) { return (res.makeResponse(404, 'failure', 'createPausedGame.generic.fail')); } if (isNullish(resp)) { return (res.makeResponse(404, 'failure', 'createPausedGame.generic.fail')); }
// else // else
return (res.makeResponse(200, 'success', 'createPausedGame.success')); return (res.makeResponse(200, 'success', 'createPausedGame.success', { gameId: resp }));
}, },
); );
}; };

View file

@ -223,12 +223,12 @@ class StateI {
} }
public newPausedGame(suid1: string, suid2: string): GameId | undefined { public newPausedGame(suid1: string, suid2: string): GameId | undefined {
if ( // if (
!this.users.has(suid1 as UserId) || // !this.users.has(suid1 as UserId) ||
!this.users.has(suid2 as UserId) // !this.users.has(suid2 as UserId)
) { // ) {
return undefined; // return undefined;
} // }
const uid1: UserId = suid1 as UserId; const uid1: UserId = suid1 as UserId;
const uid2: UserId = suid2 as UserId; const uid2: UserId = suid2 as UserId;
const g = new Pong(uid1, uid2); const g = new Pong(uid1, uid2);