From 5b8e8f903773be1159f856a3b7c68bc77f4b0c1b Mon Sep 17 00:00:00 2001 From: Holly Date: Tue, 8 Oct 2024 22:55:01 +0100 Subject: [PATCH] better debug --- client/Terminal-00-Multiuser.user.js | 62 +++++++++++++++++++++------- server/index.ts | 3 ++ server/scripts | 2 +- 3 files changed, 51 insertions(+), 16 deletions(-) diff --git a/client/Terminal-00-Multiuser.user.js b/client/Terminal-00-Multiuser.user.js index 71f91cb..d501862 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 20241008.1 +// @version 20241008.2 // @description Probe with friends! // @author tgpholly // @match https://*.angusnicneven.com/* @@ -55,7 +55,7 @@ console.log("[MP] MultiProbe init"); 'use strict'; // Make sure to change the userscript version too!!!!!!!!!! - const USERSCRIPT_VERSION_RAW = "20241008.1"; + const USERSCRIPT_VERSION_RAW = "20241008.2"; const USERSCRIPT_VERSION = parseInt(USERSCRIPT_VERSION_RAW.replace(".", "")); if (!continueRunningScript) { @@ -510,19 +510,29 @@ mp_button { }, 1000); const debugMessageContainer = document.createElement("mp_container"); - debugMessageContainer.style = "position:fixed;top:0;left:0;padding:4px;pointer-events:none;text-shadow: 0px 0px 4px black"; - document.documentElement.appendChild(debugMessageContainer); + debugMessageContainer.style = "position:fixed;top:0;left:0;padding:8px;margin:4px;pointer-events:none;text-shadow: 0px 0px 4px black;z-index:999999999999;background-color:rgba(0,0,0,0.5);outline:1px solid white"; + if (!window.multiprobe_debug) { + debugMessageContainer.style.display = "none"; + } - if (window.multiprobe_debug) { - const debugText = document.createElement("mp_text"); - debugText.innerText = "RUNNING IN DEBUG"; - debugMessageContainer.appendChild(debugText); - } - if (window.multiprobe_connectLocal) { - const debugConnectLocal = document.createElement("mp_text"); - debugConnectLocal.innerText = "CONNECTED TO DEV SERVER"; - debugMessageContainer.appendChild(debugConnectLocal); - } + const debugText = document.createElement("mp_text"); + debugText.innerText = "MultiProbe DEBUG"; + debugText.style.color = "rgb(255, 200, 200)"; + + const debugConnectedTo = document.createElement("mp_text"); + debugConnectedTo.innerText = "Disconnected"; + + const debugAuthedAs = document.createElement("mp_text"); + debugAuthedAs.innerText = "Not Authenticated"; + + const debugPing = document.createElement("mp_text"); + debugPing.innerText = "Ping: Calculating..."; + + debugMessageContainer.appendChild(debugText); + debugMessageContainer.appendChild(debugConnectedTo); + debugMessageContainer.appendChild(debugAuthedAs); + debugMessageContainer.appendChild(debugPing); + document.documentElement.appendChild(debugMessageContainer); let needsToUpdate = false; console.log("[MP] Checking for new versions..."); @@ -712,8 +722,16 @@ mp_button { window.onkeydown = (e) => { if (!windowContainer && e.key === "F1") { + e.preventDefault(); localStorage["mpshowfirsttime"] = "true"; createFirstTimeDialog(); + return false; + } + if (e.key === "F3") { + e.preventDefault(); + window.multiprobe_debug = !window.multiprobe_debug; + debugMessageContainer.style.display = window.multiprobe_debug ? "block" : "none"; + return false; } }; @@ -770,27 +788,38 @@ mp_button { console.log("[MP] Connecting to realtime server..."); ws = new WebSocket((windowLocation.includes("//localhost:") || window.multiprobe_connectLocal) ? "wss://ws.eusv.net/t00mpdev" : "wss://ws.eusv.net/t00mp"); let keepAliveInterval; + let pingStartTime = -1; + let lastPing = 0; ws.onopen = () => { console.log("[MP] Connected! Authenticating..."); + debugConnectedTo.innerText = `Connected to ${ws.url}`; otherCursors.innerHTML = ""; selfCursor = new RemoteClient(localStorage["t00mp_username"], false, true); selfCursor.probeImage.style.visibility = "hidden"; selfCursor.element.style.visibility = localStorage["t00mp_cursorStyle"] ?? "hidden"; selfCursor.hasBeenMoved = true; const currentPage = windowLocation.split("/").slice(2).join("/"); + ws.send(keepAlivePacket); ws.send(createWriter(Endian.LE, 4 + apiKey.length + currentPage.length) .writeUByte(MessageType.ClientDetails) .writeShortString(apiKey) .writeString(currentPage) .toBuffer()); keepAliveInterval = setInterval(() => { + pingStartTime = performance.now(); ws.send(keepAlivePacket); - }, 5000); + }, 2000); } function onMessage(buf) { const reader = createReader(Endian.LE, Buffer.from(buf)); switch (reader.readByte()) { + case MessageType.KeepAlive: + { + lastPing = performance.now() - pingStartTime; + debugPing.innerText = `Ping: ${lastPing}ms`; + break; + } case MessageType.Clients: { const clientCount = reader.readUShort(); @@ -813,6 +842,7 @@ mp_button { if (!needsToUpdate) { createFirstTimeDialog(); } + debugAuthedAs.innerText = `Authenticated as ${localStorage["t00mp_username"]}`; console.log("[MP] Authenticated!"); break; } @@ -914,6 +944,8 @@ mp_button { if (keepAliveInterval) { clearInterval(keepAliveInterval); keepAliveInterval = undefined; + debugConnectedTo.innerText = "Disconnected"; + debugAuthedAs.innerText = "Not Authenticated"; } ws = undefined; ready = false; diff --git a/server/index.ts b/server/index.ts index 1dfeff7..ee04695 100644 --- a/server/index.ts +++ b/server/index.ts @@ -194,6 +194,8 @@ async function updateConnectionMetrics() { onlineUsersUnique.Value = userCount; } +const keepalivePacket = createWriter(Endian.LE, 1).writeByte(MessageType.KeepAlive).toBuffer(); + websocketServer.on("connection", (socket) => { const myUUID = crypto.randomUUID(); let user:RemoteUser; @@ -257,6 +259,7 @@ websocketServer.on("connection", (socket) => { if (user !== undefined) { user.lastKeepAliveTime = Date.now(); } + socket.send(keepalivePacket); break; } case MessageType.ClientDetails: diff --git a/server/scripts b/server/scripts index f5432ff..f701cd6 160000 --- a/server/scripts +++ b/server/scripts @@ -1 +1 @@ -Subproject commit f5432ffac9a4f03ccee22bf31de1fe871040f780 +Subproject commit f701cd6715b9b8e4ddaf8126c3d4cd58339f3954