11diff --git a/src/client/chat.js b/src/client/chat.js
2- index 8d0869b150681574ad19292a026cce9f67a137ee..2efa2e6600f017b566155974cb9fb1856fa582f9 100644
2+ index 0021870994fc59a82f0ac8aba0a65a8be43ef2f4..a53fceb843105ea2a1d88722b3fc7c3b43cb102a 100644
33--- a/src/client/chat.js
44+++ b/src/client/chat.js
5- @@ -109 ,7 +109 ,7 @@ module.exports = function (client, options) {
5+ @@ -116 ,7 +116 ,7 @@ module.exports = function (client, options) {
66 for (const player of packet.data) {
77 if (player.chatSession) {
88 client._players[player.uuid] = {
@@ -11,7 +11,7 @@ index 8d0869b150681574ad19292a026cce9f67a137ee..2efa2e6600f017b566155974cb9fb185
1111 publicKeyDER: player.chatSession.publicKey.keyBytes,
1212 sessionUuid: player.chatSession.uuid
1313 }
14- @@ -119 ,7 +119 ,7 @@ module.exports = function (client, options) {
14+ @@ -126 ,7 +126 ,7 @@ module.exports = function (client, options) {
1515
1616 if (player.crypto) {
1717 client._players[player.uuid] = {
@@ -20,16 +20,16 @@ index 8d0869b150681574ad19292a026cce9f67a137ee..2efa2e6600f017b566155974cb9fb185
2020 publicKeyDER: player.crypto.publicKey,
2121 signature: player.crypto.signature,
2222 displayName: player.displayName || player.name
23- @@ -189 ,7 +189 ,7 @@ module.exports = function (client, options) {
23+ @@ -196 ,7 +196 ,7 @@ module.exports = function (client, options) {
2424 if (mcData.supportFeature('useChatSessions')) {
2525 const tsDelta = BigInt(Date.now()) - packet.timestamp
2626 const expired = !packet.timestamp || tsDelta > messageExpireTime || tsDelta < 0
2727- const verified = !packet.unsignedChatContent && updateAndValidateSession(packet.senderUuid, packet.plainMessage, packet.signature, packet.index, packet.previousMessages, packet.salt, packet.timestamp) && !expired
2828+ const verified = false && !packet.unsignedChatContent && updateAndValidateSession(packet.senderUuid, packet.plainMessage, packet.signature, packet.index, packet.previousMessages, packet.salt, packet.timestamp) && !expired
2929 if (verified) client._signatureCache.push(packet.signature)
3030 client.emit('playerChat', {
31- plainMessage : packet.plainMessage ,
32- @@ -354 ,7 +354 ,7 @@ module.exports = function (client, options) {
31+ globalIndex : packet.globalIndex ,
32+ @@ -362 ,7 +362 ,7 @@ module.exports = function (client, options) {
3333 }
3434 }
3535
@@ -38,16 +38,16 @@ index 8d0869b150681574ad19292a026cce9f67a137ee..2efa2e6600f017b566155974cb9fb185
3838 options.timestamp = options.timestamp || BigInt(Date.now())
3939 options.salt = options.salt || 1n
4040
41- @@ -396 ,7 +396 ,7 @@ module.exports = function (client, options) {
41+ @@ -407 ,7 +407 ,7 @@ module.exports = function (client, options) {
4242 message,
4343 timestamp: options.timestamp,
4444 salt: options.salt,
4545- signature: (client.profileKeys && client._session) ? client.signMessage(message, options.timestamp, options.salt, undefined, acknowledgements) : undefined,
4646+ signature: (client.profileKeys && client._session) ? await client.signMessage(message, options.timestamp, options.salt, undefined, acknowledgements) : undefined,
4747 offset: client._lastSeenMessages.pending,
48+ checksum: computeChatChecksum(client._lastSeenMessages), // 1.21.5+
4849 acknowledged
49- })
50- @@ -410,7 +410,7 @@ module.exports = function (client, options) {
50+ @@ -422,7 +422,7 @@ module.exports = function (client, options) {
5151 message,
5252 timestamp: options.timestamp,
5353 salt: options.salt,
@@ -57,7 +57,7 @@ index 8d0869b150681574ad19292a026cce9f67a137ee..2efa2e6600f017b566155974cb9fb185
5757 previousMessages: client._lastSeenMessages.map((e) => ({
5858 messageSender: e.sender,
5959diff --git a/src/client/encrypt.js b/src/client/encrypt.js
60- index b9d21bab9faccd5dbf1975fc423fc55c73e906c5..99ffd76527b410e3a393181beb260108f4c63536 100644
60+ index 63cc2bd9615100bd2fd63dfe14c094aa6b8cd1c9..36df57d1196af9761d920fa285ac48f85410eaef 100644
6161--- a/src/client/encrypt.js
6262+++ b/src/client/encrypt.js
6363@@ -25,7 +25,11 @@ module.exports = function (client, options) {
@@ -73,41 +73,11 @@ index b9d21bab9faccd5dbf1975fc423fc55c73e906c5..99ffd76527b410e3a393181beb260108
7373 }
7474
7575 function onJoinServerResponse (err) {
76- diff --git a/src/client/play.js b/src/client/play.js
77- index 559607f34e9a5b2b7809423f8ca4cd6746b60225..4dc1c3139438cc2729b05c57e57bd00252728f8a 100644
78- --- a/src/client/play.js
79- +++ b/src/client/play.js
80- @@ -53,7 +53,7 @@ module.exports = function (client, options) {
81- client.write('configuration_acknowledged', {})
82- }
83- client.state = states.CONFIGURATION
84- - client.on('select_known_packs', () => {
85- + client.once('select_known_packs', () => {
86- client.write('select_known_packs', { packs: [] })
87- })
88- // Server should send finish_configuration on its own right after sending the client a dimension codec
8976diff --git a/src/client.js b/src/client.js
90- index 5c7a62b013daa69be91ec9e763b1f48ffe96ffa6..174d42a77740a937afcb106e1f39a9ee824a24b9 100644
77+ index e369e77d055ba919e8f9da7b8e8b5dc879c74cf4..54bb9e6644388e9b6bd42b3012951875989cdf0c 100644
9178--- a/src/client.js
9279+++ b/src/client.js
93- @@ -89,10 +89,12 @@ class Client extends EventEmitter {
94- parsed.metadata.name = parsed.data.name
95- parsed.data = parsed.data.params
96- parsed.metadata.state = state
97- - debug('read packet ' + state + '.' + parsed.metadata.name)
98- - if (debug.enabled) {
99- - const s = JSON.stringify(parsed.data, null, 2)
100- - debug(s && s.length > 10000 ? parsed.data : s)
101- + if (!globalThis.excludeCommunicationDebugEvents?.includes(parsed.metadata.name)) {
102- + debug('read packet ' + state + '.' + parsed.metadata.name)
103- + if (debug.enabled) {
104- + const s = JSON.stringify(parsed.data, null, 2)
105- + debug(s && s.length > 10000 ? parsed.data : s)
106- + }
107- }
108- if (this._hasBundlePacket && parsed.metadata.name === 'bundle_delimiter') {
109- if (this._mcBundle.length) { // End bundle
110- @@ -110,7 +112,13 @@ class Client extends EventEmitter {
80+ @@ -111,7 +111,13 @@ class Client extends EventEmitter {
11181 this._hasBundlePacket = false
11282 }
11383 } else {
@@ -122,7 +92,7 @@ index 5c7a62b013daa69be91ec9e763b1f48ffe96ffa6..174d42a77740a937afcb106e1f39a9ee
12292 }
12393 })
12494 }
125- @@ -168 ,7 +176 ,10 @@ class Client extends EventEmitter {
95+ @@ -169 ,7 +175 ,10 @@ class Client extends EventEmitter {
12696 }
12797
12898 const onFatalError = (err) => {
@@ -134,25 +104,21 @@ index 5c7a62b013daa69be91ec9e763b1f48ffe96ffa6..174d42a77740a937afcb106e1f39a9ee
134104 endSocket()
135105 }
136106
137- @@ -197 ,6 +208,8 @@ class Client extends EventEmitter {
107+ @@ -198 ,6 +207,10 @@ class Client extends EventEmitter {
138108 serializer -> framer -> socket -> splitter -> deserializer */
139109 if (this.serializer) {
140110 this.serializer.end()
141- + this.socket?.end()
142- + this.socket?.emit('end')
111+ + setTimeout(() => {
112+ + this.socket?.end()
113+ + this.socket?.emit('end')
114+ + }, 2000) // allow the serializer to finish writing
143115 } else {
144116 if (this.socket) this.socket.end()
145117 }
146- @@ -238,8 +251,11 @@ class Client extends EventEmitter {
147-
148- write (name, params) {
149- if (!this.serializer.writable) { return }
150- - debug('writing packet ' + this.state + '.' + name)
151- - debug(params)
152- + if (!globalThis.excludeCommunicationDebugEvents?.includes(name)) {
153- + debug(`[${this.state}] from ${this.isServer ? 'server' : 'client'}: ` + name)
154- + debug(params)
155- + }
118+ @@ -243,6 +256,7 @@ class Client extends EventEmitter {
119+ debug('writing packet ' + this.state + '.' + name)
120+ debug(params)
121+ }
156122+ this.emit('writePacket', name, params)
157123 this.serializer.write({ name, params })
158124 }
0 commit comments