node-minecraft-protocol/test/common/clientHelpers.js
extremeheat d7c5053a13
1.19.0 support (#1027)
* Bump mcdata for 1.19

* 1.19 in version.js

* 1.19.0 in ci yml

* Update ci.yml

* Update version.js

* Update package.json

* No fail fast

* Update mcdata

* Update package.json

* Update ci.yml

* [1.19] fix tests and library session code (#1020)

* make tests work, add todo's

* clean up, varlong test, additional todo

* removed log statements, fix for older versions

* Update mcdata

* Update ci.yml

* Update ci.yml

* remove excessive version comments near supportFeature checks

Co-authored-by: Romain Beaumont <romain.rom1@gmail.com>

* chat signing implementation

* Update ci.yml

* move some boilerplate to pauth

* update tests

* update chat example

* bump pauth, update doc

* modify test nextMessage func

* lint

* update default version

* add server player verifyMessage

* update doc

Co-authored-by: Romain Beaumont <romain.rom1@gmail.com>
Co-authored-by: Rob9315 <dev.robk@gmail.com>
2022-08-16 00:57:26 +02:00

39 lines
1,012 B
JavaScript

module.exports = client => {
const mcData = require('minecraft-data')(client.version)
const hasSignedChat = mcData.supportFeature('signedChat')
client.chat = (message) => {
if (hasSignedChat) {
const timestamp = BigInt(Date.now())
client.write('chat_message', {
message,
timestamp,
salt: 0,
signature: Buffer.alloc(0)
})
} else {
client.write('chat', { message })
}
}
client.nextMessage = (containing) => {
return new Promise((resolve) => {
function onChat (packet) {
const m = packet.message || packet.unsignedChatContent || packet.signedChatContent
if (containing) {
if (m.includes(containing)) return finish(m)
else return
}
return finish(m)
}
client.on(hasSignedChat ? 'player_chat' : 'chat', onChat)
function finish (m) {
client.off(hasSignedChat ? 'player_chat' : 'chat', onChat)
resolve(m)
}
})
}
return client
}