From 6a133186b8e362992f8dd16994dc3a07934acd0b Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Sat, 28 Dec 2024 16:32:52 +0700 Subject: [PATCH] Check MKB's protocol version --- src/modules/mkb/pointer-client.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/modules/mkb/pointer-client.ts b/src/modules/mkb/pointer-client.ts index 30b0202..9069694 100755 --- a/src/modules/mkb/pointer-client.ts +++ b/src/modules/mkb/pointer-client.ts @@ -8,6 +8,7 @@ enum PointerAction { BUTTON_RELEASE = 3, SCROLL = 4, POINTER_CAPTURE_CHANGED = 5, + PROTOCOL_VERSION = 127, } @@ -15,6 +16,7 @@ export class PointerClient { private static instance: PointerClient; public static getInstance = () => PointerClient.instance ?? (PointerClient.instance = new PointerClient()); private readonly LOG_TAG = 'PointerClient'; + private readonly REQUIRED_PROTOCOL_VERSION = 2; private socket: WebSocket | undefined | null; private mkbHandler: MkbHandler | undefined; @@ -56,6 +58,15 @@ export class PointerClient { let messageType = dataView.getInt8(0); let offset = Int8Array.BYTES_PER_ELEMENT; switch (messageType) { + case PointerAction.PROTOCOL_VERSION: + const protocolVersion = this.onProtocolVersion(dataView, offset); + BxLogger.info(this.LOG_TAG, 'Protocol version', protocolVersion); + + if (protocolVersion !== this.REQUIRED_PROTOCOL_VERSION) { + alert('Required MKB protocol: ' + protocolVersion); + this.stop(); + } + break; case PointerAction.MOVE: this.onMove(dataView, offset); break; @@ -75,6 +86,10 @@ export class PointerClient { }); } + private onProtocolVersion(dataView: DataView, offset: number) { + return dataView.getUint16(offset); + } + onMove(dataView: DataView, offset: number) { // [X, Y] const x = dataView.getInt16(offset);