Skip to content

Add support for new protocol checksum & chatIndex #1386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RomainNeup
Copy link

@RomainNeup RomainNeup commented Mar 26, 2025

resolve #1385
Waiting for PrismarineJS/minecraft-data#995 to be merge for minecraft-data to be up to date

Comment on lines +222 to +231
// Override and extend logSentMessageFromPeer to increment index
const originalLogSent = client.logSentMessageFromPeer
client.logSentMessageFromPeer = function (chatPacket) {
// Include chat index in outgoing player_chat packets
if (client.supportFeature('chatIndex')) {
chatPacket.index = client._chatMessageIndex++
}

return originalLogSent ? originalLogSent.call(this, chatPacket) : true
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not good

Comment on lines +122 to +126
const calculatedChecksum = calculateChecksum(packet.previousMessages)
if (packet.checksum !== 0 && packet.checksum !== calculatedChecksum) {
debug('Chat checksum mismatch', packet.checksum, calculatedChecksum)
raise('multiplayer.disconnect.chat_validation_failed')
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we should be enforcing all these checks at the library level as opposed to the user level. We did add some abstractions to chat for the purpose of not having to reimplement complex logic on the user's side. Perhaps it would make sense to have these kind of kick checks behind a flag.

Comment on lines +231 to +233
client.emit('error', new Error(`Chat index mismatch. Expected: ${client._expectedChatIndex}, got: ${packet.index}`))
client.end('Chat message received out of order')
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as other comment

Comment on lines +426 to +428
// Add checksum for 1.21.5+
if (mcData.supportFeature('chatChecksum')) {
params.checksum = options.checksum !== undefined ? options.checksum : calculateChecksum(client._lastSeenMessages)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if both the if branches rely on same code you can avoid the duplicate code here by putting it up top

// Calculate checksum for the lastSeen message signatures (1.21.5+)
const calculateChecksum = (lastSeen) => {
if (!mcData.supportFeature('chatChecksum') || !lastSeen || lastSeen.length === 0) {
return 0 // Default value for backward compatibility
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate here what you mean by "backward compatibility"?

@RomainNeup
Copy link
Author

RomainNeup commented Mar 26, 2025

I still have an issue on the client side. I'm investigating, it seems related to the login packet but I checked the protocol (directly by decompiling the client and comparing with 1.21.4) and nothing as changed (at least from my POV).

PartialReadError: Read error for undefined : Missing characters in string, found size is 9 expected size was 12
    at new ExtendableError (/Users/romainneuplanche/Documents/perso/github_public/node-minecraft-protocol/node_modules/protodef/src/utils.js:63:13)
    at new PartialReadError (/Users/romainneuplanche/Documents/perso/github_public/node-minecraft-protocol/node_modules/protodef/src/utils.js:70:5)
    at Object.string (eval at compile (/Users/romainneuplanche/Documents/perso/github_public/node-minecraft-protocol/node_modules/protodef/src/compiler.js:262:12), <anonymous>:106:15)
    at Object.packet_scoreboard_display_objective (eval at compile (/Users/romainneuplanche/Documents/perso/github_public/node-minecraft-protocol/node_modules/protodef/src/compiler.js:262:12), <anonymous>:3360:57)
    at eval (eval at compile (/Users/romainneuplanche/Documents/perso/github_public/node-minecraft-protocol/node_modules/protodef/src/compiler.js:262:12), <anonymous>:4122:96)
    at packet (eval at compile (/Users/romainneuplanche/Documents/perso/github_public/node-minecraft-protocol/node_modules/protodef/src/compiler.js:262:12), <anonymous>:4162:9)
    at CompiledProtodef.read (/Users/romainneuplanche/Documents/perso/github_public/node-minecraft-protocol/node_modules/protodef/src/compiler.js:70:12)
    at e.message (/Users/romainneuplanche/Documents/perso/github_public/node-minecraft-protocol/node_modules/protodef/src/compiler.js:111:49)
    at tryCatch (/Users/romainneuplanche/Documents/perso/github_public/node-minecraft-protocol/node_modules/protodef/src/utils.js:50:16)
    at CompiledProtodef.parsePacketBuffer (/Users/romainneuplanche/Documents/perso/github_public/node-minecraft-protocol/node_modules/protodef/src/compiler.js:111:29)

@rom1504
Copy link
Member

rom1504 commented Apr 27, 2025

part of 1.21.5 support; tracked at PrismarineJS/mineflayer#3641

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support protocol 770 (minecraft pc 1.21.5
3 participants