mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-06 07:37:19 +02:00
Check MKB's protocol version
This commit is contained in:
parent
91b5434952
commit
6a133186b8
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user