-
-
Notifications
You must be signed in to change notification settings - Fork 246
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
base: master
Are you sure you want to change the base?
Conversation
// 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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not good
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 |
There was a problem hiding this comment.
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.
client.emit('error', new Error(`Chat index mismatch. Expected: ${client._expectedChatIndex}, got: ${packet.index}`)) | ||
client.end('Chat message received out of order') | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as other comment
// Add checksum for 1.21.5+ | ||
if (mcData.supportFeature('chatChecksum')) { | ||
params.checksum = options.checksum !== undefined ? options.checksum : calculateChecksum(client._lastSeenMessages) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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"?
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).
|
part of 1.21.5 support; tracked at PrismarineJS/mineflayer#3641 |
resolve #1385
Waiting for PrismarineJS/minecraft-data#995 to be merge for minecraft-data to be up to date