WIP - block guests - working - deBugging

This commit is contained in:
NigeParis 2026-01-08 08:39:30 +01:00 committed by Maix0
parent 7178673794
commit 2b9613fbfb
3 changed files with 22 additions and 6 deletions

View file

@ -206,11 +206,14 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
// Listen for the 'connect' event // Listen for the 'connect' event
socket.on("connect", async () => { socket.on("connect", async () => {
const systemWindow = document.getElementById('system-box') as HTMLDivElement; const systemWindow = document.getElementById('system-box') as HTMLDivElement;
const sendtextbox = document.getElementById('t-chat-window') as HTMLButtonElement;
const noGuest = document.getElementById("noGuest") ?? null;
await waitSocketConnected(socket); await waitSocketConnected(socket);
const user = getUser()?.name; const user = getUser()?.name;
const userID = getUser()?.id; const userID = getUser()?.id;
// Ensure we have a user AND socket is connected // Ensure we have a user AND socket is connected
if (!user || !socket.connected) return; if (!user || !socket.connected || !noGuest) return;
const message = { const message = {
command: "", command: "",
destination: 'system-info', destination: 'system-info',
@ -223,6 +226,8 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
SenderID: userID, SenderID: userID,
}; };
socket.emit('message', JSON.stringify(message)); socket.emit('message', JSON.stringify(message));
const guest = getUser()?.guest;
if (guest) {noGuestFlag = false; noGuest.innerText = ''; sendtextbox.value = ''; return;};
const messageElement = document.createElement("div"); const messageElement = document.createElement("div");
messageElement.textContent = `${user}: is connected au server`; messageElement.textContent = `${user}: is connected au server`;
systemWindow.appendChild(messageElement); systemWindow.appendChild(messageElement);
@ -440,6 +445,7 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
if (!userId) return; if (!userId) return;
if (!userAskingToBlock) return; if (!userAskingToBlock) return;
if (noGuest === null) {break;}; if (noGuest === null) {break;};
const guest = getUser()?.guest;
if (noGuestFlag === false) { if (noGuestFlag === false) {
noGuest.innerText = '❤️​'; noGuest.innerText = '❤️​';
noGuestFlag = true; noGuestFlag = true;
@ -447,6 +453,7 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
noGuest.innerText = '💔'; noGuest.innerText = '💔';
noGuestFlag = false; noGuestFlag = false;
} }
if (guest) {noGuestFlag = false; noGuest.innerText = ''; sendtextbox.value = '';};
const userProfile: ClientProfil = { const userProfile: ClientProfil = {
command: '@noguest', command: '@noguest',
destination: '', destination: '',

View file

@ -266,12 +266,17 @@ async function onReady(fastify: FastifyInstance) {
if (profile.guestmsg) { if (profile.guestmsg) {
//console.log('Data TRUE:', clientName); //console.log('Data TRUE:', clientName);
//console.log(user?.id); console.log(user?.name);
console.log(user?.guest);
console.log(user?.allow_guest_message);
fastify.db.allowGuestMessage(user?.id); fastify.db.allowGuestMessage(user?.id);
} }
else else
{ {
//console.log('Data FALSE', clientName); //console.log('Data FALSE', clientName);
console.log(user?.name);
console.log(user?.guest);
console.log(user?.allow_guest_message);
fastify.db.denyGuestMessage(user?.id); fastify.db.denyGuestMessage(user?.id);
}; };
} }
@ -409,13 +414,13 @@ async function onReady(fastify: FastifyInstance) {
let text = 'is back in the chat'; let text = 'is back in the chat';
if (clientName === null) { if (clientName === null) {
fastify.log.error('ERROR: clientName is NULL'); return; fastify.log.error('ERROR1: clientName 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) {
fastify.log.error('ERROR: clientName is NULL'); return; fastify.log.error('ERROR2: clientName is NULL'); return;
}; };
} }
if (clientName !== null) { if (clientName !== null) {

View file

@ -29,8 +29,12 @@ export async function broadcast(fastify: FastifyInstance, data: ClientMessage, s
} }
if (!user?.id) return; if (!user?.id) return;
const boolGuestMsg = fastify.db.getGuestMessage(user?.id); const guestflag: User | null = getUserByName(Allusers,clientInfo.user);
if (boolGuestMsg && user.guest) continue; if (!guestflag) return;
console.log('G Flag Allow:', guestflag?.allow_guest_message);
console.log('User:', guestflag?.name);
const boolGuestMsg = fastify.db.getGuestMessage(guestflag?.id);
if (!boolGuestMsg) continue;
if (!blockMsgFlag) { if (!blockMsgFlag) {
socket.emit('MsgObjectServer', { message: data }); socket.emit('MsgObjectServer', { message: data });