Skip to content

Commit 24ab260

Browse files
committed
fix: up protocol to support 1.21.5
1 parent c4b284b commit 24ab260

File tree

2 files changed

+101
-86
lines changed

2 files changed

+101
-86
lines changed

patches/minecraft-protocol.patch

Lines changed: 62 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
diff --git a/src/client/chat.js b/src/client/chat.js
2-
index 8d0869b150681574ad19292a026cce9f67a137ee..2efa2e6600f017b566155974cb9fb1856fa582f9 100644
2+
index a50f4b988ad9fb29d5eb9e1633b498615aa9cd28..b8b819eef0762a77d9db5c0fb06be648303628c7 100644
33
--- a/src/client/chat.js
44
+++ b/src/client/chat.js
5-
@@ -109,7 +109,7 @@ module.exports = function (client, options) {
5+
@@ -110,7 +110,7 @@ module.exports = function (client, options) {
66
for (const player of packet.data) {
77
if (player.chatSession) {
88
client._players[player.uuid] = {
@@ -11,43 +11,43 @@ 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) {
15-
14+
@@ -120,7 +120,7 @@ module.exports = function (client, options) {
15+
1616
if (player.crypto) {
1717
client._players[player.uuid] = {
1818
- publicKey: crypto.createPublicKey({ key: player.crypto.publicKey, format: 'der', type: 'spki' }),
1919
+ // publicKey: crypto.createPublicKey({ key: player.crypto.publicKey, format: 'der', type: 'spki' }),
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+
@@ -190,7 +190,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+
@@ -356,7 +356,7 @@ module.exports = function (client, options) {
3333
}
3434
}
35-
35+
3636
- client._signedChat = (message, options = {}) => {
3737
+ client._signedChat = async (message, options = {}) => {
3838
options.timestamp = options.timestamp || BigInt(Date.now())
3939
options.salt = options.salt || 1n
40-
41-
@@ -396,7 +396,7 @@ module.exports = function (client, options) {
40+
41+
@@ -401,7 +401,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+
@@ -416,7 +416,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,
5959
diff --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) {
@@ -71,7 +71,7 @@ index b9d21bab9faccd5dbf1975fc423fc55c73e906c5..99ffd76527b410e3a393181beb260108
7171
+ // clearTimeout(loginTimeout)
7272
+ // })
7373
}
74-
74+
7575
function onJoinServerResponse (err) {
7676
diff --git a/src/client/play.js b/src/client/play.js
7777
index 559607f34e9a5b2b7809423f8ca4cd6746b60225..4dc1c3139438cc2729b05c57e57bd00252728f8a 100644
@@ -87,27 +87,10 @@ index 559607f34e9a5b2b7809423f8ca4cd6746b60225..4dc1c3139438cc2729b05c57e57bd002
8787
})
8888
// Server should send finish_configuration on its own right after sending the client a dimension codec
8989
diff --git a/src/client.js b/src/client.js
90-
index 5c7a62b013daa69be91ec9e763b1f48ffe96ffa6..174d42a77740a937afcb106e1f39a9ee824a24b9 100644
90+
index e369e77d055ba919e8f9da7b8e8b5dc879c74cf4..11c6bff299f1186ab1ecb6744f53ff0c648ab192 100644
9191
--- a/src/client.js
9292
+++ 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 {
93+
@@ -111,7 +111,13 @@ class Client extends EventEmitter {
11194
this._hasBundlePacket = false
11295
}
11396
} else {
@@ -122,9 +105,9 @@ index 5c7a62b013daa69be91ec9e763b1f48ffe96ffa6..174d42a77740a937afcb106e1f39a9ee
122105
}
123106
})
124107
}
125-
@@ -168,7 +176,10 @@ class Client extends EventEmitter {
108+
@@ -169,7 +175,10 @@ class Client extends EventEmitter {
126109
}
127-
110+
128111
const onFatalError = (err) => {
129112
- this.emit('error', err)
130113
+ // todo find out what is trying to write after client disconnect
@@ -133,8 +116,8 @@ index 5c7a62b013daa69be91ec9e763b1f48ffe96ffa6..174d42a77740a937afcb106e1f39a9ee
133116
+ }
134117
endSocket()
135118
}
136-
137-
@@ -197,6 +208,8 @@ class Client extends EventEmitter {
119+
120+
@@ -198,6 +207,8 @@ class Client extends EventEmitter {
138121
serializer -> framer -> socket -> splitter -> deserializer */
139122
if (this.serializer) {
140123
this.serializer.end()
@@ -143,17 +126,48 @@ index 5c7a62b013daa69be91ec9e763b1f48ffe96ffa6..174d42a77740a937afcb106e1f39a9ee
143126
} else {
144127
if (this.socket) this.socket.end()
145128
}
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-
+ }
129+
@@ -243,6 +254,7 @@ class Client extends EventEmitter {
130+
debug('writing packet ' + this.state + '.' + name)
131+
debug(params)
132+
}
156133
+ this.emit('writePacket', name, params)
157134
this.serializer.write({ name, params })
158135
}
159-
136+
137+
diff --git a/src/client.js.rej b/src/client.js.rej
138+
new file mode 100644
139+
index 0000000000000000000000000000000000000000..1101e2477adfdc004381b78e7d70953dacb7b484
140+
--- /dev/null
141+
+++ b/src/client.js.rej
142+
@@ -0,0 +1,31 @@
143+
+@@ -89,10 +89,12 @@
144+
+ parsed.metadata.name = parsed.data.name
145+
+ parsed.data = parsed.data.params
146+
+ parsed.metadata.state = state
147+
+- debug('read packet ' + state + '.' + parsed.metadata.name)
148+
+- if (debug.enabled) {
149+
+- const s = JSON.stringify(parsed.data, null, 2)
150+
+- debug(s && s.length > 10000 ? parsed.data : s)
151+
++ if (!globalThis.excludeCommunicationDebugEvents?.includes(parsed.metadata.name)) {
152+
++ debug('read packet ' + state + '.' + parsed.metadata.name)
153+
++ if (debug.enabled) {
154+
++ const s = JSON.stringify(parsed.data, null, 2)
155+
++ debug(s && s.length > 10000 ? parsed.data : s)
156+
++ }
157+
+ }
158+
+ if (this._hasBundlePacket && parsed.metadata.name === 'bundle_delimiter') {
159+
+ if (this._mcBundle.length) { // End bundle
160+
+@@ -239,8 +252,11 @@
161+
+
162+
+ write (name, params) {
163+
+ if (!this.serializer.writable) { return }
164+
+- debug('writing packet ' + this.state + '.' + name)
165+
+- debug(params)
166+
++ if (!globalThis.excludeCommunicationDebugEvents?.includes(name)) {
167+
++ debug(`[${this.state}] from ${this.isServer ? 'server' : 'client'}: ` + name)
168+
++ debug(params)
169+
++ }
170+
++ this.emit('writePacket', name, params)
171+
+ this.serializer.write({ name, params })
172+
+ }
173+
+

0 commit comments

Comments
 (0)