fastify.log.info done
This commit is contained in:
parent
69ba60b03d
commit
b69a452810
13 changed files with 82 additions and 118 deletions
|
|
@ -132,11 +132,11 @@ services:
|
||||||
- JWT_SECRET=KRUGKIDROVUWG2ZAMJZG653OEBTG66BANJ2W24DTEBXXMZLSEB2GQZJANRQXU6JA
|
- JWT_SECRET=KRUGKIDROVUWG2ZAMJZG653OEBTG66BANJ2W24DTEBXXMZLSEB2GQZJANRQXU6JA
|
||||||
- PROVIDER_FILE=/extra/providers.toml
|
- PROVIDER_FILE=/extra/providers.toml
|
||||||
- SESSION_MANAGER=${SESSION_MANAGER}
|
- SESSION_MANAGER=${SESSION_MANAGER}
|
||||||
logging:
|
# logging:
|
||||||
driver: gelf
|
# driver: gelf
|
||||||
options:
|
# options:
|
||||||
gelf-address: "udp://127.0.0.1:12201"
|
# gelf-address: "udp://127.0.0.1:12201"
|
||||||
tag: "{{.Name}}"
|
# tag: "{{.Name}}"
|
||||||
|
|
||||||
###############
|
###############
|
||||||
# PONG #
|
# PONG #
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
@import "tailwindcss";
|
@import "tailwindcss";
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: "Nimbus Mono L";
|
font-family: "DejaVu Sans Mono";
|
||||||
src: url("/fonts/NimbusMonoL.woff2") format("woff2");
|
src: url("/fonts/DejaVuSansMono.woff2") format("woff2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@tailwind utilities;
|
@tailwind utilities;
|
||||||
|
|
|
||||||
|
|
@ -15,21 +15,9 @@ import { actionBtnPopUpBlock } from './chatHelperFunctions/actionBtnPopUpBlock';
|
||||||
import { windowStateHidden } from './chatHelperFunctions/windowStateHidden';
|
import { windowStateHidden } from './chatHelperFunctions/windowStateHidden';
|
||||||
import type { blockedUnBlocked, obj } from './types_front';
|
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;
|
const MAX_SYSTEM_MESSAGES = 10;
|
||||||
let inviteMsgFlag: boolean = false;
|
let inviteMsgFlag: boolean = false;
|
||||||
|
|
||||||
// get the name of the machine used to connect
|
|
||||||
const machineHostName = window.location.hostname;
|
const machineHostName = window.location.hostname;
|
||||||
console.log('connect to login at %chttps://' + machineHostName + ':8888/app/login',color.yellow);
|
|
||||||
|
|
||||||
export let __socket: Socket | undefined = undefined;
|
export let __socket: Socket | undefined = undefined;
|
||||||
document.addEventListener('ft:pageChange', () => {
|
document.addEventListener('ft:pageChange', () => {
|
||||||
|
|
@ -73,7 +61,7 @@ async function windowStateVisable() {
|
||||||
const socketId = __socket || undefined;
|
const socketId = __socket || undefined;
|
||||||
let oldName = localStorage.getItem("oldName") || 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();
|
let user = await updateUser();
|
||||||
if(user === null) return;
|
if(user === null) return;
|
||||||
socketId.emit('client_entered', {
|
socketId.emit('client_entered', {
|
||||||
|
|
@ -166,14 +154,11 @@ async function connected(socket: Socket): Promise<void> {
|
||||||
const buddies = document.getElementById('div-buddies') as HTMLDivElement;
|
const buddies = document.getElementById('div-buddies') as HTMLDivElement;
|
||||||
const loggedIn = isLoggedIn();
|
const loggedIn = isLoggedIn();
|
||||||
if (!loggedIn) throw('Not Logged in');
|
if (!loggedIn) throw('Not Logged in');
|
||||||
console.log('%cloggedIn:',color.blue, loggedIn?.name);
|
|
||||||
let oldUser = localStorage.getItem("oldName") ?? "";
|
let oldUser = localStorage.getItem("oldName") ?? "";
|
||||||
console.log('%coldUser:',color.yellow, oldUser);
|
if (loggedIn?.name === undefined) {return ;};
|
||||||
if (loggedIn?.name === undefined) {console.log('');return ;}
|
|
||||||
oldUser = loggedIn.name ?? "";
|
oldUser = loggedIn.name ?? "";
|
||||||
// const res = await client.guestLogin();
|
// const res = await client.guestLogin();
|
||||||
let user = await updateUser();
|
let user = await updateUser();
|
||||||
console.log('%cUser?name:',color.yellow, user?.name);
|
|
||||||
localStorage.setItem("oldName", oldUser);
|
localStorage.setItem("oldName", oldUser);
|
||||||
buddies.textContent = "";
|
buddies.textContent = "";
|
||||||
socket.emit('list', {
|
socket.emit('list', {
|
||||||
|
|
@ -376,11 +361,8 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
|
||||||
const bquit = document.getElementById('b-quit') as HTMLDivElement;
|
const bquit = document.getElementById('b-quit') as HTMLDivElement;
|
||||||
const bnextGame = document.getElementById('b-nextGame') as HTMLDivElement;
|
const bnextGame = document.getElementById('b-nextGame') as HTMLDivElement;
|
||||||
|
|
||||||
// chatWindow.textContent = '';
|
|
||||||
// chatWindow.innerHTML = '';
|
|
||||||
buddies.textContent = '';
|
buddies.textContent = '';
|
||||||
buddies.innerHTML = '';
|
buddies.innerHTML = '';
|
||||||
|
|
||||||
const buttonPro = document.getElementById("close-modal") ?? null;
|
const buttonPro = document.getElementById("close-modal") ?? null;
|
||||||
|
|
||||||
if (buttonPro)
|
if (buttonPro)
|
||||||
|
|
@ -465,12 +447,12 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
|
||||||
};
|
};
|
||||||
socket.emit('privMessage', JSON.stringify(message));
|
socket.emit('privMessage', JSON.stringify(message));
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
// Clear the input in all cases
|
||||||
|
sendtextbox.value = "";
|
||||||
}
|
}
|
||||||
// Clear the input in all cases
|
|
||||||
sendtextbox.value = "";
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
// Clear Text button
|
// Clear Text button
|
||||||
clearText?.addEventListener("click", () => {
|
clearText?.addEventListener("click", () => {
|
||||||
|
|
@ -491,8 +473,10 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
|
||||||
});
|
});
|
||||||
|
|
||||||
// Enter key to send message
|
// Enter key to send message
|
||||||
sendtextbox!.addEventListener('keydown', (event) => {
|
sendtextbox.addEventListener('keydown', (event) => {
|
||||||
|
if(!sendtextbox) return;
|
||||||
if (event.key === 'Enter') {
|
if (event.key === 'Enter') {
|
||||||
|
event.preventDefault();
|
||||||
sendButton?.click();
|
sendButton?.click();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
@import "tailwindcss";
|
@import "tailwindcss";
|
||||||
|
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: "Nimbus Mono L";
|
font-family: "DejaVu Sans Mono";
|
||||||
src: url("/fonts/NimbusMonoL.woff2") format("woff2");
|
src: url("/fonts/DejaVuSansMono.woff2") format("woff2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
@import "tailwindcss";
|
@import "tailwindcss";
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: "Nimbus Mono L";
|
font-family: "DejaVu Sans Mono";
|
||||||
src: url("/fonts/NimbusMonoL.woff2") format("woff2");
|
src: url("/fonts/DejaVuSansMono.woff2") format("woff2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@tailwind utilities;
|
@tailwind utilities;
|
||||||
|
|
|
||||||
|
|
@ -21,26 +21,14 @@ import { setGameLink } from './setGameLink';
|
||||||
import { nextGame_SocketListener } from './nextGame_SocketListener';
|
import { nextGame_SocketListener } from './nextGame_SocketListener';
|
||||||
import { list_SocketListener } from './chatBackHelperFunctions/list_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;
|
declare const __SERVICE_NAME: string;
|
||||||
|
|
||||||
// Global map of clients
|
|
||||||
// key = socket, value = clientname
|
|
||||||
interface ClientInfo {
|
interface ClientInfo {
|
||||||
user: string;
|
user: string;
|
||||||
socket: string
|
socket: string
|
||||||
lastSeen: number;
|
lastSeen: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export type blockedUnBlocked =
|
export type blockedUnBlocked =
|
||||||
{
|
{
|
||||||
userState: string,
|
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 UserToBlock: User | null = getUserById(users, `${isBlocked_Id}`);
|
||||||
const UserAskingToBlock: User | null = getUserById(users, `${blockedBy_Id}`);
|
const UserAskingToBlock: User | null = getUserById(users, `${blockedBy_Id}`);
|
||||||
if (!UserToBlock) {
|
if (!UserToBlock) {
|
||||||
console.log(color.blue, `'User: ${UserAskingToBlock?.id} has not blocked' ${isBlocked_Id}`);
|
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
if (!UserAskingToBlock) {
|
if (!UserAskingToBlock) {
|
||||||
console.log(color.blue, `'User: ${UserToBlock?.id} has not blocked by' ${blockedBy_Id}`);
|
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
const usersBlocked: BlockedData[] = fastify.db.getAllBlockedUsers() ?? [];
|
const usersBlocked: BlockedData[] = fastify.db.getAllBlockedUsers() ?? [];
|
||||||
const userAreBlocked: boolean = isBlocked(UserAskingToBlock, UserToBlock, usersBlocked);
|
const userAreBlocked: boolean = isBlocked(UserAskingToBlock, UserToBlock, usersBlocked);
|
||||||
if (userAreBlocked) {
|
if (userAreBlocked) {
|
||||||
console.log(color.yellow, `'User :${UserAskingToBlock.name}) Hhas UN blocked ${UserToBlock.name}`);
|
|
||||||
return UserAskingToBlock.name;
|
return UserAskingToBlock.name;
|
||||||
}
|
}
|
||||||
console.log(color.blue, `'User :${UserAskingToBlock.name}) has BBBblocked ${UserToBlock.name}`);
|
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -147,7 +131,7 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
if (session) {
|
if (session) {
|
||||||
const part = session.split('/')[1];
|
const part = session.split('/')[1];
|
||||||
const machineName = part.split('.')[0];
|
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) => {
|
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() });
|
clientChat.set(socket.id, { user: obj.user, socket: socket.id, lastSeen: Date.now() });
|
||||||
socket.emit('welcome', { msg: 'Welcome to the chat! : ' });
|
socket.emit('welcome', { msg: 'Welcome to the chat! : ' });
|
||||||
broadcast(fastify, obj, obj.SenderWindowID);
|
broadcast(fastify, obj, obj.SenderWindowID);
|
||||||
|
fastify.log.info(`Client connected: ${socket.id}`);
|
||||||
});
|
});
|
||||||
nextGame_SocketListener(fastify, socket);
|
nextGame_SocketListener(fastify, socket);
|
||||||
list_SocketListener(fastify, socket);
|
list_SocketListener(fastify, socket);
|
||||||
|
|
@ -166,7 +151,6 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
if (userFromFrontend.oldUser !== userFromFrontend.user) {
|
if (userFromFrontend.oldUser !== userFromFrontend.user) {
|
||||||
if (client) {
|
if (client) {
|
||||||
client.user = userFromFrontend.user;
|
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: '',
|
SenderUserName: '',
|
||||||
SenderUserID: '',
|
SenderUserID: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
broadcast(fastify, obj, obj.SenderWindowID);
|
broadcast(fastify, obj, obj.SenderWindowID);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -272,6 +255,7 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
socket.on('profilMessage', async (data: string) => {
|
socket.on('profilMessage', async (data: string) => {
|
||||||
const clientName: string = clientChat.get(socket.id)?.user || '';
|
const clientName: string = clientChat.get(socket.id)?.user || '';
|
||||||
const profilMessage: ClientMessage = JSON.parse(data) || '';
|
const profilMessage: ClientMessage = JSON.parse(data) || '';
|
||||||
|
|
@ -287,7 +271,6 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
|
|
||||||
const inviteHtml: string = 'invites you to a game ' + setGameLink('');
|
const inviteHtml: string = 'invites you to a game ' + setGameLink('');
|
||||||
if (clientName !== null) {
|
if (clientName !== null) {
|
||||||
console.log(`DEBUG LOG: clientName =${clientName}`);
|
|
||||||
sendInvite(fastify, inviteHtml, profilInvite);
|
sendInvite(fastify, inviteHtml, profilInvite);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -397,29 +380,18 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
const userNameFromFrontend = data?.userName || null;
|
const userNameFromFrontend = data?.userName || null;
|
||||||
const userFromFrontend = data?.user || null;
|
const userFromFrontend = data?.user || null;
|
||||||
let clientName = clientChat.get(socket.id)?.user || null;
|
let clientName = clientChat.get(socket.id)?.user || null;
|
||||||
// const client = clientChat.get(socket.id) || null;
|
|
||||||
let text = 'is back in the chat';
|
let text = 'is back in the chat';
|
||||||
|
|
||||||
if (clientName === null) {
|
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) {
|
if (userNameFromFrontend !== userFromFrontend) {
|
||||||
text = `'is back in the chat, I used to be called '${userNameFromFrontend}`;
|
text = `'is back in the chat, I used to be called '${userNameFromFrontend}`;
|
||||||
clientName = userFromFrontend;
|
clientName = userFromFrontend;
|
||||||
if (clientName === null) {
|
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) {
|
if (clientName !== null) {
|
||||||
const obj: ClientMessage = {
|
const obj: ClientMessage = {
|
||||||
command: '',
|
command: '',
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import { clientChat } from './app';
|
||||||
export async function broadcastNextGame(fastify: FastifyInstance, gameLink?: Promise<string>) {
|
export async function broadcastNextGame(fastify: FastifyInstance, gameLink?: Promise<string>) {
|
||||||
const link = gameLink ? await gameLink : undefined;
|
const link = gameLink ? await gameLink : undefined;
|
||||||
const sockets = await fastify.io.fetchSockets();
|
const sockets = await fastify.io.fetchSockets();
|
||||||
// fastify.io.fetchSockets().then((sockets) => {
|
|
||||||
for (const socket of sockets) {
|
for (const socket of sockets) {
|
||||||
const clientInfo = clientChat.get(socket.id);
|
const clientInfo = clientChat.get(socket.id);
|
||||||
if (!clientInfo?.user) {
|
if (!clientInfo?.user) {
|
||||||
|
|
@ -18,6 +17,5 @@ export async function broadcastNextGame(fastify: FastifyInstance, gameLink?: Pro
|
||||||
if (link) {
|
if (link) {
|
||||||
socket.emit('nextGame', link);
|
socket.emit('nextGame', link);
|
||||||
}
|
}
|
||||||
// console.log(color.green, `'DEBUG LOG: Broadcast to:', ${data.command} message: ${data.text}`);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -27,6 +27,9 @@ export async function broadcast(fastify: FastifyInstance, data: ClientMessage, s
|
||||||
}
|
}
|
||||||
if (!blockMsgFlag) {
|
if (!blockMsgFlag) {
|
||||||
socket.emit('MsgObjectServer', { message: data });
|
socket.emit('MsgObjectServer', { message: data });
|
||||||
|
if (data.SenderUserID) {
|
||||||
|
fastify.log.info({ senderID: data.SenderUserID, msgBroadcast: data.text });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3,6 +3,16 @@ import { clientChat } from '../app';
|
||||||
import { FastifyInstance } from 'fastify';
|
import { FastifyInstance } from 'fastify';
|
||||||
import { sendPrivMessage } from './sendPrivMessage';
|
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
|
* function looks for the user online in the chat
|
||||||
* and sends emit to invite - format HTML to make clickable
|
* and sends emit to invite - format HTML to make clickable
|
||||||
|
|
@ -10,39 +20,38 @@ import { sendPrivMessage } from './sendPrivMessage';
|
||||||
* @param fastify
|
* @param fastify
|
||||||
* @param innerHtml
|
* @param innerHtml
|
||||||
* @param profil
|
* @param profil
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function sendInvite(fastify: FastifyInstance, innerHtml: string, profil: ClientProfil) {
|
export async function sendInvite(fastify: FastifyInstance, innerHtml: string, profil: ClientProfil) {
|
||||||
fastify.io.fetchSockets().then((sockets) => {
|
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 = clientChat.get(socket.id)?.user || '';
|
||||||
targetSocket = socket || null;
|
targetSocket = socket || null;
|
||||||
if (!targetSocket) continue;
|
if (!targetSocket) continue;
|
||||||
if (clientInfo === profil.user) {
|
if (clientInfo === profil.user) {
|
||||||
profil.innerHtml = innerHtml ?? '';
|
profil.innerHtml = innerHtml ?? '';
|
||||||
if (targetSocket.id) {
|
if (targetSocket.id) {
|
||||||
const data: ClientMessage = {
|
const data: ClientMessage = {
|
||||||
command: `@${clientInfo}`,
|
command: `@${clientInfo}`,
|
||||||
destination: 'inviteMsg',
|
destination: 'inviteMsg',
|
||||||
type: 'chat',
|
type: 'chat',
|
||||||
user: profil.SenderName,
|
user: profil.SenderName,
|
||||||
token: '',
|
token: '',
|
||||||
text: ' needs some text to work',
|
text: getGameNumber(),
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
SenderWindowID: socket.id,
|
SenderWindowID: socket.id,
|
||||||
userID: '',
|
userID: '',
|
||||||
frontendUserName: '',
|
frontendUserName: '',
|
||||||
frontendUser: '',
|
frontendUser: '',
|
||||||
SenderUserName: profil.SenderName,
|
SenderUserName: profil.SenderName,
|
||||||
SenderUserID: '',
|
SenderUserID: '',
|
||||||
Sendertext: '',
|
Sendertext: '',
|
||||||
innerHtml: innerHtml,
|
innerHtml: innerHtml,
|
||||||
};
|
};
|
||||||
sendPrivMessage(fastify, data, '');
|
sendPrivMessage(fastify, data, '');
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -42,22 +42,22 @@ function whoBlockedMe(fastify: FastifyInstance, myID: string): BlockRelation []
|
||||||
* @param fastify
|
* @param fastify
|
||||||
* @param data
|
* @param data
|
||||||
* @param sender
|
* @param sender
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMessage, sender?: string) {
|
export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMessage, sender?: string) {
|
||||||
|
|
||||||
const sockets = await fastify.io.fetchSockets();
|
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);
|
const senderSocket = sockets.find(socket => socket.id === sender);
|
||||||
for (const socket of sockets) {
|
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 list:BlockRelation[] = whoBlockedMe(fastify, UserID);
|
||||||
const clientInfo = clientChat.get(socket.id);
|
const clientInfo = clientChat.get(socket.id);
|
||||||
if (!clientInfo?.user) {
|
if (!clientInfo?.user) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let blockMsgFlag: boolean = false;
|
let blockMsgFlag: boolean = false;
|
||||||
const UserByID = getUserByName(AllusersBlocked, clientInfo.user) ?? '';
|
const UserByID = getUserByName(allUsers, clientInfo.user) ?? '';
|
||||||
if (UserByID === '') {
|
if (UserByID === '') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -74,6 +74,7 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess
|
||||||
}
|
}
|
||||||
if (!blockMsgFlag) {
|
if (!blockMsgFlag) {
|
||||||
socket.emit('MsgObjectServer', { message: data });
|
socket.emit('MsgObjectServer', { message: data });
|
||||||
|
fastify.log.info({ senderID: `${UserID}`, msgPriv: data.text, target: `${UserByID.id}` });
|
||||||
if (senderSocket) {
|
if (senderSocket) {
|
||||||
senderSocket.emit('privMessageCopy', `${data.command}: ${data.text}🔒`);
|
senderSocket.emit('privMessageCopy', `${data.command}: ${data.text}🔒`);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,12 @@ import type { ClientProfil } from '../chat_types';
|
||||||
* @param fastify
|
* @param fastify
|
||||||
* @param profil
|
* @param profil
|
||||||
* @param SenderWindowID
|
* @param SenderWindowID
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function sendProfil(fastify: FastifyInstance, profil: ClientProfil, SenderWindowID?: string) {
|
export async function sendProfil(fastify: FastifyInstance, profil: ClientProfil, SenderWindowID?: string) {
|
||||||
fastify.io.fetchSockets().then((sockets) => {
|
const sockets = await fastify.io.fetchSockets();
|
||||||
const senderSocket = sockets.find(socket => socket.id === SenderWindowID);
|
const senderSocket = sockets.find(socket => socket.id === SenderWindowID);
|
||||||
if (senderSocket) {
|
if (senderSocket) {
|
||||||
senderSocket.emit('profilMessage', profil);
|
senderSocket.emit('profilMessage', profil);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
@ -24,7 +24,6 @@ const start = async () => {
|
||||||
f.log.info('Requested to shutdown');
|
f.log.info('Requested to shutdown');
|
||||||
process.exit(134);
|
process.exit(134);
|
||||||
});
|
});
|
||||||
console.log('-------->Serving static files from:');
|
|
||||||
await f.register(app, {});
|
await f.register(app, {});
|
||||||
await f.listen({ port: 80, host: '0.0.0.0' });
|
await f.listen({ port: 80, host: '0.0.0.0' });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,6 @@ export class StateI {
|
||||||
socket.on('debugInfo', () => this.debugSocket(socket));
|
socket.on('debugInfo', () => this.debugSocket(socket));
|
||||||
|
|
||||||
socket.on('gameMove', (e) => this.gameMove(socket, e));
|
socket.on('gameMove', (e) => this.gameMove(socket, e));
|
||||||
if (socket) {console.log('Socket:', socket.id);};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateClient(socket: SSocket): void {
|
private updateClient(socket: SSocket): void {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue