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());