Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/client/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,16 +413,18 @@ module.exports = function (client, options) {
if (mcData.supportFeature('useChatSessions')) { // 1.19.3+
const { acknowledged, acknowledgements } = getAcknowledgements()
const canSign = client.profileKeys && client._session
const argumentSignatures = canSign ? signaturesForCommand(command, options.timestamp, options.salt, options.preview, acknowledgements) : []
const chatPacket = {
command,
timestamp: options.timestamp,
salt: options.salt,
argumentSignatures: canSign ? signaturesForCommand(command, options.timestamp, options.salt, options.preview, acknowledgements) : [],
argumentSignatures,
messageCount: client._lastSeenMessages.pending,
checksum: computeChatChecksum(client._lastSeenMessages), // 1.21.5+
acknowledged
}
client.write((mcData.supportFeature('seperateSignedChatCommandPacket') && canSign) ? 'chat_command_signed' : 'chat_command', chatPacket)
// A command with nothing to sign goes as the unsigned chat_command whether or not the client can sign.
client.write((mcData.supportFeature('seperateSignedChatCommandPacket') && argumentSignatures.length > 0) ? 'chat_command_signed' : 'chat_command', chatPacket)
client._lastSeenMessages.pending = 0
} else {
client.write('chat_command', {
Expand Down
57 changes: 57 additions & 0 deletions test/declareCommandsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,61 @@ describe('declare_commands handling', () => {
assert.strictEqual(writes[0].name, 'chat_command_signed')
assert.deepStrictEqual(writes[0].data.argumentSignatures.map(sig => sig.argumentName), ['message'])
})

it('sends a command with no signable argument as the unsigned packet', () => {
const client = new EventEmitter()
client.version = '26.1'
client.verifyMessage = () => true
client.profileKeys = true
client._session = { uuid: '00000000-0000-0000-0000-000000000000' }

const writes = []
client.write = (name, data) => writes.push({ name, data })

injectChatPlugin(client, {})
client.signMessage = () => Buffer.from([1])

client.emit('declare_commands', {
rootIndex: 0,
nodes: [
{ children: [1] },
{ children: [2], extraNodeData: { name: 'msg' } },
{ children: [], extraNodeData: { name: 'message', parser: 'minecraft:message' } }
]
})

client._signedChat('/login hunter2', { timestamp: 1n, salt: 1n })

assert.strictEqual(writes.length, 1)
assert.strictEqual(writes[0].name, 'chat_command')
assert.deepStrictEqual(writes[0].data.argumentSignatures, [])
})

it('sends a known command without arguments as the unsigned packet', () => {
const client = new EventEmitter()
client.version = '26.1'
client.verifyMessage = () => true
client.profileKeys = true
client._session = { uuid: '00000000-0000-0000-0000-000000000000' }

const writes = []
client.write = (name, data) => writes.push({ name, data })

injectChatPlugin(client, {})
client.signMessage = () => Buffer.from([1])

client.emit('declare_commands', {
rootIndex: 0,
nodes: [
{ children: [1] },
{ children: [2], extraNodeData: { name: 'msg' } },
{ children: [], extraNodeData: { name: 'message', parser: 'minecraft:message' } }
]
})

client._signedChat('/msg', { timestamp: 1n, salt: 1n })

assert.strictEqual(writes.length, 1)
assert.strictEqual(writes[0].name, 'chat_command')
})
})
Loading