From cd170dc471262c9eacb2d3e13272950b4cd2ff89 Mon Sep 17 00:00:00 2001 From: Holly Date: Mon, 6 May 2024 15:41:26 +0100 Subject: [PATCH] Fixes for suprious group messages --- client/Terminal-00-Multiuser.user.js | 34 +++++++++++++++++++++++++--- server/index.ts | 2 +- server/objects/RemoteUser.ts | 2 +- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/client/Terminal-00-Multiuser.user.js b/client/Terminal-00-Multiuser.user.js index 0b880ac..01ed034 100644 --- a/client/Terminal-00-Multiuser.user.js +++ b/client/Terminal-00-Multiuser.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name MultiProbe // @namespace https://*.angusnicneven.com/* -// @version 20240502.3 +// @version 20240506.1 // @description Probe with friends! // @author tgpholly // @match https://*.angusnicneven.com/* @@ -32,11 +32,13 @@ if (!window.TE_ACTIVE) { setInterval(nukeCC, 1000); } +window.multiprobe_debug = false; + (function() { 'use strict'; // Make sure to change the userscript version too!!!!!!!!!! - const USERSCRIPT_VERSION_RAW = "20240502.3"; + const USERSCRIPT_VERSION_RAW = "20240506.1"; const USERSCRIPT_VERSION = parseInt(USERSCRIPT_VERSION_RAW.replace(".", "")); if (!continueRunningScript) { @@ -400,6 +402,11 @@ kbd { } } + function log(type, text) { + const d = new Date(); + console.log(`[hNET] [${String(d.getHours()).padStart(2, "0")}:${String(d.getMinutes()).padStart(2, "0")}:${String(d.getSeconds()).padStart(2, "0")}.${String(d.getMilliseconds()).padStart(4, "0")}] [${type}] ${text}`); + } + let allowedPings = 10; window.onkeypress = (e) => { if (e.key === "p") { @@ -494,6 +501,9 @@ kbd { const clientY = reader.readInt(); remoteClients.set(clientId, new RemoteClient(clientName)).rawSetPosInit(clientX, clientY); } + if (window.multiprobe_debug) { + log("RECV", `Initial client packet, got ${clientCount} clients.`); + } ready = true; if (windowContainer) { windowContainer.remove(); @@ -509,6 +519,9 @@ kbd { const clientId = reader.readUInt(); const clientName = reader.readShortString(); remoteClients.set(clientId, new RemoteClient(clientName)); + if (window.multiprobe_debug) { + log("RECV", `New client joined page: ${clientName} ID=${clientId}`); + } break; } case MessageType.CursorPos: @@ -518,6 +531,9 @@ kbd { const cursorX = reader.readFloat(); const cursorY = reader.readInt(); remoteClients.get(clientId).rawSetPos(cursorX, cursorY); + if (window.multiprobe_debug) { + log("RECV", `Cursor position update for ${clientId}, X=${cursorX}, Y=${cursorY}`); + } } break; } @@ -525,6 +541,9 @@ kbd { { const clientId = reader.readUInt(); removeClient(clientId); + if (window.multiprobe_debug) { + log("RECV", `Client ${clientId} left or switched pages`); + } break; } case MessageType.Ping: @@ -532,6 +551,9 @@ kbd { const cursorX = reader.readFloat(); const cursorY = reader.readInt(); createPing(cursorX * clientWidth, cursorY); + if (window.multiprobe_debug) { + log("RECV", `Got a ping, X=${cursorX}, Y=${cursorY}`); + } break; } case MessageType.GroupData: @@ -539,10 +561,16 @@ kbd { groupUIBase.style = ""; groupUsers.innerHTML = ""; groupTitle.innerText = reader.readShortString(); - const groupUserCount = reader.readUShort(); + const groupUserCount = reader.readUShort(); + if (window.multiprobe_debug) { + log("RECV", `Server sent group information for "${groupTitle.innerText}" (${groupUserCount} clients)`); + } for (let i = 0; i < groupUserCount; i++) { const groupUsername = reader.readShortString(); const groupUserLocation = reader.readString(); + if (window.multiprobe_debug) { + log("RECV", `[GROUP USER] USERNAME=${groupUsername}, LOCATION=${groupUserLocation}`); + } createGroupUser(groupUsername, groupUserLocation); } break; diff --git a/server/index.ts b/server/index.ts index f0065d6..641d8a1 100644 --- a/server/index.ts +++ b/server/index.ts @@ -374,7 +374,7 @@ websocketServer.on("connection", (socket) => { } async function sendGroupUpdate(sendUser:RemoteUser, groupSend = false) { - if (!sendUser || user.groupId === Number.MIN_VALUE) { + if (!sendUser || sendUser.groupId === Number.MIN_VALUE) { return; } diff --git a/server/objects/RemoteUser.ts b/server/objects/RemoteUser.ts index c6153bf..24b15a6 100644 --- a/server/objects/RemoteUser.ts +++ b/server/objects/RemoteUser.ts @@ -13,7 +13,7 @@ export default class RemoteUser { public allowedPings:number; public lastPingReset:number; public userId:number; - public groupId:number; + public groupId:number = Number.MIN_VALUE; public groupName:string; constructor(socket:WebSocket, username:string, currentURL:string, rawURL:string, userId:number, groupId:number, groupName:string) {