fix(web): support minimap bezel overlay, HTTPS /ws/ proxy routing, dynamic WS buffer, and VirtualFile cache fallback
Updates the TeaVM web client to render the 249x156 minimap bezel overlay cleanly, route WebSockets through same-origin /ws/<port> on HTTPS, dynamically grow WebSocket receive buffers, and fall back to preloaded VirtualFile cache data. ### Core / System Architecture - `DesktopHooks.java`: - Added `setModernMinimapOverlay(int[])` reference-cached pixel conversion for the 249x156 minimap bezel overlay and `hasCachedMainDat(String)` checking `Signlink.cache_dat.length() > 0`. - `Signlink.java`: - Routed `opensocket(int)` on `https://` origins through `wss://<window.location.host>/ws/<wsPort>` while keeping `ws://<host>:<wsPort>/` on `http://`. - `WebLauncher.java`, `index.html`: - Removed the hardcoded `192.168.1.88` server override so the client defaults cleanly to `ClientSettings.SERVER_IP` (`server.2006scape.org`). ### Bug Fixes & Edge Cases - `WebSocketAdapter.java`: - Replaced the fixed `262144`-byte ring buffer with a dynamically growing ring buffer (up to 32 MB) synchronized on `rxLock` to prevent truncation on large transfers.
This commit is contained in:
1 parent
2dfee296e4
commit
ef7eca97e3
5 files changed
+94
-22
No files matched your search
@@ -179,6 +179,13 @@ public final class DesktopHooks {
|
|||||||
private static int[] modernTabPixels = null;
|
private static int[] modernTabPixels = null;
|
||||||
private static boolean[] modernTabMask = null;
|
private static boolean[] modernTabMask = null;
|
||||||
private static boolean hudImagesRequested = false;
|
private static boolean hudImagesRequested = false;
|
||||||
|
private static int[] modernMinimapOverlayPixels = null;
|
||||||
|
private static int[] lastModernMinimapOverlayRef = null;
|
||||||
|
private static Uint8ClampedArray cachedModernMinimapOverlayRgba = null;
|
||||||
|
|
||||||
|
public static void setModernMinimapOverlay(int[] overlay249x156) {
|
||||||
|
modernMinimapOverlayPixels = overlay249x156;
|
||||||
|
}
|
||||||
|
|
||||||
public static void drawModernMinimap(Object graphics, int[] minimapPixels, int windowWidth) {
|
public static void drawModernMinimap(Object graphics, int[] minimapPixels, int windowWidth) {
|
||||||
if (minimapPixels == null || minimapPixels.length < 172 * 156) return;
|
if (minimapPixels == null || minimapPixels.length < 172 * 156) return;
|
||||||
@@ -186,13 +193,40 @@ public final class DesktopHooks {
|
|||||||
HTMLCanvasElement canvas = RSImageProducer.getCanvas();
|
HTMLCanvasElement canvas = RSImageProducer.getCanvas();
|
||||||
if (canvas == null) return;
|
if (canvas == null) return;
|
||||||
Uint8ClampedArray rgba = toRgbaOpaque(minimapPixels, 172 * 156);
|
Uint8ClampedArray rgba = toRgbaOpaque(minimapPixels, 172 * 156);
|
||||||
|
int[] ov = modernMinimapOverlayPixels;
|
||||||
|
if (ov != lastModernMinimapOverlayRef) {
|
||||||
|
cachedModernMinimapOverlayRgba = (ov != null && ov.length >= 249 * 156)
|
||||||
|
? toRgbaWithSentinel(ov, 249 * 156, Game.MODERN_BEZEL_SENTINEL)
|
||||||
|
: null;
|
||||||
|
lastModernMinimapOverlayRef = ov;
|
||||||
|
}
|
||||||
boolean toGpu = WebHd317Renderer.ensureOverlayReady();
|
boolean toGpu = WebHd317Renderer.ensureOverlayReady();
|
||||||
HTMLCanvasElement hudC = jsDrawModernMinimap(canvas, rgba, windowWidth, !toGpu);
|
HTMLCanvasElement hudC = jsDrawModernMinimap(canvas, rgba, cachedModernMinimapOverlayRgba, windowWidth, !toGpu);
|
||||||
if (toGpu && hudC != null) {
|
if (toGpu && hudC != null) {
|
||||||
WebHd317Renderer.drawHudCanvas(hudC, windowWidth - 249, 0, 249, 168);
|
WebHd317Renderer.drawHudCanvas(hudC, windowWidth - 249, 0, 249, 168);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Uint8ClampedArray toRgbaWithSentinel(int[] pixels, int len, int sentinel) {
|
||||||
|
Uint8ClampedArray out = Uint8ClampedArray.create(len * 4);
|
||||||
|
int idx = 0;
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
int p = pixels[i];
|
||||||
|
if (p == sentinel || p == 0) {
|
||||||
|
out.set(idx++, 0);
|
||||||
|
out.set(idx++, 0);
|
||||||
|
out.set(idx++, 0);
|
||||||
|
out.set(idx++, 0);
|
||||||
|
} else {
|
||||||
|
out.set(idx++, (p >> 16) & 0xff);
|
||||||
|
out.set(idx++, (p >> 8) & 0xff);
|
||||||
|
out.set(idx++, p & 0xff);
|
||||||
|
out.set(idx++, 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
public static void drawModernChat(Object graphics, int[] chatContentPixels, int[] chatButtonsPixels, int windowHeight) {
|
public static void drawModernChat(Object graphics, int[] chatContentPixels, int[] chatButtonsPixels, int windowHeight) {
|
||||||
ensureHudAssets();
|
ensureHudAssets();
|
||||||
HTMLCanvasElement canvas = RSImageProducer.getCanvas();
|
HTMLCanvasElement canvas = RSImageProducer.getCanvas();
|
||||||
@@ -455,16 +489,21 @@ public final class DesktopHooks {
|
|||||||
"};")
|
"};")
|
||||||
private static native void jsInitHudAssets();
|
private static native void jsInitHudAssets();
|
||||||
|
|
||||||
@JSBody(params = {"canvas", "rgba", "winW", "draw2d"}, script =
|
@JSBody(params = {"canvas", "rgba", "overlayRgba", "winW", "draw2d"}, script =
|
||||||
"var h = window.scapeHud; if (!h || !h.minimapBezel.complete || h.minimapBezel.naturalWidth <= 0 || !h.minimapHole.complete || h.minimapHole.naturalWidth <= 0) return null;\n" +
|
"var h = window.scapeHud; if (!h || !h.minimapBezel.complete || h.minimapBezel.naturalWidth <= 0 || !h.minimapHole.complete || h.minimapHole.naturalWidth <= 0) return null;\n" +
|
||||||
"var id = h.mContentCtx.createImageData(172, 156); id.data.set(rgba); h.mContentCtx.putImageData(id, 0, 0);\n" +
|
"var id = h.mContentCtx.createImageData(172, 156); id.data.set(rgba); h.mContentCtx.putImageData(id, 0, 0);\n" +
|
||||||
"var g = h.mcCtx; g.clearRect(0, 0, 249, 168);\n" +
|
"var g = h.mcCtx; g.clearRect(0, 0, 249, 168);\n" +
|
||||||
"g.globalCompositeOperation = 'source-over'; g.drawImage(h.mContent, 34, 4);\n" +
|
"g.globalCompositeOperation = 'source-over'; g.drawImage(h.mContent, 34, 4);\n" +
|
||||||
"g.globalCompositeOperation = 'destination-in'; g.drawImage(h.minimapHole, 0, 0);\n" +
|
"g.globalCompositeOperation = 'destination-in'; g.drawImage(h.minimapHole, 0, 0);\n" +
|
||||||
"g.globalCompositeOperation = 'source-over'; g.drawImage(h.minimapBezel, 0, 0);\n" +
|
"g.globalCompositeOperation = 'source-over'; g.drawImage(h.minimapBezel, 0, 0);\n" +
|
||||||
|
"if (overlayRgba) {\n" +
|
||||||
|
" if (!h.mOv) { h.mOv = document.createElement('canvas'); h.mOv.width = 249; h.mOv.height = 156; h.mOvCtx = h.mOv.getContext('2d'); }\n" +
|
||||||
|
" var oid = h.mOvCtx.createImageData(249, 156); oid.data.set(overlayRgba); h.mOvCtx.putImageData(oid, 0, 0);\n" +
|
||||||
|
" g.drawImage(h.mOv, 0, 4);\n" +
|
||||||
|
"}\n" +
|
||||||
"if (draw2d) canvas.getContext('2d').drawImage(h.mc, winW - 249, 0);\n" +
|
"if (draw2d) canvas.getContext('2d').drawImage(h.mc, winW - 249, 0);\n" +
|
||||||
"return h.mc;")
|
"return h.mc;")
|
||||||
private static native HTMLCanvasElement jsDrawModernMinimap(HTMLCanvasElement canvas, Uint8ClampedArray rgba, int winW, boolean draw2d);
|
private static native HTMLCanvasElement jsDrawModernMinimap(HTMLCanvasElement canvas, Uint8ClampedArray rgba, Uint8ClampedArray overlayRgba, int winW, boolean draw2d);
|
||||||
|
|
||||||
@JSBody(params = {"canvas", "contentRgba", "buttonsRgba", "winH", "draw2d"}, script =
|
@JSBody(params = {"canvas", "contentRgba", "buttonsRgba", "winH", "draw2d"}, script =
|
||||||
"var h = window.scapeHud; if (!h || !h.chatFrame.complete || h.chatFrame.naturalWidth <= 0) return null;\n" +
|
"var h = window.scapeHud; if (!h || !h.chatFrame.complete || h.chatFrame.naturalWidth <= 0) return null;\n" +
|
||||||
@@ -671,6 +710,14 @@ public final class DesktopHooks {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean hasCachedMainDat(String cacheDir) {
|
||||||
|
try {
|
||||||
|
return Signlink.cache_dat != null && Signlink.cache_dat.length() > 0;
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@JSBody(params = {"v"}, script = "return v === undefined || v === null;")
|
@JSBody(params = {"v"}, script = "return v === undefined || v === null;")
|
||||||
private static native boolean jsIsUndefined(JSObject v);
|
private static native boolean jsIsUndefined(JSObject v);
|
||||||
|
|
||||||
|
|||||||
@@ -53,8 +53,14 @@ public final class Signlink {
|
|||||||
host = "127.0.0.1";
|
host = "127.0.0.1";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String proto = isSecureOrigin() ? "wss://" : "ws://";
|
if (isSecureOrigin()) {
|
||||||
String url = proto + host + ":" + wsPort + "/";
|
String pageHost = getBrowserHost();
|
||||||
|
if (pageHost != null && !pageHost.isEmpty()) {
|
||||||
|
return new WebSocketAdapter("wss://" + pageHost + "/ws/" + wsPort);
|
||||||
|
}
|
||||||
|
return new WebSocketAdapter("wss://" + host + ":" + wsPort + "/");
|
||||||
|
}
|
||||||
|
String url = "ws://" + host + ":" + wsPort + "/";
|
||||||
return new WebSocketAdapter(url);
|
return new WebSocketAdapter(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,6 +125,9 @@ public final class Signlink {
|
|||||||
// Nothing to close synchronously
|
// Nothing to close synchronously
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JSBody(script = "return window.location.host || '';")
|
||||||
|
private static native String getBrowserHost();
|
||||||
|
|
||||||
@JSBody(script = "return window.location.hostname || '127.0.0.1';")
|
@JSBody(script = "return window.location.hostname || '127.0.0.1';")
|
||||||
private static native String getBrowserHostname();
|
private static native String getBrowserHostname();
|
||||||
|
|
||||||
|
|||||||
@@ -37,8 +37,6 @@ public final class WebLauncher {
|
|||||||
ClientSettings.SERVER_IP = serverParam;
|
ClientSettings.SERVER_IP = serverParam;
|
||||||
} else if (!optServer.isEmpty()) {
|
} else if (!optServer.isEmpty()) {
|
||||||
ClientSettings.SERVER_IP = optServer;
|
ClientSettings.SERVER_IP = optServer;
|
||||||
} else {
|
|
||||||
ClientSettings.SERVER_IP = "192.168.1.88";
|
|
||||||
}
|
}
|
||||||
String wsPortParam = DesktopHooks.getParameter("wsPort");
|
String wsPortParam = DesktopHooks.getParameter("wsPort");
|
||||||
if (!wsPortParam.isEmpty()) {
|
if (!wsPortParam.isEmpty()) {
|
||||||
|
|||||||
@@ -21,10 +21,12 @@ import java.io.OutputStream;
|
|||||||
*/
|
*/
|
||||||
public final class WebSocketAdapter extends Socket {
|
public final class WebSocketAdapter extends Socket {
|
||||||
|
|
||||||
private static final int BUFFER_CAPACITY = 262144; // 256 KB ring buffer
|
private static final int INITIAL_BUFFER_CAPACITY = 262144; // 256 KB initial ring buffer
|
||||||
|
private static final int MAX_BUFFER_CAPACITY = 32 * 1024 * 1024; // 32 MB cap for large archive transfers
|
||||||
|
|
||||||
private final WebSocket ws;
|
private final WebSocket ws;
|
||||||
private final byte[] rxBuffer = new byte[BUFFER_CAPACITY];
|
private final Object rxLock = new Object();
|
||||||
|
private byte[] rxBuffer = new byte[INITIAL_BUFFER_CAPACITY];
|
||||||
private int rxHead = 0;
|
private int rxHead = 0;
|
||||||
private int rxTail = 0;
|
private int rxTail = 0;
|
||||||
private int rxCount = 0;
|
private int rxCount = 0;
|
||||||
@@ -55,15 +57,30 @@ public final class WebSocketAdapter extends Socket {
|
|||||||
ArrayBuffer buf = (ArrayBuffer) data;
|
ArrayBuffer buf = (ArrayBuffer) data;
|
||||||
Uint8Array arr = Uint8Array.create(buf);
|
Uint8Array arr = Uint8Array.create(buf);
|
||||||
int len = arr.getLength();
|
int len = arr.getLength();
|
||||||
synchronized (rxBuffer) {
|
synchronized (rxLock) {
|
||||||
|
int needed = rxCount + len;
|
||||||
|
if (needed > rxBuffer.length && rxBuffer.length < MAX_BUFFER_CAPACITY) {
|
||||||
|
int newCap = rxBuffer.length;
|
||||||
|
while (newCap < needed && newCap < MAX_BUFFER_CAPACITY) {
|
||||||
|
newCap = Math.min(MAX_BUFFER_CAPACITY, newCap * 2);
|
||||||
|
}
|
||||||
|
byte[] next = new byte[newCap];
|
||||||
|
for (int i = 0; i < rxCount; i++) {
|
||||||
|
next[i] = rxBuffer[(rxHead + i) % rxBuffer.length];
|
||||||
|
}
|
||||||
|
rxBuffer = next;
|
||||||
|
rxHead = 0;
|
||||||
|
rxTail = rxCount;
|
||||||
|
}
|
||||||
|
int cap = rxBuffer.length;
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
if (rxCount >= BUFFER_CAPACITY) {
|
if (rxCount >= cap) {
|
||||||
// Drop oldest byte on overflow to prevent lockup
|
// Drop oldest byte only if MAX_BUFFER_CAPACITY is exceeded
|
||||||
rxHead = (rxHead + 1) % BUFFER_CAPACITY;
|
rxHead = (rxHead + 1) % cap;
|
||||||
rxCount--;
|
rxCount--;
|
||||||
}
|
}
|
||||||
rxBuffer[rxTail] = (byte) arr.get(i);
|
rxBuffer[rxTail] = (byte) arr.get(i);
|
||||||
rxTail = (rxTail + 1) % BUFFER_CAPACITY;
|
rxTail = (rxTail + 1) % cap;
|
||||||
rxCount++;
|
rxCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,7 +146,7 @@ public final class WebSocketAdapter extends Socket {
|
|||||||
private final class WsInputStream extends InputStream {
|
private final class WsInputStream extends InputStream {
|
||||||
@Override
|
@Override
|
||||||
public int available() {
|
public int available() {
|
||||||
synchronized (rxBuffer) {
|
synchronized (rxLock) {
|
||||||
return rxCount;
|
return rxCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,10 +154,10 @@ public final class WebSocketAdapter extends Socket {
|
|||||||
@Override
|
@Override
|
||||||
public int read() throws IOException {
|
public int read() throws IOException {
|
||||||
while (true) {
|
while (true) {
|
||||||
synchronized (rxBuffer) {
|
synchronized (rxLock) {
|
||||||
if (rxCount > 0) {
|
if (rxCount > 0) {
|
||||||
int b = rxBuffer[rxHead] & 0xFF;
|
int b = rxBuffer[rxHead] & 0xFF;
|
||||||
rxHead = (rxHead + 1) % BUFFER_CAPACITY;
|
rxHead = (rxHead + 1) % rxBuffer.length;
|
||||||
rxCount--;
|
rxCount--;
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
@@ -160,12 +177,13 @@ public final class WebSocketAdapter extends Socket {
|
|||||||
public int read(byte[] b, int off, int len) throws IOException {
|
public int read(byte[] b, int off, int len) throws IOException {
|
||||||
if (len <= 0) return 0;
|
if (len <= 0) return 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
synchronized (rxBuffer) {
|
synchronized (rxLock) {
|
||||||
if (rxCount > 0) {
|
if (rxCount > 0) {
|
||||||
int toRead = Math.min(len, rxCount);
|
int toRead = Math.min(len, rxCount);
|
||||||
|
int cap = rxBuffer.length;
|
||||||
for (int i = 0; i < toRead; i++) {
|
for (int i = 0; i < toRead; i++) {
|
||||||
b[off + i] = rxBuffer[rxHead];
|
b[off + i] = rxBuffer[rxHead];
|
||||||
rxHead = (rxHead + 1) % BUFFER_CAPACITY;
|
rxHead = (rxHead + 1) % cap;
|
||||||
rxCount--;
|
rxCount--;
|
||||||
}
|
}
|
||||||
return toRead;
|
return toRead;
|
||||||
|
|||||||
@@ -533,7 +533,7 @@
|
|||||||
<div class="opt-group-title">Server & World</div>
|
<div class="opt-group-title">Server & World</div>
|
||||||
<label class="opt-row">
|
<label class="opt-row">
|
||||||
<span>Server Host</span>
|
<span>Server Host</span>
|
||||||
<input id="opt-server" type="text" placeholder="192.168.1.88" />
|
<input id="opt-server" type="text" placeholder="server.2006scape.org" />
|
||||||
</label>
|
</label>
|
||||||
<label class="opt-row">
|
<label class="opt-row">
|
||||||
<span>World</span>
|
<span>World</span>
|
||||||
@@ -907,7 +907,7 @@
|
|||||||
document.getElementById('opt-autologin').checked = !!o.autoLogin;
|
document.getElementById('opt-autologin').checked = !!o.autoLogin;
|
||||||
document.getElementById('opt-username').value = o.username || '';
|
document.getElementById('opt-username').value = o.username || '';
|
||||||
document.getElementById('opt-password').value = o.password || '';
|
document.getElementById('opt-password').value = o.password || '';
|
||||||
document.getElementById('opt-server').value = o.server || params.get('server') || '192.168.1.88';
|
document.getElementById('opt-server').value = o.server || params.get('server') || 'server.2006scape.org';
|
||||||
document.getElementById('opt-world').value = o.world || params.get('world') || '1';
|
document.getElementById('opt-world').value = o.world || params.get('world') || '1';
|
||||||
document.getElementById('opt-hd').checked = (o.hd !== undefined) ? !!o.hd : (params.get('hd') === 'true' || params.get('hd') === '1');
|
document.getElementById('opt-hd').checked = (o.hd !== undefined) ? !!o.hd : (params.get('hd') === 'true' || params.get('hd') === '1');
|
||||||
document.getElementById('opt-mode').value = String(window.scapeDisplayMode !== undefined ? window.scapeDisplayMode : (o.displayMode || 0));
|
document.getElementById('opt-mode').value = String(window.scapeDisplayMode !== undefined ? window.scapeDisplayMode : (o.displayMode || 0));
|
||||||
@@ -921,7 +921,7 @@
|
|||||||
autoLogin: document.getElementById('opt-autologin').checked,
|
autoLogin: document.getElementById('opt-autologin').checked,
|
||||||
username: document.getElementById('opt-username').value.trim(),
|
username: document.getElementById('opt-username').value.trim(),
|
||||||
password: document.getElementById('opt-password').value,
|
password: document.getElementById('opt-password').value,
|
||||||
server: document.getElementById('opt-server').value.trim() || '192.168.1.88',
|
server: document.getElementById('opt-server').value.trim() || 'server.2006scape.org',
|
||||||
world: parseInt(document.getElementById('opt-world').value, 10) || 1,
|
world: parseInt(document.getElementById('opt-world').value, 10) || 1,
|
||||||
hd: document.getElementById('opt-hd').checked,
|
hd: document.getElementById('opt-hd').checked,
|
||||||
displayMode: parseInt(document.getElementById('opt-mode').value, 10) || 0,
|
displayMode: parseInt(document.getElementById('opt-mode').value, 10) || 0,
|
||||||
|
|||||||
Reference in new issue
Block a user