Fix outbound user data request/response
This commit is contained in:
@@ -33,9 +33,11 @@ export function packUserDataRequestMessage (properties: UserDataRequestMessage,
|
||||
const packedData = new SmartBuffer()
|
||||
packedData.writeBytes(usernameLength)
|
||||
packedData.writeBytes(username)
|
||||
packedData.pad(32 - username.length)
|
||||
packedData.writeBytes(colour)
|
||||
packedData.writeBytes(clientIdLength)
|
||||
packedData.writeBytes(clientId)
|
||||
packedData.pad(32 - clientId.length)
|
||||
|
||||
// Encrypt the data.
|
||||
const data = encrypt(packedData.data, MESSAGE_TYPE, key)
|
||||
|
||||
@@ -33,9 +33,11 @@ export function packUserDataResponseMessage (properties: UserDataResponseMessage
|
||||
const packedData = new SmartBuffer()
|
||||
packedData.writeBytes(usernameLength)
|
||||
packedData.writeBytes(username)
|
||||
packedData.pad(32 - username.length)
|
||||
packedData.writeBytes(colour)
|
||||
packedData.writeBytes(clientIdLength)
|
||||
packedData.writeBytes(clientId)
|
||||
packedData.pad(32 - clientId.length)
|
||||
|
||||
// Return encrypted data.
|
||||
const data = encrypt(packedData.data, MESSAGE_TYPE, key)
|
||||
|
||||
@@ -79,7 +79,8 @@ export class SmartBuffer {
|
||||
* @param length The number of bytes to pad.
|
||||
*/
|
||||
pad (length: number): void {
|
||||
this._data.push(...Array<number>(length))
|
||||
this._data.push(...Array<number>(length).fill(0))
|
||||
this.cursor += length
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,7 +101,7 @@ export class SmartBuffer {
|
||||
*/
|
||||
splice (start: number, deleteCount: number, ...items: number[]): void {
|
||||
if (this.length < start) {
|
||||
this.pad(start)
|
||||
this._data.push(...Array<number>(start))
|
||||
}
|
||||
this._data.splice(this.cursor, deleteCount, ...items)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user