diff --git a/docker-compose.yml b/docker-compose.yml index 8a66590..2cd1d56 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -132,11 +132,11 @@ services: - JWT_SECRET=KRUGKIDROVUWG2ZAMJZG653OEBTG66BANJ2W24DTEBXXMZLSEB2GQZJANRQXU6JA - PROVIDER_FILE=/extra/providers.toml - SESSION_MANAGER=${SESSION_MANAGER} - logging: - driver: gelf - options: - gelf-address: "udp://127.0.0.1:12201" - tag: "{{.Name}}" + # logging: + # driver: gelf + # options: + # gelf-address: "udp://127.0.0.1:12201" + # tag: "{{.Name}}" ############### # PONG # diff --git a/frontend/src/pages/chat/chat.css b/frontend/src/pages/chat/chat.css index 720fbdc..3b3dbb9 100644 --- a/frontend/src/pages/chat/chat.css +++ b/frontend/src/pages/chat/chat.css @@ -1,7 +1,7 @@ @import "tailwindcss"; @font-face { - font-family: "Nimbus Mono L"; - src: url("/fonts/NimbusMonoL.woff2") format("woff2"); + font-family: "DejaVu Sans Mono"; + src: url("/fonts/DejaVuSansMono.woff2") format("woff2"); } @tailwind utilities; diff --git a/frontend/src/pages/chat/chat.ts b/frontend/src/pages/chat/chat.ts index 93d82d1..9f4218e 100644 --- a/frontend/src/pages/chat/chat.ts +++ b/frontend/src/pages/chat/chat.ts @@ -15,21 +15,9 @@ import { actionBtnPopUpBlock } from './chatHelperFunctions/actionBtnPopUpBlock'; import { windowStateHidden } from './chatHelperFunctions/windowStateHidden'; import type { blockedUnBlocked, obj } from './types_front'; -export const color = { - red: 'color: red;', - green: 'color: green;', - yellow: 'color: orange;', - blue: 'color: blue;', - reset: '', -}; - - const MAX_SYSTEM_MESSAGES = 10; let inviteMsgFlag: boolean = false; - -// get the name of the machine used to connect const machineHostName = window.location.hostname; -console.log('connect to login at %chttps://' + machineHostName + ':8888/app/login',color.yellow); export let __socket: Socket | undefined = undefined; document.addEventListener('ft:pageChange', () => { @@ -73,7 +61,7 @@ async function windowStateVisable() { const socketId = __socket || undefined; let oldName = localStorage.getItem("oldName") || undefined; - if (socketId === undefined || oldName === undefined) {console.log("%SOCKET ID", color.red); return;} + if (socketId === undefined || oldName === undefined) {return;}; let user = await updateUser(); if(user === null) return; socketId.emit('client_entered', { @@ -166,14 +154,11 @@ async function connected(socket: Socket): Promise { const buddies = document.getElementById('div-buddies') as HTMLDivElement; const loggedIn = isLoggedIn(); if (!loggedIn) throw('Not Logged in'); - console.log('%cloggedIn:',color.blue, loggedIn?.name); let oldUser = localStorage.getItem("oldName") ?? ""; - console.log('%coldUser:',color.yellow, oldUser); - if (loggedIn?.name === undefined) {console.log('');return ;} + if (loggedIn?.name === undefined) {return ;}; oldUser = loggedIn.name ?? ""; // const res = await client.guestLogin(); let user = await updateUser(); - console.log('%cUser?name:',color.yellow, user?.name); localStorage.setItem("oldName", oldUser); buddies.textContent = ""; socket.emit('list', { @@ -376,11 +361,8 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn const bquit = document.getElementById('b-quit') as HTMLDivElement; const bnextGame = document.getElementById('b-nextGame') as HTMLDivElement; - // chatWindow.textContent = ''; - // chatWindow.innerHTML = ''; buddies.textContent = ''; buddies.innerHTML = ''; - const buttonPro = document.getElementById("close-modal") ?? null; if (buttonPro) @@ -465,12 +447,12 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn }; socket.emit('privMessage', JSON.stringify(message)); break; + } + // Clear the input in all cases + sendtextbox.value = ""; } - // Clear the input in all cases - sendtextbox.value = ""; } - } - }); + }); // Clear Text button clearText?.addEventListener("click", () => { @@ -491,8 +473,10 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn }); // Enter key to send message - sendtextbox!.addEventListener('keydown', (event) => { + sendtextbox.addEventListener('keydown', (event) => { + if(!sendtextbox) return; if (event.key === 'Enter') { + event.preventDefault(); sendButton?.click(); } }); diff --git a/frontend/src/pages/ttt/ttt.css b/frontend/src/pages/ttt/ttt.css index d17e0b8..3162ccb 100644 --- a/frontend/src/pages/ttt/ttt.css +++ b/frontend/src/pages/ttt/ttt.css @@ -1,8 +1,8 @@ @import "tailwindcss"; @font-face { - font-family: "Nimbus Mono L"; - src: url("/fonts/NimbusMonoL.woff2") format("woff2"); + font-family: "DejaVu Sans Mono"; + src: url("/fonts/DejaVuSansMono.woff2") format("woff2"); } diff --git a/frontend/src/pong/pong.css b/frontend/src/pong/pong.css index 25963c7..4cc9eb9 100644 --- a/frontend/src/pong/pong.css +++ b/frontend/src/pong/pong.css @@ -1,7 +1,7 @@ @import "tailwindcss"; @font-face { - font-family: "Nimbus Mono L"; - src: url("/fonts/NimbusMonoL.woff2") format("woff2"); + font-family: "DejaVu Sans Mono"; + src: url("/fonts/DejaVuSansMono.woff2") format("woff2"); } @tailwind utilities; diff --git a/src/chat/src/app.ts b/src/chat/src/app.ts index 8f81b82..32b9263 100644 --- a/src/chat/src/app.ts +++ b/src/chat/src/app.ts @@ -21,26 +21,14 @@ import { setGameLink } from './setGameLink'; import { nextGame_SocketListener } from './nextGame_SocketListener'; import { list_SocketListener } from './chatBackHelperFunctions/list_SocketListener'; -// colors for console.log -export const color = { - red: '\x1b[31m', - green: '\x1b[32m', - yellow: '\x1b[33m', - blue: '\x1b[34m', - reset: '\x1b[0m', -}; - declare const __SERVICE_NAME: string; -// Global map of clients -// key = socket, value = clientname interface ClientInfo { user: string; socket: string lastSeen: number; } - export type blockedUnBlocked = { userState: string, @@ -125,20 +113,16 @@ function isUser_BlockedBy_me(fastify: FastifyInstance, blockedBy_Id : string, is const UserToBlock: User | null = getUserById(users, `${isBlocked_Id}`); const UserAskingToBlock: User | null = getUserById(users, `${blockedBy_Id}`); if (!UserToBlock) { - console.log(color.blue, `'User: ${UserAskingToBlock?.id} has not blocked' ${isBlocked_Id}`); return ''; }; if (!UserAskingToBlock) { - console.log(color.blue, `'User: ${UserToBlock?.id} has not blocked by' ${blockedBy_Id}`); return ''; }; const usersBlocked: BlockedData[] = fastify.db.getAllBlockedUsers() ?? []; const userAreBlocked: boolean = isBlocked(UserAskingToBlock, UserToBlock, usersBlocked); if (userAreBlocked) { - console.log(color.yellow, `'User :${UserAskingToBlock.name}) Hhas UN blocked ${UserToBlock.name}`); return UserAskingToBlock.name; } - console.log(color.blue, `'User :${UserAskingToBlock.name}) has BBBblocked ${UserToBlock.name}`); return ''; }; @@ -147,7 +131,7 @@ async function onReady(fastify: FastifyInstance) { if (session) { const part = session.split('/')[1]; const machineName = part.split('.')[0]; - console.log(color.yellow, 'Connect at : https://' + machineName + ':8888/app/login'); + fastify.log.info(`Connect at : https://${machineName}:8888/`); } fastify.io.on('connection', (socket: Socket) => { @@ -156,6 +140,7 @@ async function onReady(fastify: FastifyInstance) { clientChat.set(socket.id, { user: obj.user, socket: socket.id, lastSeen: Date.now() }); socket.emit('welcome', { msg: 'Welcome to the chat! : ' }); broadcast(fastify, obj, obj.SenderWindowID); + fastify.log.info(`Client connected: ${socket.id}`); }); nextGame_SocketListener(fastify, socket); list_SocketListener(fastify, socket); @@ -166,7 +151,6 @@ async function onReady(fastify: FastifyInstance) { if (userFromFrontend.oldUser !== userFromFrontend.user) { if (client) { client.user = userFromFrontend.user; - console.log(color.yellow, `'DEBUG LOG: client.user is, '${client.user}'`); } } }); @@ -218,7 +202,6 @@ async function onReady(fastify: FastifyInstance) { SenderUserName: '', SenderUserID: '', }; - broadcast(fastify, obj, obj.SenderWindowID); } }); @@ -272,6 +255,7 @@ async function onReady(fastify: FastifyInstance) { } }); + socket.on('profilMessage', async (data: string) => { const clientName: string = clientChat.get(socket.id)?.user || ''; const profilMessage: ClientMessage = JSON.parse(data) || ''; @@ -287,7 +271,6 @@ async function onReady(fastify: FastifyInstance) { const inviteHtml: string = 'invites you to a game ' + setGameLink(''); if (clientName !== null) { - console.log(`DEBUG LOG: clientName =${clientName}`); sendInvite(fastify, inviteHtml, profilInvite); } }); @@ -397,29 +380,18 @@ async function onReady(fastify: FastifyInstance) { const userNameFromFrontend = data?.userName || null; const userFromFrontend = data?.user || null; let clientName = clientChat.get(socket.id)?.user || null; - // const client = clientChat.get(socket.id) || null; let text = 'is back in the chat'; if (clientName === null) { - console.log('ERROR: clientName is NULL'); return; + fastify.log.error('ERROR: clientName is NULL'); return; }; - // if (client === null) { - // console.log('ERROR: client is NULL'); return; - // }; if (userNameFromFrontend !== userFromFrontend) { text = `'is back in the chat, I used to be called '${userNameFromFrontend}`; clientName = userFromFrontend; if (clientName === null) { - console.log('ERROR: clientName is NULL'); return; + fastify.log.error('ERROR: clientName is NULL'); return; }; - // if (client) { - // client.user = clientName; - // } } - // console.log( - // color.green, - // `Client entered the Chat: ${clientName} (${socket.id})`, - // ); if (clientName !== null) { const obj: ClientMessage = { command: '', diff --git a/src/chat/src/broadcastNextGame.ts b/src/chat/src/broadcastNextGame.ts index 05f0289..b584ab0 100644 --- a/src/chat/src/broadcastNextGame.ts +++ b/src/chat/src/broadcastNextGame.ts @@ -9,7 +9,6 @@ import { clientChat } from './app'; export async function broadcastNextGame(fastify: FastifyInstance, gameLink?: Promise) { const link = gameLink ? await gameLink : undefined; const sockets = await fastify.io.fetchSockets(); - // fastify.io.fetchSockets().then((sockets) => { for (const socket of sockets) { const clientInfo = clientChat.get(socket.id); if (!clientInfo?.user) { @@ -18,6 +17,5 @@ export async function broadcastNextGame(fastify: FastifyInstance, gameLink?: Pro if (link) { socket.emit('nextGame', link); } - // console.log(color.green, `'DEBUG LOG: Broadcast to:', ${data.command} message: ${data.text}`); } }; \ No newline at end of file diff --git a/src/chat/src/chatBackHelperFunctions/broadcast.ts b/src/chat/src/chatBackHelperFunctions/broadcast.ts index 63e862b..f9e1438 100644 --- a/src/chat/src/chatBackHelperFunctions/broadcast.ts +++ b/src/chat/src/chatBackHelperFunctions/broadcast.ts @@ -27,6 +27,9 @@ export async function broadcast(fastify: FastifyInstance, data: ClientMessage, s } if (!blockMsgFlag) { socket.emit('MsgObjectServer', { message: data }); + if (data.SenderUserID) { + fastify.log.info({ senderID: data.SenderUserID, msgBroadcast: data.text }); + } } } } \ No newline at end of file diff --git a/src/chat/src/chatBackHelperFunctions/sendInvite.ts b/src/chat/src/chatBackHelperFunctions/sendInvite.ts index 21e7e39..d4ea121 100644 --- a/src/chat/src/chatBackHelperFunctions/sendInvite.ts +++ b/src/chat/src/chatBackHelperFunctions/sendInvite.ts @@ -3,6 +3,16 @@ import { clientChat } from '../app'; import { FastifyInstance } from 'fastify'; import { sendPrivMessage } from './sendPrivMessage'; +/** + * TODO + * function needed to transfer the game number +*/ + +function getGameNumber():string { + const gameNumber = '123456GameNum'; + return gameNumber; +} + /** * function looks for the user online in the chat * and sends emit to invite - format HTML to make clickable @@ -10,39 +20,38 @@ import { sendPrivMessage } from './sendPrivMessage'; * @param fastify * @param innerHtml * @param profil - */ +*/ -export function sendInvite(fastify: FastifyInstance, innerHtml: string, profil: ClientProfil) { - fastify.io.fetchSockets().then((sockets) => { - let targetSocket; - for (const socket of sockets) { - const clientInfo: string = clientChat.get(socket.id)?.user || ''; - targetSocket = socket || null; - if (!targetSocket) continue; - if (clientInfo === profil.user) { - profil.innerHtml = innerHtml ?? ''; - if (targetSocket.id) { - const data: ClientMessage = { - command: `@${clientInfo}`, - destination: 'inviteMsg', - type: 'chat', - user: profil.SenderName, - token: '', - text: ' needs some text to work', - timestamp: Date.now(), - SenderWindowID: socket.id, - userID: '', - frontendUserName: '', - frontendUser: '', - SenderUserName: profil.SenderName, - SenderUserID: '', - Sendertext: '', - innerHtml: innerHtml, - }; - sendPrivMessage(fastify, data, ''); - } - return; +export async function sendInvite(fastify: FastifyInstance, innerHtml: string, profil: ClientProfil) { + const sockets = await fastify.io.fetchSockets(); + let targetSocket; + for (const socket of sockets) { + const clientInfo: string = clientChat.get(socket.id)?.user || ''; + targetSocket = socket || null; + if (!targetSocket) continue; + if (clientInfo === profil.user) { + profil.innerHtml = innerHtml ?? ''; + if (targetSocket.id) { + const data: ClientMessage = { + command: `@${clientInfo}`, + destination: 'inviteMsg', + type: 'chat', + user: profil.SenderName, + token: '', + text: getGameNumber(), + timestamp: Date.now(), + SenderWindowID: socket.id, + userID: '', + frontendUserName: '', + frontendUser: '', + SenderUserName: profil.SenderName, + SenderUserID: '', + Sendertext: '', + innerHtml: innerHtml, + }; + sendPrivMessage(fastify, data, ''); } + return; } - }); -} + } +} \ No newline at end of file diff --git a/src/chat/src/chatBackHelperFunctions/sendPrivMessage.ts b/src/chat/src/chatBackHelperFunctions/sendPrivMessage.ts index b5bc46c..b0645da 100644 --- a/src/chat/src/chatBackHelperFunctions/sendPrivMessage.ts +++ b/src/chat/src/chatBackHelperFunctions/sendPrivMessage.ts @@ -42,22 +42,22 @@ function whoBlockedMe(fastify: FastifyInstance, myID: string): BlockRelation [] * @param fastify * @param data * @param sender - */ +*/ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMessage, sender?: string) { const sockets = await fastify.io.fetchSockets(); - const AllusersBlocked: User[] = fastify.db.getAllUsers() ?? []; + const allUsers: User[] = fastify.db.getAllUsers() ?? []; const senderSocket = sockets.find(socket => socket.id === sender); for (const socket of sockets) { - const UserID = getUserByName(AllusersBlocked, data.user)?.id ?? ''; + const UserID = getUserByName(allUsers, data.user)?.id ?? ''; const list:BlockRelation[] = whoBlockedMe(fastify, UserID); const clientInfo = clientChat.get(socket.id); if (!clientInfo?.user) { continue; } let blockMsgFlag: boolean = false; - const UserByID = getUserByName(AllusersBlocked, clientInfo.user) ?? ''; + const UserByID = getUserByName(allUsers, clientInfo.user) ?? ''; if (UserByID === '') { return; } @@ -74,6 +74,7 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess } if (!blockMsgFlag) { socket.emit('MsgObjectServer', { message: data }); + fastify.log.info({ senderID: `${UserID}`, msgPriv: data.text, target: `${UserByID.id}` }); if (senderSocket) { senderSocket.emit('privMessageCopy', `${data.command}: ${data.text}🔒`); } diff --git a/src/chat/src/chatBackHelperFunctions/sendProfil.ts b/src/chat/src/chatBackHelperFunctions/sendProfil.ts index dc18eda..e5f9996 100644 --- a/src/chat/src/chatBackHelperFunctions/sendProfil.ts +++ b/src/chat/src/chatBackHelperFunctions/sendProfil.ts @@ -6,13 +6,12 @@ import type { ClientProfil } from '../chat_types'; * @param fastify * @param profil * @param SenderWindowID - */ +*/ -export function sendProfil(fastify: FastifyInstance, profil: ClientProfil, SenderWindowID?: string) { - fastify.io.fetchSockets().then((sockets) => { - const senderSocket = sockets.find(socket => socket.id === SenderWindowID); - if (senderSocket) { - senderSocket.emit('profilMessage', profil); - } - }); +export async function sendProfil(fastify: FastifyInstance, profil: ClientProfil, SenderWindowID?: string) { + const sockets = await fastify.io.fetchSockets(); + const senderSocket = sockets.find(socket => socket.id === SenderWindowID); + if (senderSocket) { + senderSocket.emit('profilMessage', profil); + } } \ No newline at end of file diff --git a/src/pong/src/run.ts b/src/pong/src/run.ts index c050473..b1b3727 100644 --- a/src/pong/src/run.ts +++ b/src/pong/src/run.ts @@ -24,7 +24,6 @@ const start = async () => { f.log.info('Requested to shutdown'); process.exit(134); }); - console.log('-------->Serving static files from:'); await f.register(app, {}); await f.listen({ port: 80, host: '0.0.0.0' }); } diff --git a/src/tic-tac-toe/src/state.ts b/src/tic-tac-toe/src/state.ts index 0b5877d..24b0d2e 100644 --- a/src/tic-tac-toe/src/state.ts +++ b/src/tic-tac-toe/src/state.ts @@ -95,7 +95,6 @@ export class StateI { socket.on('debugInfo', () => this.debugSocket(socket)); socket.on('gameMove', (e) => this.gameMove(socket, e)); - if (socket) {console.log('Socket:', socket.id);}; } private updateClient(socket: SSocket): void {