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

View file

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

View file

@ -29,8 +29,12 @@ export async function broadcast(fastify: FastifyInstance, data: ClientMessage, s
}
if (!user?.id) return;
const boolGuestMsg = fastify.db.getGuestMessage(user?.id);
if (boolGuestMsg && user.guest) continue;
const guestflag: User | null = getUserByName(Allusers,clientInfo.user);
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) {
socket.emit('MsgObjectServer', { message: data });