From 171f7d42ffddfd28e8e6b7b141672aafbb31a34e Mon Sep 17 00:00:00 2001 From: ayunami2000 Date: Fri, 27 Dec 2024 11:14:56 -0500 Subject: [PATCH] fix wisp spec hell (trailing slash) also remove logging --- src/1.8.ts | 2 -- src/connection/crypto.ts | 16 ---------------- src/connection/epoxy.ts | 2 ++ src/connection/fakewebsocket.ts | 8 +++++--- src/connection/framer.ts | 9 --------- src/connection/index.ts | 6 ------ src/index.ts | 17 +++++++++++++---- 7 files changed, 20 insertions(+), 40 deletions(-) diff --git a/src/1.8.ts b/src/1.8.ts index 15f365b..b8fa778 100644 --- a/src/1.8.ts +++ b/src/1.8.ts @@ -352,7 +352,6 @@ export class EaglerProxy { } let serverid = packet.readString(); - console.log("Server ID: " + serverid); let publicKey = packet.readVariableData(); let verifyToken = packet.readVariableData(); @@ -372,7 +371,6 @@ export class EaglerProxy { modulus, exponent ); - console.log("joining with: ", this.authStore); await joinServer( this.authStore.yggToken, digest, diff --git a/src/connection/crypto.ts b/src/connection/crypto.ts index 98ba154..332d19f 100644 --- a/src/connection/crypto.ts +++ b/src/connection/crypto.ts @@ -406,7 +406,6 @@ export class Decryptor { // this.feedback = new Uint8Array(iv); const start = performance.now(); this.aesCfb = new CFBDecryptor(iv, iv, 1); - console.log("Took " + (performance.now() - start) + " to seed Decryptor"); } constructor() { @@ -426,13 +425,6 @@ export class Decryptor { } const start = performance.now(); controller.enqueue(new Buffer(this.aesCfb.decrypt(chunk.inner))); - console.log( - "Took " + - (performance.now() - start) + - " to transform chunk of size " + - chunk.length + - " (Decryption)" - ); }, }); } @@ -449,7 +441,6 @@ export class Encryptor { // this.feedback = new Uint8Array(iv); const start = performance.now(); this.aesCfb = new CFBEncryptor(iv, iv, 1); - console.log("Took " + (performance.now() - start) + " to seed Encryptor"); } transform(chunk: Buffer): Buffer { @@ -462,13 +453,6 @@ export class Encryptor { if (!this.aesCfb) return chunk; const start = performance.now(); const retobj = new Buffer(this.aesCfb.encrypt(chunk.inner)); - console.log( - "Took " + - (performance.now() - start) + - " to transform chunk of size " + - chunk.length + - " (Encryption)" - ); return retobj; } } diff --git a/src/connection/epoxy.ts b/src/connection/epoxy.ts index 79df0b9..04f8163 100644 --- a/src/connection/epoxy.ts +++ b/src/connection/epoxy.ts @@ -3,6 +3,7 @@ import initEpoxy, { EpoxyClient, EpoxyClientOptions, } from "@mercuryworkshop/epoxy-tls/minimal-epoxy-bundled"; +import { setWispUrl } from ".."; let connectedwisp = ""; @@ -48,6 +49,7 @@ export async function connect_tcp(socket: string): Promise { export function set_wisp_server(wisp_url: string) { initpromise = new Promise((r) => (resolver = r)); + setWispUrl(wisp_url); initWisp(wisp_url); } diff --git a/src/connection/fakewebsocket.ts b/src/connection/fakewebsocket.ts index 0c92c0e..66606be 100644 --- a/src/connection/fakewebsocket.ts +++ b/src/connection/fakewebsocket.ts @@ -283,12 +283,14 @@ const NativeWebSocket = WebSocket; export function makeFakeWebSocket(): typeof WebSocket { return new Proxy(WebSocket, { construct(_target, [uri, protos]) { + if (uri == wispUrl) { + return new NativeWebSocket(uri, protos); + } + let url = new URL(uri); let isCustomProtocol = url.port == "" && url.pathname.startsWith("//"); - if (url.href == wispUrl) { - return new NativeWebSocket(uri, protos); - } else if (isCustomProtocol && url.hostname == "java") { + if (isCustomProtocol && url.hostname == "java") { const ws = new WispWS(uri); ws.start(); return ws; diff --git a/src/connection/framer.ts b/src/connection/framer.ts index fa40494..cef718d 100644 --- a/src/connection/framer.ts +++ b/src/connection/framer.ts @@ -61,9 +61,6 @@ export function bufferTransformer(): TransformStream { return new TransformStream({ transform(chunk, controller) { controller.enqueue(new Buffer(chunk)); - console.log( - "Got a packet of size " + chunk.length + " (bufferTransformer)" - ); }, }); } @@ -101,9 +98,6 @@ export function lengthTransformer(): TransformStream { controller.enqueue(pkt); currentSize = -1; } - console.log( - "Took " + (performance.now() - start) + " to lengthTransform packet" - ); }, }); } @@ -133,9 +127,6 @@ export class Decompressor { "Decompressor: server sent compressed packet below threshold" ); } - console.log( - "Took " + (performance.now() - start) + " to decompress packet" - ); }, }); } diff --git a/src/connection/index.ts b/src/connection/index.ts index 6d268ea..90fd923 100644 --- a/src/connection/index.ts +++ b/src/connection/index.ts @@ -125,8 +125,6 @@ export class Connection { () => backlog++ ).getReader(); - // setInterval(() => console.log("epoxy backlog ", backlog), 1000); - while (true) { const { done, value } = await reader.read(); if (done || !value) return; @@ -147,15 +145,11 @@ export class Connection { () => backlog++ ).getReader(); - // setInterval(() => console.log("eagler backlog ", backlog), 1000); while (true) { const start = performance.now(); const { done, value } = await reader.read(); if (done || !value) return; await impl.eaglerRead(value); - console.log( - "Took " + (performance.now() - start) + " to eaglerRead packet" - ); backlog--; } diff --git a/src/index.ts b/src/index.ts index 31152d9..b82bd9c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,10 +24,19 @@ export let authstore: AuthStore = { const nativeFetch = fetch; -wispUrl = - new URL(window.location.href).searchParams.get("wisp") || - localStorage["wispcraft_wispurl"] || - "wss://wisp.run/"; +export function setWispUrl(wisp: string) { + const wispUrlUrl = new URL(wisp); + if (!wispUrlUrl.pathname.endsWith("/")) { + wispUrlUrl.pathname += "/"; + } + wispUrl = wispUrlUrl.href; +} + +setWispUrl(wispUrl = + new URL(window.location.href).searchParams.get("wisp") || + localStorage["wispcraft_wispurl"] || + "wss://wisp.run/" + ); if (localStorage["wispcraft_accounts"]) { const accounts = JSON.parse(