Skip to content

Commit

Permalink
always show errors on tcp disconnect!
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy committed Sep 27, 2023
1 parent 47b895d commit e4265e2
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 34 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
"url": "^0.11.1",
"valtio": "^1.11.1",
"minecraft-assets": "^1.9.1",
"workbox-build": "^7.0.0"
"workbox-build": "^7.0.0",
"debug": "^4.3.4"
},
"devDependencies": {
"@types/three": "0.128.0",
Expand Down
67 changes: 36 additions & 31 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 21 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ import { contro } from './controls'
import { genTexturePackTextures, watchTexturepackInViewer } from './texturePack'
import { connectToPeer } from './localServerMultiplayer'
import CustomChannelClient from './customClient'
import debug from 'debug'

window.debug = debug
//@ts-ignore
window.THREE = THREE

Expand All @@ -98,6 +100,7 @@ if ('serviceWorker' in navigator && !isCypress() && process.env.NODE_ENV !== 'de

// ACTUAL CODE

// todo stats-gl
let stats
let stats2
stats = new Stats()
Expand Down Expand Up @@ -333,7 +336,9 @@ async function connect(connectOptions: {
bot.removeAllListeners()
bot._client.removeAllListeners()
bot._client = undefined
bot = undefined
// for debugging
window._botDisconnected = undefined
window.bot = bot = undefined
}
removeAllListeners()
for (const timeout of timeouts) {
Expand Down Expand Up @@ -465,8 +470,10 @@ async function connect(connectOptions: {
closeTimeout: 240 * 1000,
async versionSelectedHook(client) {
await downloadMcData(client.version)
setLoadingScreenStatus('Connecting to server')
}
})
window.bot = bot
if (singeplayer || p2pMultiplayer) {
// p2pMultiplayer still uses the same flying-squid server
const _supportFeature = bot.supportFeature
Expand All @@ -479,6 +486,19 @@ async function connect(connectOptions: {

bot.emit('inject_allowed')
bot._client.emit('connect')
} else {
bot._client.socket.on('connect', () => {
console.log('TCP connection established')
//@ts-ignore
bot._client.socket._ws.addEventListener('close', () => {
console.log('TCP connection closed')
setTimeout(() => {
if (bot) {
bot.emit('end', 'TCP connection closed with unknown reason')
}
})
})
})
}
} catch (err) {
handleError(err)
Expand Down Expand Up @@ -560,7 +580,6 @@ async function connect(connectOptions: {
const debugMenu = hud.shadowRoot.querySelector('#debug-overlay')

window.loadedData = mcData
window.bot = bot
window.Vec3 = Vec3
window.pathfinder = pathfinder
window.debugMenu = debugMenu
Expand Down

0 comments on commit e4265e2

Please sign in to comment.