parent
14af5fe04f
commit
957c83995a
7 changed files with 26 additions and 11 deletions
2
index.d.ts
vendored
2
index.d.ts
vendored
|
|
@ -1,7 +1,7 @@
|
|||
import EventEmitter from "events"
|
||||
|
||||
declare module "bedrock-protocol" {
|
||||
type Version = '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.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 }
|
||||
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ class Client extends Connection {
|
|||
_connect = async (sessionData) => {
|
||||
debug('[client] connecting to', this.options.host, this.options.port, sessionData, this.connection)
|
||||
this.connection.onConnected = () => this.sendLogin()
|
||||
this.connection.onCloseConnection = () => this.close()
|
||||
this.connection.onCloseConnection = (reason) => this.close()
|
||||
this.connection.onEncapsulated = this.onEncapsulated
|
||||
this.connection.connect()
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ const mcData = require('minecraft-data')
|
|||
// Minimum supported version (< will be kicked)
|
||||
const MIN_VERSION = '1.16.201'
|
||||
// Currently supported verson. Note, clients with newer versions can still connect as long as data is in minecraft-data
|
||||
const CURRENT_VERSION = '1.18.0'
|
||||
const CURRENT_VERSION = '1.18.11'
|
||||
|
||||
const Versions = Object.fromEntries(mcData.versions.bedrock.filter(e => e.releaseType === 'release').map(e => [e.minecraftVersion, e.version]).reverse())
|
||||
|
||||
|
|
|
|||
19
src/rak.js
19
src/rak.js
|
|
@ -86,6 +86,7 @@ class RakNativeServer extends EventEmitter {
|
|||
protocolVersion: 10,
|
||||
message: server.getAdvertisement().toBuffer()
|
||||
})
|
||||
this.onClose = () => {}
|
||||
|
||||
this.updateAdvertisement = () => {
|
||||
this.raknet.setOfflineMessage(server.getAdvertisement().toBuffer())
|
||||
|
|
@ -106,6 +107,8 @@ class RakNativeServer extends EventEmitter {
|
|||
this.raknet.on('encapsulated', ({ buffer, address }) => {
|
||||
this.onEncapsulated(buffer, address)
|
||||
})
|
||||
|
||||
this.raknet.on('close', (reason) => this.onClose(reason))
|
||||
}
|
||||
|
||||
listen () {
|
||||
|
|
@ -122,6 +125,7 @@ class RakJsClient extends EventEmitter {
|
|||
super()
|
||||
this.options = options
|
||||
this.onConnected = () => { }
|
||||
this.onCloseConnection = () => { }
|
||||
this.onEncapsulated = () => { }
|
||||
if (options.useWorkers) {
|
||||
this.connect = this.workerConnect
|
||||
|
|
@ -151,6 +155,10 @@ class RakJsClient extends EventEmitter {
|
|||
}
|
||||
case 'pong':
|
||||
this.pongCb?.(evt.args)
|
||||
break
|
||||
case 'disconnect':
|
||||
this.onCloseConnection()
|
||||
break
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -164,7 +172,8 @@ class RakJsClient extends EventEmitter {
|
|||
})
|
||||
|
||||
this.raknet.on('connected', this.onConnected)
|
||||
this.raknet.on('encapsulated', (encapsulated, addr) => this.onEncapsulated(encapsulated.buffer, addr.hash))
|
||||
this.raknet.on('encapsulated', (encapsulated, addr) => this.onEncapsulated(encapsulated, addr.hash))
|
||||
this.raknet.on('disconnect', (reason) => this.onCloseConnection(reason))
|
||||
}
|
||||
|
||||
workerSendReliable (buffer, immediate) {
|
||||
|
|
@ -175,8 +184,8 @@ class RakJsClient extends EventEmitter {
|
|||
const sendPacket = new EncapsulatedPacket()
|
||||
sendPacket.reliability = Reliability.ReliableOrdered
|
||||
sendPacket.buffer = buffer
|
||||
this.connection.addEncapsulatedToQueue(sendPacket)
|
||||
if (immediate) this.connection.sendQueue()
|
||||
this.raknet.connection.addEncapsulatedToQueue(sendPacket)
|
||||
if (immediate) this.raknet.connection.sendQueue()
|
||||
}
|
||||
|
||||
async ping (timeout = 1000) {
|
||||
|
|
@ -205,8 +214,9 @@ class RakJsServer extends EventEmitter {
|
|||
this.onOpenConnection = () => { }
|
||||
this.onCloseConnection = () => { }
|
||||
this.onEncapsulated = (packet, address) => server.onEncapsulated(packet.buffer, address)
|
||||
this.onClose = () => {}
|
||||
this.updateAdvertisement = () => {
|
||||
// TODO
|
||||
this.raknet.setPongAdvertisement(server.getAdvertisement())
|
||||
}
|
||||
if (options.useWorkers) {
|
||||
throw Error('nyi')
|
||||
|
|
@ -229,6 +239,7 @@ class RakJsServer extends EventEmitter {
|
|||
})
|
||||
this.raknet.on('closeConnection', this.onCloseConnection)
|
||||
this.raknet.on('encapsulated', this.onEncapsulated)
|
||||
this.raknet.on('close', this.onClose)
|
||||
}
|
||||
|
||||
close () {
|
||||
|
|
|
|||
|
|
@ -34,9 +34,12 @@ function main () {
|
|||
})
|
||||
|
||||
raknet.on('encapsulated', (...args) => {
|
||||
setTimeout(() => {
|
||||
parentPort.postMessage({ type: 'encapsulated', args })
|
||||
}, 100)
|
||||
parentPort.postMessage({ type: 'encapsulated', args })
|
||||
})
|
||||
|
||||
raknet.on('disconnect', (reason) => {
|
||||
debug('[worker] disconnected!')
|
||||
parentPort.postMessage({ type: 'disconnect', reason })
|
||||
})
|
||||
|
||||
raknet.on('raw', (buffer, inetAddr) => {
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ class Server extends EventEmitter {
|
|||
this.raknet.onOpenConnection = this.onOpenConnection
|
||||
this.raknet.onCloseConnection = this.onCloseConnection
|
||||
this.raknet.onEncapsulated = this.onEncapsulated
|
||||
this.raknet.onClose = (reason) => this.close(reason || 'Raknet closed')
|
||||
|
||||
this.serverTimer = setInterval(() => {
|
||||
this.raknet.updateAdvertisement()
|
||||
|
|
|
|||
|
|
@ -207,5 +207,5 @@ async function timedTest (version, timeout = 1000 * 220) {
|
|||
console.info('✔ ok')
|
||||
}
|
||||
|
||||
// if (!module.parent) timedTest('1.17.40')
|
||||
// if (!module.parent) timedTest('1.18.11')
|
||||
module.exports = { startTest, timedTest, requestChunks }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue