@@ -9,9 +9,16 @@ import {
99 type ConnectionOptions ,
1010 ConnectionState
1111} from '.'
12+ import { type MinecraftChat } from '../chatToJsx'
1213import { concatPacketData , type Packet } from '../packet'
1314import { getLoginPacket , handleEncryptionRequest } from './shared'
14- import { readVarInt , writeVarInt , resolveHostname , protocolMap } from '../utils'
15+ import {
16+ readVarInt ,
17+ writeVarInt ,
18+ resolveHostname ,
19+ protocolMap ,
20+ parseChat
21+ } from '../utils'
1522import packetIds from '../packets/ids'
1623
1724const { ConnectionModule } = NativeModules
@@ -50,7 +57,7 @@ export class NativeServerConnection
5057 id : string
5158 options : ConnectionOptions
5259 disconnectTimer ?: NodeJS . Timeout
53- disconnectReason ?: string
60+ disconnectReason ?: MinecraftChat
5461 msgSalt ?: Buffer
5562
5663 constructor ( id : string , options : ConnectionOptions ) {
@@ -118,10 +125,10 @@ export class NativeServerConnection
118125 ( packet . id === packetIds . CLIENTBOUND_DISCONNECT_PLAY ( version ) &&
119126 this . state === ConnectionState . PLAY )
120127 ) {
121- const [ chatLength , chatVarIntLength ] = readVarInt ( packet . data )
122- this . disconnectReason = packet . data
123- . slice ( chatVarIntLength , chatVarIntLength + chatLength )
124- . toString ( 'utf8' )
128+ this . disconnectReason = parseChat (
129+ packet . data , // The Disconnect (login) packet always returns JSON.
130+ this . state === ConnectionState . LOGIN ? undefined : version
131+ ) [ 0 ]
125132 } else if ( packet . id === 0x04 && this . state === ConnectionState . LOGIN ) {
126133 /* Login Plugin Request */
127134 const [ msgId ] = readVarInt ( packet . data )
0 commit comments