159 lines
7.5 KiB
Diff
159 lines
7.5 KiB
Diff
diff --git a/src/client/chat.js b/src/client/chat.js
|
|
index 8d0869b150681574ad19292a026cce9f67a137ee..2efa2e6600f017b566155974cb9fb1856fa582f9 100644
|
|
--- a/src/client/chat.js
|
|
+++ b/src/client/chat.js
|
|
@@ -109,7 +109,7 @@ module.exports = function (client, options) {
|
|
for (const player of packet.data) {
|
|
if (player.chatSession) {
|
|
client._players[player.uuid] = {
|
|
- publicKey: crypto.createPublicKey({ key: player.chatSession.publicKey.keyBytes, format: 'der', type: 'spki' }),
|
|
+ // publicKey: crypto.createPublicKey({ key: player.chatSession.publicKey.keyBytes, format: 'der', type: 'spki' }),
|
|
publicKeyDER: player.chatSession.publicKey.keyBytes,
|
|
sessionUuid: player.chatSession.uuid
|
|
}
|
|
@@ -119,7 +119,7 @@ module.exports = function (client, options) {
|
|
|
|
if (player.crypto) {
|
|
client._players[player.uuid] = {
|
|
- publicKey: crypto.createPublicKey({ key: player.crypto.publicKey, format: 'der', type: 'spki' }),
|
|
+ // publicKey: crypto.createPublicKey({ key: player.crypto.publicKey, format: 'der', type: 'spki' }),
|
|
publicKeyDER: player.crypto.publicKey,
|
|
signature: player.crypto.signature,
|
|
displayName: player.displayName || player.name
|
|
@@ -189,7 +189,7 @@ module.exports = function (client, options) {
|
|
if (mcData.supportFeature('useChatSessions')) {
|
|
const tsDelta = BigInt(Date.now()) - packet.timestamp
|
|
const expired = !packet.timestamp || tsDelta > messageExpireTime || tsDelta < 0
|
|
- const verified = !packet.unsignedChatContent && updateAndValidateSession(packet.senderUuid, packet.plainMessage, packet.signature, packet.index, packet.previousMessages, packet.salt, packet.timestamp) && !expired
|
|
+ const verified = false && !packet.unsignedChatContent && updateAndValidateSession(packet.senderUuid, packet.plainMessage, packet.signature, packet.index, packet.previousMessages, packet.salt, packet.timestamp) && !expired
|
|
if (verified) client._signatureCache.push(packet.signature)
|
|
client.emit('playerChat', {
|
|
plainMessage: packet.plainMessage,
|
|
@@ -354,7 +354,7 @@ module.exports = function (client, options) {
|
|
}
|
|
}
|
|
|
|
- client._signedChat = (message, options = {}) => {
|
|
+ client._signedChat = async (message, options = {}) => {
|
|
options.timestamp = options.timestamp || BigInt(Date.now())
|
|
options.salt = options.salt || 1n
|
|
|
|
@@ -396,7 +396,7 @@ module.exports = function (client, options) {
|
|
message,
|
|
timestamp: options.timestamp,
|
|
salt: options.salt,
|
|
- signature: (client.profileKeys && client._session) ? client.signMessage(message, options.timestamp, options.salt, undefined, acknowledgements) : undefined,
|
|
+ signature: (client.profileKeys && client._session) ? await client.signMessage(message, options.timestamp, options.salt, undefined, acknowledgements) : undefined,
|
|
offset: client._lastSeenMessages.pending,
|
|
acknowledged
|
|
})
|
|
@@ -410,7 +410,7 @@ module.exports = function (client, options) {
|
|
message,
|
|
timestamp: options.timestamp,
|
|
salt: options.salt,
|
|
- signature: client.profileKeys ? client.signMessage(message, options.timestamp, options.salt, options.preview) : Buffer.alloc(0),
|
|
+ signature: client.profileKeys ? await client.signMessage(message, options.timestamp, options.salt, options.preview) : Buffer.alloc(0),
|
|
signedPreview: options.didPreview,
|
|
previousMessages: client._lastSeenMessages.map((e) => ({
|
|
messageSender: e.sender,
|
|
diff --git a/src/client/encrypt.js b/src/client/encrypt.js
|
|
index b9d21bab9faccd5dbf1975fc423fc55c73e906c5..99ffd76527b410e3a393181beb260108f4c63536 100644
|
|
--- a/src/client/encrypt.js
|
|
+++ b/src/client/encrypt.js
|
|
@@ -25,7 +25,11 @@ module.exports = function (client, options) {
|
|
if (packet.serverId !== '-') {
|
|
debug('This server appears to be an online server and you are providing no password, the authentication will probably fail')
|
|
}
|
|
- sendEncryptionKeyResponse()
|
|
+ client.end('This server appears to be an online server and you are providing no authentication. Try authenticating first.')
|
|
+ // sendEncryptionKeyResponse()
|
|
+ // client.once('set_compression', () => {
|
|
+ // clearTimeout(loginTimeout)
|
|
+ // })
|
|
}
|
|
|
|
function onJoinServerResponse (err) {
|
|
diff --git a/src/client/play.js b/src/client/play.js
|
|
index 559607f34e9a5b2b7809423f8ca4cd6746b60225..4dc1c3139438cc2729b05c57e57bd00252728f8a 100644
|
|
--- a/src/client/play.js
|
|
+++ b/src/client/play.js
|
|
@@ -53,7 +53,7 @@ module.exports = function (client, options) {
|
|
client.write('configuration_acknowledged', {})
|
|
}
|
|
client.state = states.CONFIGURATION
|
|
- client.on('select_known_packs', () => {
|
|
+ client.once('select_known_packs', () => {
|
|
client.write('select_known_packs', { packs: [] })
|
|
})
|
|
// Server should send finish_configuration on its own right after sending the client a dimension codec
|
|
diff --git a/src/client.js b/src/client.js
|
|
index 5c7a62b013daa69be91ec9e763b1f48ffe96ffa6..174d42a77740a937afcb106e1f39a9ee824a24b9 100644
|
|
--- a/src/client.js
|
|
+++ b/src/client.js
|
|
@@ -89,10 +89,12 @@ class Client extends EventEmitter {
|
|
parsed.metadata.name = parsed.data.name
|
|
parsed.data = parsed.data.params
|
|
parsed.metadata.state = state
|
|
- debug('read packet ' + state + '.' + parsed.metadata.name)
|
|
- if (debug.enabled) {
|
|
- const s = JSON.stringify(parsed.data, null, 2)
|
|
- debug(s && s.length > 10000 ? parsed.data : s)
|
|
+ if (!globalThis.excludeCommunicationDebugEvents?.includes(parsed.metadata.name)) {
|
|
+ debug('read packet ' + state + '.' + parsed.metadata.name)
|
|
+ if (debug.enabled) {
|
|
+ const s = JSON.stringify(parsed.data, null, 2)
|
|
+ debug(s && s.length > 10000 ? parsed.data : s)
|
|
+ }
|
|
}
|
|
if (this._hasBundlePacket && parsed.metadata.name === 'bundle_delimiter') {
|
|
if (this._mcBundle.length) { // End bundle
|
|
@@ -110,7 +112,13 @@ class Client extends EventEmitter {
|
|
this._hasBundlePacket = false
|
|
}
|
|
} else {
|
|
- emitPacket(parsed)
|
|
+ try {
|
|
+ emitPacket(parsed)
|
|
+ } catch (err) {
|
|
+ console.log('Client incorrectly handled packet ' + parsed.metadata.name)
|
|
+ console.error(err)
|
|
+ // todo investigate why it doesn't close the stream even if unhandled there
|
|
+ }
|
|
}
|
|
})
|
|
}
|
|
@@ -168,7 +176,10 @@ class Client extends EventEmitter {
|
|
}
|
|
|
|
const onFatalError = (err) => {
|
|
- this.emit('error', err)
|
|
+ // todo find out what is trying to write after client disconnect
|
|
+ if(err.code !== 'ECONNABORTED') {
|
|
+ this.emit('error', err)
|
|
+ }
|
|
endSocket()
|
|
}
|
|
|
|
@@ -197,6 +208,8 @@ class Client extends EventEmitter {
|
|
serializer -> framer -> socket -> splitter -> deserializer */
|
|
if (this.serializer) {
|
|
this.serializer.end()
|
|
+ this.socket?.end()
|
|
+ this.socket?.emit('end')
|
|
} else {
|
|
if (this.socket) this.socket.end()
|
|
}
|
|
@@ -238,8 +251,11 @@ class Client extends EventEmitter {
|
|
|
|
write (name, params) {
|
|
if (!this.serializer.writable) { return }
|
|
- debug('writing packet ' + this.state + '.' + name)
|
|
- debug(params)
|
|
+ if (!globalThis.excludeCommunicationDebugEvents?.includes(name)) {
|
|
+ debug(`[${this.state}] from ${this.isServer ? 'server' : 'client'}: ` + name)
|
|
+ debug(params)
|
|
+ }
|
|
+ this.emit('writePacket', name, params)
|
|
this.serializer.write({ name, params })
|
|
}
|
|
|