From 0b19b8327115de9554d9af7903dcd4dc5679eb63 Mon Sep 17 00:00:00 2001 From: Jack Hadrill Date: Fri, 18 Mar 2022 17:33:10 +0000 Subject: [PATCH] Fixed user data request/response definitions --- src/messages/userDataRequest.ts | 1 + src/messages/userDataResponse.ts | 1 + tests/messages/userDataRequest.test.ts | 8 +++++++- tests/messages/userDataResponse.test.ts | 8 +++++++- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/messages/userDataRequest.ts b/src/messages/userDataRequest.ts index 6f1a43a..4465d08 100644 --- a/src/messages/userDataRequest.ts +++ b/src/messages/userDataRequest.ts @@ -57,6 +57,7 @@ export function unpackUserDataRequestMessage (data: Uint8Array): UserDataRequest const usernameLength = packedData.readUInt16() const username = packedData.readBytes(usernameLength) + packedData.cursor = 34 const colour = packedData.readBytes(3) const clientIdLength = packedData.readUInt16() const clientId = packedData.readBytes(clientIdLength) diff --git a/src/messages/userDataResponse.ts b/src/messages/userDataResponse.ts index e47896d..fe8ceba 100644 --- a/src/messages/userDataResponse.ts +++ b/src/messages/userDataResponse.ts @@ -56,6 +56,7 @@ export function unpackUserDataResponseMessage (data: Uint8Array): UserDataRespon const usernameLength = packedData.readUInt16() const username = packedData.readBytes(usernameLength) + packedData.cursor = 34 const colour = packedData.readBytes(3) const clientIdLength = packedData.readUInt16() const clientId = packedData.readBytes(clientIdLength) diff --git a/tests/messages/userDataRequest.test.ts b/tests/messages/userDataRequest.test.ts index 594c58a..e7e2973 100644 --- a/tests/messages/userDataRequest.test.ts +++ b/tests/messages/userDataRequest.test.ts @@ -31,7 +31,13 @@ test('Create a user data request (0x0002) packet.', () => { test('Parse a user data request (0x0002).', () => { // Given - const data = new Uint8Array([0, 12, 66, 117, 116, 108, 101, 114, 115, 97, 117, 114, 117, 115, 255, 64, 0, 0, 7, 77, 101, 114, 99, 117, 114, 121]) + const data = new Uint8Array([ + 0, 12, + 66, 117, 116, 108, 101, 114, 115, 97, 117, 114, 117, 115, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 255, 64, 0, + 0, 7, + 77, 101, 114, 99, 117, 114, 121, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + ]) const username = 'Butlersaurus' const colour = Color('#FF4000') const clientId = 'Mercury' diff --git a/tests/messages/userDataResponse.test.ts b/tests/messages/userDataResponse.test.ts index 7356f66..99ca6f0 100644 --- a/tests/messages/userDataResponse.test.ts +++ b/tests/messages/userDataResponse.test.ts @@ -31,7 +31,13 @@ test('Create a user data response (0x0003) packet.', () => { test('Parse a user data response (0x0003).', () => { // Given - const data = new Uint8Array([0, 12, 66, 117, 116, 108, 101, 114, 115, 97, 117, 114, 117, 115, 255, 64, 0, 0, 7, 77, 101, 114, 99, 117, 114, 121]) + const data = new Uint8Array([ + 0, 12, + 66, 117, 116, 108, 101, 114, 115, 97, 117, 114, 117, 115, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 255, 64, 0, + 0, 7, + 77, 101, 114, 99, 117, 114, 121, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + ]) const username = 'Butlersaurus' const colour = Color('#FF4000') const clientId = 'Mercury'