Compare commits

..

No commits in common. "86269e624befe5ce1f727b56dfe48ab0f7e13937" and "4947a445ea2a0926855b45d1bcdb100e2da2e9e3" have entirely different histories.

3 changed files with 34 additions and 47 deletions

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name MultiProbe // @name MultiProbe
// @namespace https://*.angusnicneven.com/* // @namespace https://*.angusnicneven.com/*
// @version 20240508.1 // @version 20240507.1
// @description Probe with friends! // @description Probe with friends!
// @author tgpholly // @author tgpholly
// @match https://*.angusnicneven.com/* // @match https://*.angusnicneven.com/*
@ -41,7 +41,7 @@ console.log("[MP] MultiProbe init");
'use strict'; 'use strict';
// Make sure to change the userscript version too!!!!!!!!!! // Make sure to change the userscript version too!!!!!!!!!!
const USERSCRIPT_VERSION_RAW = "20240508.1"; const USERSCRIPT_VERSION_RAW = "20240507.1";
const USERSCRIPT_VERSION = parseInt(USERSCRIPT_VERSION_RAW.replace(".", "")); const USERSCRIPT_VERSION = parseInt(USERSCRIPT_VERSION_RAW.replace(".", ""));
if (!continueRunningScript) { if (!continueRunningScript) {
@ -461,39 +461,35 @@ kbd {
let timeLastFrame = performance.now(); let timeLastFrame = performance.now();
let frameDeltaTime = 0; let frameDeltaTime = 0;
let timeSinceLastPingReset = performance.now(); let timeSinceLastPingReset = performance.now();
try { function animate() {
function animate() { frameDeltaTime = (performance.now() - timeLastFrame) * 0.001;
frameDeltaTime = (performance.now() - timeLastFrame) * 0.001;
if (ws && ready) {
if (ws && ready) { if (currentMouseX !== oldMouseX || currentMouseY !== oldMouseY) {
if (currentMouseX !== oldMouseX || currentMouseY !== oldMouseY) { if ((performance.now() - lastSendTime) >= 41) {
if ((performance.now() - lastSendTime) >= 41) { lastSendTime = performance.now();
lastSendTime = performance.now(); oldMouseX = currentMouseX;
oldMouseX = currentMouseX; oldMouseY = currentMouseY;
oldMouseY = currentMouseY; ws.send(createWriter(Endian.LE, 9).writeByte(MessageType.CursorPos).writeFloat(oldMouseX / clientWidth).writeInt(currentMouseY).toBuffer());
ws.send(createWriter(Endian.LE, 9).writeByte(MessageType.CursorPos).writeFloat(oldMouseX / clientWidth).writeInt(currentMouseY).toBuffer());
}
} }
} }
if ((performance.now() - timeSinceLastPingReset) >= 1000) {
allowedPings = 10;
timeSinceLastPingReset = performance.now();
}
remoteClients.forEach(remoteUser => {
remoteUser.actualX = lerp(remoteUser.actualX, remoteUser.targetX, 20 * frameDeltaTime);
remoteUser.actualY = lerp(remoteUser.actualY, remoteUser.targetY, 20 * frameDeltaTime);
remoteUser.updateCursor();
});
requestAnimationFrame(animate);
timeLastFrame = performance.now();
} }
animate();
} catch (e) { if ((performance.now() - timeSinceLastPingReset) >= 1000) {
console.error(e); allowedPings = 10;
timeSinceLastPingReset = performance.now();
}
remoteClients.forEach(remoteUser => {
remoteUser.actualX = lerp(remoteUser.actualX, remoteUser.targetX, 20 * frameDeltaTime);
remoteUser.actualY = lerp(remoteUser.actualY, remoteUser.targetY, 20 * frameDeltaTime);
remoteUser.updateCursor();
});
requestAnimationFrame(animate);
timeLastFrame = performance.now();
} }
animate();
let windowContainer = null; let windowContainer = null;
@ -626,9 +622,7 @@ kbd {
setTimeout(() => doConnect(localStorage["mpapikey"]), 5000); setTimeout(() => doConnect(localStorage["mpapikey"]), 5000);
} }
ws.onclose = onCloseAndError; ws.onclose = onCloseAndError;
ws.onerror = (e) => { ws.onerror = onCloseAndError;
console.error(e);
}
} }
function createOnlineDialog() { function createOnlineDialog() {

View File

@ -411,13 +411,10 @@ websocketServer.on("connection", (socket) => {
socket.on("message", async (data) => { socket.on("message", async (data) => {
const reader = createReader(Endian.LE, data as Buffer); const reader = createReader(Endian.LE, data as Buffer);
// There is absolutely no reason we should ever get
// more than 50 bytes legit.
if (reader.length > 0 && reader.length < 1024) { if (reader.length > 0 && reader.length < 1024) {
switch (reader.readByte()) { switch (reader.readByte()) {
case MessageType.KeepAlive:
{
user.lastKeepAliveTime = Date.now();
break;
}
case MessageType.ClientDetails: case MessageType.ClientDetails:
{ {
if (user !== undefined) { if (user !== undefined) {
@ -452,9 +449,9 @@ websocketServer.on("connection", (socket) => {
usersToSend.writeUInt(otherUser.id).writeShortString(otherUser.username).writeFloat(otherUser.cursorX).writeInt(otherUser.cursorY); usersToSend.writeUInt(otherUser.id).writeShortString(otherUser.username).writeFloat(otherUser.cursorX).writeInt(otherUser.cursorY);
} }
if (dbParty) { if (dbParty) {
user = users.set(myUUID, new RemoteUser(socket, myUUID, dbUser.Username, page, rawURL, dbUser.Id, dbParty.Id, dbParty.Name)); user = users.set(myUUID, new RemoteUser(socket, dbUser.Username, page, rawURL, dbUser.Id, dbParty.Id, dbParty.Name));
} else { } else {
user = users.set(myUUID, new RemoteUser(socket, myUUID, dbUser.Username, page, rawURL, dbUser.Id, Number.MIN_VALUE, "")); user = users.set(myUUID, new RemoteUser(socket, dbUser.Username, page, rawURL, dbUser.Id, Number.MIN_VALUE, ""));
} }
sendToAllButSelf(user, createWriter(Endian.LE, 6 + dbUser.Username.length).writeByte(MessageType.ClientJoined).writeUInt(user.id).writeShortString(dbUser.Username).toBuffer()); sendToAllButSelf(user, createWriter(Endian.LE, 6 + dbUser.Username.length).writeByte(MessageType.ClientJoined).writeUInt(user.id).writeShortString(dbUser.Username).toBuffer());
user.send(usersToSend.toBuffer()); user.send(usersToSend.toBuffer());

View File

@ -3,8 +3,7 @@ import { WebSocket } from "ws";
export default class RemoteUser { export default class RemoteUser {
private static USER_IDS = 0; private static USER_IDS = 0;
public readonly socket:WebSocket; private readonly socket:WebSocket;
public readonly connectionUUID:string;
public readonly id:number; public readonly id:number;
public readonly username:string; public readonly username:string;
public readonly currentURL:string; public readonly currentURL:string;
@ -16,11 +15,9 @@ export default class RemoteUser {
public userId:number; public userId:number;
public groupId:number = Number.MIN_VALUE; public groupId:number = Number.MIN_VALUE;
public groupName:string; public groupName:string;
public lastKeepAliveTime:number;
constructor(socket:WebSocket, connectionUUID:string, username:string, currentURL:string, rawURL:string, userId:number, groupId:number, groupName:string) { constructor(socket:WebSocket, username:string, currentURL:string, rawURL:string, userId:number, groupId:number, groupName:string) {
this.socket = socket; this.socket = socket;
this.connectionUUID = connectionUUID;
this.id = RemoteUser.USER_IDS++; this.id = RemoteUser.USER_IDS++;
this.username = username; this.username = username;
this.currentURL = currentURL; this.currentURL = currentURL;
@ -30,7 +27,6 @@ export default class RemoteUser {
this.userId = userId; this.userId = userId;
this.groupId = groupId; this.groupId = groupId;
this.groupName = groupName; this.groupName = groupName;
this.lastKeepAliveTime = Date.now();
} }
send(data:Buffer) { send(data:Buffer) {