@@ -32,7 +32,7 @@ import { watchOptionsAfterViewerInit, watchOptionsAfterWorldViewInit } from './w
32
32
import downloadAndOpenFile from './downloadAndOpenFile'
33
33
34
34
import fs from 'fs'
35
- import net from 'net'
35
+ import net , { Socket } from 'net'
36
36
import mineflayer from 'mineflayer'
37
37
38
38
import debug from 'debug'
@@ -300,6 +300,7 @@ export async function connect (connectOptions: ConnectOptions) {
300
300
let updateDataAfterJoin = ( ) => { }
301
301
let localServer
302
302
let localReplaySession : ReturnType < typeof startLocalReplayServer > | undefined
303
+ let lastKnownKickReason = undefined as string | undefined
303
304
try {
304
305
const serverOptions = defaultsDeep ( { } , connectOptions . serverOverrides ?? { } , options . localServerOptions , defaultServerOptions )
305
306
Object . assign ( serverOptions , connectOptions . serverOverridesFlat ?? { } )
@@ -566,6 +567,16 @@ export async function connect (connectOptions: ConnectOptions) {
566
567
bot . _client . emit ( 'connect' )
567
568
} else {
568
569
const setupConnectHandlers = ( ) => {
570
+ Socket . prototype [ 'handleStringMessage' ] = function ( message : string ) {
571
+ if ( message . startsWith ( 'proxy-message' ) || message . startsWith ( 'proxy-command:' ) ) { // for future
572
+ return false
573
+ }
574
+ if ( message . startsWith ( 'proxy-shutdown:' ) ) {
575
+ lastKnownKickReason = message . slice ( 'proxy-shutdown:' . length )
576
+ return false
577
+ }
578
+ return true
579
+ }
569
580
bot . _client . socket . on ( 'connect' , ( ) => {
570
581
console . log ( 'Proxy WebSocket connection established' )
571
582
//@ts -expect-error
@@ -643,9 +654,9 @@ export async function connect (connectOptions: ConnectOptions) {
643
654
if ( ended ) return
644
655
console . log ( 'disconnected for' , endReason )
645
656
if ( endReason === 'socketClosed' ) {
646
- endReason = 'Connection with server lost'
657
+ endReason = lastKnownKickReason ?? 'Connection with server lost'
647
658
}
648
- setLoadingScreenStatus ( `You have been disconnected from the server. End reason: ${ endReason } ` , true )
659
+ setLoadingScreenStatus ( `You have been disconnected from the server. End reason:\n ${ endReason } ` , true )
649
660
appStatusState . showReconnect = true
650
661
onPossibleErrorDisconnect ( )
651
662
destroyAll ( )
0 commit comments