Blockage u-Game from user
This commit is contained in:
parent
432fd849b8
commit
2e422eee2a
3 changed files with 38 additions and 49 deletions
|
|
@ -174,6 +174,10 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
socket.on('privMessage', (data) => {
|
socket.on('privMessage', (data) => {
|
||||||
const clientName: string = clientChat.get(socket.id)?.user || '';
|
const clientName: string = clientChat.get(socket.id)?.user || '';
|
||||||
const prvMessage: ClientMessage = JSON.parse(data) || '';
|
const prvMessage: ClientMessage = JSON.parse(data) || '';
|
||||||
|
console.log("------------------------------------------------")
|
||||||
|
console.log("PRUV GAME")
|
||||||
|
console.log(data)
|
||||||
|
console.log("------------------------------------------------")
|
||||||
if (clientName !== null) {
|
if (clientName !== null) {
|
||||||
const obj: ClientMessage = {
|
const obj: ClientMessage = {
|
||||||
command: prvMessage.command,
|
command: prvMessage.command,
|
||||||
|
|
@ -183,7 +187,7 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
text: prvMessage.text,
|
text: prvMessage.text,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
SenderWindowID: socket.id,
|
SenderWindowID: socket.id,
|
||||||
};
|
};``
|
||||||
sendPrivMessage(fastify, obj, obj.SenderWindowID);
|
sendPrivMessage(fastify, obj, obj.SenderWindowID);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -217,12 +221,18 @@ 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) || '';
|
||||||
|
console.log("------------------------------------------------")
|
||||||
|
console.log("INVITE GAME")
|
||||||
|
console.log(data)
|
||||||
|
console.log("------------------------------------------------")
|
||||||
|
|
||||||
const linkGame: PongGameId | undefined = await setGameLink(fastify, data);
|
const linkGame: PongGameId | undefined = await setGameLink(fastify, data);
|
||||||
if (!linkGame) return;
|
if (!linkGame) return;
|
||||||
const link: string = `<a href="https://localhost:8888/app/pong?game=${linkGame}" 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;
|
const inviteHtml: string = 'invites you to a game ' + link;
|
||||||
|
|
||||||
if (clientName !== null) {
|
if (clientName !== null) {
|
||||||
sendInvite(fastify, inviteHtml, profilInvite);
|
sendInvite(fastify, inviteHtml, profilInvite, socket.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,8 @@
|
||||||
import type { ClientMessage, ClientProfil } from '../chat_types';
|
import type { ClientProfil } from '../chat_types';
|
||||||
import { clientChat } from '../app';
|
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
|
||||||
|
|
@ -22,37 +12,20 @@ function getGameNumber():string {
|
||||||
* @param profil
|
* @param profil
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export async function sendInvite(fastify: FastifyInstance, innerHtml: string, profil: ClientProfil) {
|
export async function sendInvite(fastify: FastifyInstance, innerHtml: string, profil: ClientProfil, senderSocketId: string) {
|
||||||
const sockets = await fastify.io.fetchSockets();
|
|
||||||
let targetSocket;
|
const clientName: string = clientChat.get(senderSocketId)?.user || '';
|
||||||
const senderSocket = sockets.find(socket => {
|
|
||||||
const clientInfo = clientChat.get(socket.id);
|
sendPrivMessage(fastify, {
|
||||||
|
command: `@${profil.user}`,
|
||||||
|
destination: 'inviteMsg',
|
||||||
|
type: 'chat',
|
||||||
|
user: clientName,
|
||||||
|
userID: profil.userID,
|
||||||
|
SenderWindowID: senderSocketId,
|
||||||
|
SenderUserID: profil.SenderID,
|
||||||
|
SenderUserName: profil.SenderName,
|
||||||
|
innerHtml: innerHtml,
|
||||||
|
}, senderSocketId);
|
||||||
|
|
||||||
return clientInfo?.user === profil.SenderName
|
|
||||||
});
|
|
||||||
for (const socket of sockets) {
|
|
||||||
const clientInfo: string | undefined = clientChat.get(socket.id)?.user || undefined;
|
|
||||||
targetSocket = socket || null;
|
|
||||||
if (!targetSocket) continue;
|
|
||||||
if (clientInfo === profil.user) {
|
|
||||||
profil.innerHtml = innerHtml ?? '';
|
|
||||||
if (targetSocket.id) {
|
|
||||||
const data: ClientMessage = {
|
|
||||||
...profil,
|
|
||||||
command: `@${clientInfo}`,
|
|
||||||
destination: 'inviteMsg',
|
|
||||||
type: 'chat',
|
|
||||||
user: profil.user,
|
|
||||||
text: getGameNumber(),
|
|
||||||
timestamp: Date.now(),
|
|
||||||
SenderWindowID: socket.id,
|
|
||||||
userID: profil.userID,
|
|
||||||
SenderUserName: profil.SenderName,
|
|
||||||
innerHtml: innerHtml,
|
|
||||||
};
|
|
||||||
sendPrivMessage(fastify, data, senderSocket?.id);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -23,7 +23,9 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess
|
||||||
|
|
||||||
const sockets = await fastify.io.fetchSockets();
|
const sockets = await fastify.io.fetchSockets();
|
||||||
const allUsers: User[] = fastify.db.getAllUsers() ?? [];
|
const allUsers: User[] = fastify.db.getAllUsers() ?? [];
|
||||||
|
console.log('sender', sender);
|
||||||
const senderSocket = sockets.find(socket => socket.id === sender);
|
const senderSocket = sockets.find(socket => socket.id === sender);
|
||||||
|
console.log('senderSOcket', senderSocket?.id);
|
||||||
|
|
||||||
for (const socket of sockets) {
|
for (const socket of sockets) {
|
||||||
if (socket.id === sender) continue;
|
if (socket.id === sender) continue;
|
||||||
|
|
@ -44,15 +46,19 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess
|
||||||
}
|
}
|
||||||
|
|
||||||
blockMsgFlag = checkNamePair(list, UserID, receiverUser.id) || false;
|
blockMsgFlag = checkNamePair(list, UserID, receiverUser.id) || false;
|
||||||
|
console.log("userID", UserID);
|
||||||
|
console.log("receiverUserID", receiverUser.id)
|
||||||
if (!blockMsgFlag) {
|
if (!blockMsgFlag) {
|
||||||
socket.emit('MsgObjectServer', { message: data });
|
socket.emit('MsgObjectServer', { message: data });
|
||||||
fastify.log.info({ senderID: `${UserID}`, msgPriv: data.text, target: `${receiverUser.id}` });
|
fastify.log.info({ senderID: `${UserID}`, msgPriv: data.text, target: `${receiverUser.id}` });
|
||||||
if (senderSocket) {
|
if (senderSocket) {
|
||||||
if (!data.innerHtml)
|
if (!data.innerHtml) {
|
||||||
|
console.log('privMsg text');
|
||||||
senderSocket.emit('privMessageCopy', `${data.command}: ${data.text}🔒`);
|
senderSocket.emit('privMessageCopy', `${data.command}: ${data.text}🔒`);
|
||||||
else
|
} else {
|
||||||
|
console.log('privMsg texthtml');
|
||||||
senderSocket.emit('privMessageCopy', `${data.command}: ${data.innerHtml}🔒`);
|
senderSocket.emit('privMessageCopy', `${data.command}: ${data.innerHtml}🔒`);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue