Skip to content

Commit

Permalink
Ignore unconnected packets, remove babel (#185)
Browse files Browse the repository at this point in the history
* Ignore unconnected packets, remove babel

* re-enable proxy test on ubuntu runner
  • Loading branch information
extremeheat authored Feb 21, 2022
1 parent 330c819 commit 817fd91
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 49 deletions.
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ node_modules/
npm-debug.log
package-lock.json
__*
src/**/*.json
# Runtime generated data
data/
tools/bds*
tools/*/*
*.txt
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
node_modules/
npm-debug.log
__*
src/**/*.json
# Runtime generated data
data/
tools/bds*
Expand Down
3 changes: 0 additions & 3 deletions babel.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion examples/viewer/client/ProxyProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ProxyProvider extends BotProvider {
this.movements.pushCameraControl(params, 1)

// Log Movement deltas
{
{ // eslint-disable-line
this.lastMovePacket = params
if (this.firstPlayerMovePacket) {
const id = diff(this.firstPlayerMovePacket.input_data, params.input_data)
Expand Down
7 changes: 3 additions & 4 deletions examples/viewer/client/movements.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ class MovementManager {
}, PHYSICS_INTERVAL_MS)
}

get sprinting() {
get sprinting () {
return this.player.sprinting
}

set sprinting(val) {
set sprinting (val) {
this.player.events.startSprint = val
this.player.events.stopSprint = !val
if (val && !this.player.sprinting) {
Expand Down Expand Up @@ -219,7 +219,7 @@ class MovementManager {
const isAxis = AXES.includes(control)
let hasOtherAxisKeyDown = false
for (const c of AXES) {
if (this.controls[c] && c != control) {
if (this.controls[c] && c !== control) {
hasOtherAxisKeyDown = true
}
}
Expand Down Expand Up @@ -278,7 +278,6 @@ class MovementManager {
globalThis.debugYaw = [yaw, yawRad]
}


// Called when a proxy player sends a PlayerInputPacket. We need to apply these inputs tick-by-tick
// as these packets are sent by the client every tick.
pushCameraControl (state, id = 1) {
Expand Down
2 changes: 1 addition & 1 deletion examples/viewer/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path')
const { app, BrowserWindow, globalShortcut } = require('electron')

function createMainWindow() {
function createMainWindow () {
const window = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import EventEmitter from "events"

declare module "bedrock-protocol" {
type Version = '1.18.11' | '1.18.10' | '1.18.2' | '1.18.1' | '1.18.0' | '1.17.41' | '1.17.40' | '1.17.34' | '1.17.30' | '1.17.11' | '1.17.10' | '1.17.0' | '1.16.220' | '1.16.210' | '1.16.201'
type Version = '1.18.12' | '1.18.11' | '1.18.10' | '1.18.2' | '1.18.1' | '1.18.0' | '1.17.41' | '1.17.40' | '1.17.34' | '1.17.30' | '1.17.11' | '1.17.10' | '1.17.0' | '1.16.220' | '1.16.210' | '1.16.201'

enum title { MinecraftNintendoSwitch, MinecraftJava }

Expand Down
7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,12 @@
"raknet-native": "^1.0.3"
},
"devDependencies": {
"@babel/eslint-parser": "^7.13.10",
"babel-eslint": "^10.1.0",
"bedrock-protocol": "file:.",
"bedrock-provider": "^2.0.0",
"leveldb-zlib": "^1.0.1",
"mocha": "^9.1.2",
"protodef-yaml": "^1.1.0",
"standard": "^16.0.3"
},
"standard": {
"parser": "babel-eslint"
"standard": "^17.0.0-2"
},
"repository": {
"type": "git",
Expand Down
11 changes: 3 additions & 8 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ class Client extends Connection {
try {
return await this.connection.ping(this.options.connectTimeout)
} catch (e) {
// TODO: workaround bug in standardjs, waiting for https://github.com/standard/eslint-config-standard/pull/193
const t = `Unable to connect to [${this.options.host}]/${this.options.port}. Is the server running?`
this.conLog?.(t)
this.conLog?.(`Unable to connect to [${this.options.host}]/${this.options.port}. Is the server running?`)
throw e
}
}
Expand Down Expand Up @@ -130,9 +128,7 @@ class Client extends Connection {
}

onDisconnectRequest (packet) {
// TODO: workaround bug in standardjs, waiting for https://github.com/standard/eslint-config-standard/pull/193
const t = `Server requested ${packet.hide_disconnect_reason ? 'silent disconnect' : 'disconnect'}: ${packet.message}`
this.conLog?.(t)
this.conLog?.(`Server requested ${packet.hide_disconnect_reason ? 'silent disconnect' : 'disconnect'}: ${packet.message}`)
this.emit('kick', packet)
this.close()
}
Expand Down Expand Up @@ -221,8 +217,7 @@ class Client extends Connection {
break
default:
if (this.status !== ClientStatus.Initializing && this.status !== ClientStatus.Initialized) {
// TODO: standardjs bug happens here with ?.(`something ${des.data.name}`)
if (this.inLog) this.inLog(`Can't accept ${des.data.name}, client not yet authenticated : ${this.status}`)
this.inLog?.(`Can't accept ${des.data.name}, client not yet authenticated : ${this.status}`)
return
}
}
Expand Down
13 changes: 9 additions & 4 deletions src/relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ class RelayPlayer extends Player {

if (!des.canceled) {
if (name === 'start_game') {
this.sentStartGame = true
setTimeout(() => {
this.sentStartGame = true
}, 500)
} else if (name === 'level_chunk' && !this.sentStartGame) {
this.chunkSendCache.push(params)
return
Expand Down Expand Up @@ -104,7 +106,8 @@ class RelayPlayer extends Player {
if (this.startRelaying) {
// Upstream is still connecting/handshaking
if (!this.upstream) {
this.downInLog('Got downstream connected packet but upstream is not connected yet, added to q', this.upQ.length)
const des = this.server.deserializer.parsePacketBuffer(packet)
this.downInLog('Got downstream connected packet but upstream is not connected yet, added to q', des)
this.upQ.push(packet) // Put into a queue
return
}
Expand Down Expand Up @@ -178,8 +181,10 @@ class Relay extends Server {
autoInitPlayer: false
})
// Set the login payload unless `noLoginForward` option
if (!client.noLoginForward) client.skinData = ds.skinData
client.connect()
if (!client.noLoginForward) client.options.skinData = ds.skinData
client.ping().then(pongData => {
client.connect()
})
this.conLog('Connecting to', this.options.destination.host, this.options.destination.port)
client.outLog = ds.upOutLog
client.inLog = ds.upInLog
Expand Down
3 changes: 2 additions & 1 deletion src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class Server extends EventEmitter {
onEncapsulated = (buffer, address) => {
const client = this.clients[address]
if (!client) {
this.emit('error', new Error(`packet from unknown inet addr: ${address}`))
// Ignore packets from clients that are not connected.
debug(`ignoring packet from unknown inet addr: ${address}`)
return
}
client.handle(buffer)
Expand Down
9 changes: 5 additions & 4 deletions src/transforms/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ class Parser extends FullPacketParser {
const oldBuffer = deserialized.fullBuffer
const newBuffer = serializer.createPacketBuffer({ name, params })
if (!newBuffer.equals(oldBuffer)) {
console.warn('New', newBuffer.toString('hex'))
console.warn('Old', oldBuffer.toString('hex'))
console.log('Failed to re-encode', name, params)
process.exit(1)
const fs = require('fs')
fs.writeFileSync('new.bin', newBuffer)
fs.writeFileSync('old.bin', oldBuffer)
fs.writeFileSync('failed.json', JSON.stringify(params, (k, v) => typeof v === 'bigint' ? v.toString() : v, 2))
console.warn('Failed to re-encode', name)
}
}
}
Expand Down
19 changes: 7 additions & 12 deletions test/internal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,12 @@ describe('internal client/server test', function () {
})
}

if (process.env.CI && process.platform === 'linux') {
// Don't run the test, see :
// https://github.com/PrismarineJS/bedrock-protocol/issues/124
} else {
for (const version in Versions) {
it('proxies ' + version, async () => {
console.debug(version)
await proxyTest(version)
await sleep(5000)
console.debug('Done', version)
})
}
for (const version in Versions) {
it('proxies ' + version, async () => {
console.debug(version)
await proxyTest(version)
await sleep(5000)
console.debug('Done', version)
})
}
})

0 comments on commit 817fd91

Please sign in to comment.