From 6b9b67eb3f9e856a0831ba8153f087b12d85cf13 Mon Sep 17 00:00:00 2001 From: Holly Date: Fri, 19 Apr 2024 09:44:26 +0100 Subject: [PATCH] do not send users from other pages under any circumstances --- client/Terminal-00-Multiuser.user.js | 2 +- client/otherpagetest.html | 14 ++++++++++++++ server/index.ts | 12 ++++++++---- 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 client/otherpagetest.html diff --git a/client/Terminal-00-Multiuser.user.js b/client/Terminal-00-Multiuser.user.js index 4bebd69..676e430 100644 --- a/client/Terminal-00-Multiuser.user.js +++ b/client/Terminal-00-Multiuser.user.js @@ -166,7 +166,7 @@ if (!window.TE_ACTIVE) { pingDiv.style.top = `${y}px`; pingDiv.style.left = `${x}px`; otherCursors.appendChild(pingDiv); - setTimeout(() => pingDiv.remove(), 1999); + setTimeout(() => pingDiv.remove(), 2000); } function removeClient(id) { diff --git a/client/otherpagetest.html b/client/otherpagetest.html new file mode 100644 index 0000000..019adfe --- /dev/null +++ b/client/otherpagetest.html @@ -0,0 +1,14 @@ + + + + + + + UserScript test page + + +

Test page :)

+ + + + \ No newline at end of file diff --git a/server/index.ts b/server/index.ts index 3daf3a1..69b3192 100644 --- a/server/index.ts +++ b/server/index.ts @@ -59,13 +59,17 @@ server.on("connection", (socket) => { page = ""; } let lengthOfUsernames = 0; + const usersOnPage = new Array(); await users.forEach(otherUser => { - lengthOfUsernames += otherUser.username.length + 1; // + 1 for length byte + if (otherUser.currentURL === page) { + usersOnPage.push(otherUser); + lengthOfUsernames += otherUser.username.length + 1; // + 1 for length byte + } }); - const usersToSend = createWriter(Endian.LE, 3 + (users.length * 12) + lengthOfUsernames).writeByte(MessageType.Clients).writeUShort(users.length); - await users.forEach(otherUser => { + const usersToSend = createWriter(Endian.LE, 3 + (usersOnPage.length * 12) + lengthOfUsernames).writeByte(MessageType.Clients).writeUShort(usersOnPage.length); + for (const otherUser of usersOnPage) { usersToSend.writeUInt(otherUser.id).writeShortString(otherUser.username).writeFloat(otherUser.cursorX).writeInt(otherUser.cursorY); - }); + } user = users.set(myUUID, new User(socket, username, page)); sendToAllButSelf(user, createWriter(Endian.LE, 6 + username.length).writeByte(MessageType.ClientJoined).writeUInt(user.id).writeShortString(username).toBuffer()); user.send(usersToSend.toBuffer());