-
-
Notifications
You must be signed in to change notification settings - Fork 239
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
1.20.3 / 1.20.4 support #1275
Merged
Merged
1.20.3 / 1.20.4 support #1275
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7a4d062
Inital 1.20.3 update, bring in minecraft-data with 1.20.3 support and…
wgaylord e754dba
Add data for packetTest for explosion packet.
wgaylord 180c062
Add 1.20.4 to version list.
wgaylord 772c3ec
Add fix for 1.20.3+ NBT isntead of strings for chat. Not happy with t…
wgaylord 8cefb08
Fix linting
wgaylord 5b8cf1b
Update version.js
wgaylord 8fb7f47
Comment how handleNBTStrings works.
wgaylord 2a4a936
Removed debug console.log
wgaylord b2ccd56
Update README.md
rom1504 a5b6871
chat packet nbt handling fix, use feature
extremeheat 7fe88a3
big endian UUID, add back `text` wrapper
extremeheat 0215418
use prismarine-chat in client test
extremeheat 4b58bef
expose _handleNbtComponent
extremeheat be8d53a
use prismarine-chat exposed processNbtMessage
extremeheat f5c1953
fix pre-1.20.4
extremeheat bcbe562
Update package.json
rom1504 0b3c880
Update server.js
extremeheat 185450f
Update server.js
extremeheat df4af75
update server hello world
rom1504 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
const crypto = require('crypto') | ||
const concat = require('../transforms/binaryStream').concat | ||
const nbt = require('prismarine-nbt') | ||
const uuid = require('../datatypes/uuid') | ||
const messageExpireTime = 420000 // 7 minutes (ms) | ||
|
||
function isFormatted (message) { | ||
|
@@ -22,6 +24,22 @@ module.exports = function (client, options) { | |
client._lastChatSignature = null | ||
client._lastRejectedMessage = null | ||
|
||
// 1.20.3+ serializes chat components in chat packets with NBT. Non-chat packets that send messages (like disconnect) still use JSON chat. | ||
// NMP API expects a JSON string, so since the schema is mostly the same we can convert the NBT to JSON with a transform to UUID encoding | ||
function handleNbtComponent (nbtDataOrString) { | ||
if (mcData.supportFeature('chatPacketsUseNbtComponents') && nbtDataOrString) { | ||
// UUIDs are encoded in NBT as a 4x i32 array, so convert to a hex string | ||
const simplified = nbt.simplify(nbtDataOrString) | ||
return JSON.stringify(simplified, (key, val) => { | ||
if (key === 'id' && Array.isArray(val)) return uuid.fromIntArray(val) | ||
return val | ||
}) | ||
} | ||
// already plaintext JSON or empty | ||
return nbtDataOrString | ||
} | ||
client._handleNbtComponent = handleNbtComponent | ||
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. why is this exposed privately and then not used? if we want to actually expose it, it should be exposed publicly (without _ and in API.md) |
||
|
||
// This stores the last n (5 or 20) messages that the player has seen, from unique players | ||
if (mcData.supportFeature('chainedChatWithHashing')) client._lastSeenMessages = new LastSeenMessages() | ||
else client._lastSeenMessages = new LastSeenMessagesWithInvalidation() | ||
|
@@ -139,12 +157,11 @@ module.exports = function (client, options) { | |
|
||
client.on('profileless_chat', (packet) => { | ||
// Profileless chat is parsed as an unsigned player chat message but logged as a system message | ||
|
||
client.emit('playerChat', { | ||
formattedMessage: packet.message, | ||
formattedMessage: handleNbtComponent(packet.message), | ||
type: packet.type, | ||
senderName: packet.name, | ||
targetName: packet.target, | ||
senderName: handleNbtComponent(packet.name), | ||
targetName: handleNbtComponent(packet.target), | ||
verified: false | ||
}) | ||
|
||
|
@@ -160,7 +177,7 @@ module.exports = function (client, options) { | |
client.on('system_chat', (packet) => { | ||
client.emit('systemChat', { | ||
positionId: packet.isActionBar ? 2 : 1, | ||
formattedMessage: packet.content | ||
formattedMessage: handleNbtComponent(packet.content) | ||
}) | ||
|
||
client._lastChatHistory.push({ | ||
|
@@ -198,11 +215,11 @@ module.exports = function (client, options) { | |
if (verified) client._signatureCache.push(packet.signature) | ||
client.emit('playerChat', { | ||
plainMessage: packet.plainMessage, | ||
unsignedContent: packet.unsignedChatContent, | ||
unsignedContent: handleNbtComponent(packet.unsignedChatContent), | ||
type: packet.type, | ||
sender: packet.senderUuid, | ||
senderName: packet.networkName, | ||
targetName: packet.networkTargetName, | ||
senderName: handleNbtComponent(packet.networkName), | ||
targetName: handleNbtComponent(packet.networkTargetName), | ||
verified | ||
}) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
defaultVersion: '1.20.2', | ||
supportedVersions: ['1.7', '1.8.8', '1.9.4', '1.10.2', '1.11.2', '1.12.2', '1.13.2', '1.14.4', '1.15.2', '1.16.5', '1.17.1', '1.18.2', '1.19', '1.19.2', '1.19.3', '1.19.4', '1.20', '1.20.1', '1.20.2'] | ||
defaultVersion: '1.20.4', | ||
supportedVersions: ['1.7', '1.8.8', '1.9.4', '1.10.2', '1.11.2', '1.12.2', '1.13.2', '1.14.4', '1.15.2', '1.16.5', '1.17.1', '1.18.2', '1.19', '1.19.2', '1.19.3', '1.19.4', '1.20', '1.20.1', '1.20.2', '1.20.4'] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,6 +208,10 @@ const values = { | |
packedChunkPos: { | ||
x: 10, | ||
z: 12 | ||
}, | ||
particle: { | ||
particleId: 0, | ||
data: null | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think we should expose that function here or in pchat so that mineflayer and flying-squid can use it
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 added prismarine-chat to the test code so it's cleaner (as opposed to handling chat internally), but otherwise there isn't much to add to prismarine-chat. The
handleNbtComponent
basically just calls simplify and does some mapping for UUIDs.But I guess there could be a
ChatMessage.fromNbtComponent()
inside prismarine-chat to get a ChatMessage directly. But would it would require a change in nmp API asplayerChat
andsystemChat
current expect JSON strings, not ChatMessage'sThere 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.
my concern is how do we handle the "chat nbt" in the 10 other non-chat packets where that "chat nbt" is used in mineflayer?
I can see these solutions
I think 3 or 4 are better.
2 is okay
1 I don't think it's a good idea
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.
https://github.com/PrismarineJS/minecraft-data/blob/master/data/pc/1.20.3/protocol.json look for all occurences of anonymousNbt
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.
Ah yeah I see, looks like will need some changes to all node-minecraft-protocol, prismarine-chat, mineflayer to swap the event from JSON string to a ChatMessage for #4. Maybe updating fromNotch() to and then emitting the ChatMessage:
However doing this would break the fromNetwork in prismarine-chat as it expects a JSON object when formatting the chat string, so that too would need to be updated.
Would also need to figure out a good way to do toNotch()
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.
maybe we should expose an independent method in pchat
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.
but yeah hmm let's figure out how to unblock this