-
-
Notifications
You must be signed in to change notification settings - Fork 263
Implement signed byte conversion for checksum to fix #3765 #1442
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,11 @@ const concat = require('../transforms/binaryStream').concat | |
| const { processNbtMessage } = require('prismarine-chat') | ||
| const messageExpireTime = 420000 // 7 minutes (ms) | ||
|
|
||
| const toSignedByte = (value) => { | ||
| const byte = value & 0xff | ||
| return byte > 127 ? byte - 256 : byte | ||
| } | ||
|
|
||
| function isFormatted (message) { | ||
| // This should match the ChatComponent.isDecorated function from Vanilla | ||
| try { | ||
|
|
@@ -377,7 +382,7 @@ module.exports = function (client, options) { | |
| salt: options.salt, | ||
| argumentSignatures: canSign ? signaturesForCommand(command, options.timestamp, options.salt, options.preview, acknowledgements) : [], | ||
| messageCount: client._lastSeenMessages.pending, | ||
| checksum: computeChatChecksum(client._lastSeenMessages), // 1.21.5+ | ||
| checksum: toSignedByte(computeChatChecksum(client._lastSeenMessages)), // 1.21.5+ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This branch specifically covers the chat commands only. Is this intentional? Your linked issue PrismarineJS/mineflayer#3765 seems to hint at normal chat messages too
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I only encountered this with commands. Would you mind using my fix yourself? It's easier than me doing it |
||
| acknowledged | ||
| } | ||
| client.write((mcData.supportFeature('seperateSignedChatCommandPacket') && canSign) ? 'chat_command_signed' : 'chat_command', chatPacket) | ||
|
|
||
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.
Consider moving the toSignedByte function to src/datatypes/checksums.js and exporting it alongside computeChatChecksum. This would improve code organization by grouping related checksum functionality together and make the function reusable if needed elsewhere. The function is specifically designed to handle the signed byte requirement for checksums in the Minecraft protocol.
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.
@copilot coauthor pr #1442 based on this this feedback