Fixes for suprious group messages

This commit is contained in:
Holly Stubbs 2024-05-06 15:41:26 +01:00
parent 1d3e17241a
commit cd170dc471
Signed by: tgpholly
GPG key ID: B8583C4B7D18119E
3 changed files with 33 additions and 5 deletions

View file

@ -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:
@ -540,9 +562,15 @@ kbd {
groupUsers.innerHTML = "";
groupTitle.innerText = reader.readShortString();
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;

View file

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

View file

@ -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) {