Fix chat not working on offline servers (#1060)

* Do not acknowledge unsigned messages

* Fix lint

* Parse player data in offline mode

* Fix lint
This commit is contained in:
Frej Alexander Nielsen 2023-01-16 20:36:42 +01:00 committed by GitHub
parent f2875a5f03
commit 4201b94ab8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -71,11 +71,22 @@ module.exports = function (client, options) {
publicKey: crypto.createPublicKey({ key: player.crypto.publicKey, format: 'der', type: 'spki' }), publicKey: crypto.createPublicKey({ key: player.crypto.publicKey, format: 'der', type: 'spki' }),
publicKeyDER: player.crypto.publicKey, publicKeyDER: player.crypto.publicKey,
signature: player.crypto.signature, signature: player.crypto.signature,
displayName: player.displayName || player.name displayName: player.displayName || player.name,
name: player.name
} }
client._players[player.UUID].hasChainIntegrity = true client._players[player.UUID].hasChainIntegrity = true
} else {
client._players[player.UUID] = {
displayName: player.displayName || player.name,
name: player.name
} }
} }
}
} else if (packet.action === 3) {
for (const player of packet.data) {
if (!client._players[player.UUID]) continue
client._players[player.UUID].displayName = player.displayName || client._players[player.UUID].name
}
} else if (packet.action === 4) { // remove player } else if (packet.action === 4) { // remove player
for (const player of packet.data) { for (const player of packet.data) {
delete client._players[player.UUID] delete client._players[player.UUID]
@ -294,6 +305,8 @@ class LastSeenMessages extends Array {
capacity = 5 capacity = 5
pending = 0 pending = 0
push (e) { push (e) {
if (e.signature.length === 0) return // We do not acknowledge unsigned messages
// Insert a new entry at the top and shift everything to the right // Insert a new entry at the top and shift everything to the right
let last = this[0] let last = this[0]
this[0] = e this[0] = e