better debug

This commit is contained in:
Holly Stubbs 2024-10-08 22:55:01 +01:00
parent 57ca5acc7d
commit 5b8e8f9037
Signed by: tgpholly
GPG key ID: B8583C4B7D18119E
3 changed files with 51 additions and 16 deletions

View file

@ -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;

View file

@ -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:

@ -1 +1 @@
Subproject commit f5432ffac9a4f03ccee22bf31de1fe871040f780
Subproject commit f701cd6715b9b8e4ddaf8126c3d4cd58339f3954