Update some examples, cleanup (#136)
* Update some examples, cleanup * lint
This commit is contained in:
parent
2056b7e001
commit
1f7e94e5db
11 changed files with 16 additions and 38 deletions
|
|
@ -1,3 +1,6 @@
|
|||
/**
|
||||
* Do not use this example unless you need to change the login procedure, instead see `client.js`.
|
||||
*/
|
||||
process.env.DEBUG = 'minecraft-protocol raknet'
|
||||
const { Client } = require('bedrock-protocol')
|
||||
const { ChunkColumn, Version } = require('bedrock-provider')
|
||||
|
|
@ -1,27 +1,31 @@
|
|||
/**
|
||||
* This example spawns a client. For a basic server that disconnects users, see "basicServer.js".
|
||||
*
|
||||
* bedrock-protocol server example; to run this example you need to clone this repo from git.
|
||||
* first need to dump some packets from the vanilla server as there is alot of boilerplate
|
||||
* to send to clients.
|
||||
* to send to clients. The `serverChunks.js` contains the chunk loading code.
|
||||
*
|
||||
* In your server implementation, you need to implement each of the following packets to
|
||||
* get a client to spawn like vanilla. You can look at the dumped packets in `data/1.16.10/sample`
|
||||
*
|
||||
* First, dump packets for version 1.16.210 by running `npm run dumpPackets`.
|
||||
* Then you can run `node server.js <version>` to start this script.
|
||||
*/
|
||||
process.env.DEBUG = 'minecraft-protocol' // packet logging
|
||||
// const fs = require('fs')
|
||||
const { Server } = require('../src/server')
|
||||
const { hasDumps } = require('../tools/genPacketDumps')
|
||||
const DataProvider = require('../data/provider')
|
||||
const { waitFor } = require('../src/datatypes/util')
|
||||
const { Server } = require('bedrock-protocol')
|
||||
|
||||
const { hasDumps } = require('../../tools/genPacketDumps')
|
||||
const DataProvider = require('../../data/provider')
|
||||
const { waitFor } = require('../../src/datatypes/util')
|
||||
const { loadWorld } = require('./serverChunks')
|
||||
|
||||
async function startServer (version = '1.16.220', ok) {
|
||||
async function startServer (version = '1.17.10', ok) {
|
||||
if (!hasDumps(version)) {
|
||||
throw Error('You need to dump some packets first. Run tools/genPacketDumps.js')
|
||||
}
|
||||
|
||||
const Item = require('../types/Item')(version)
|
||||
const Item = require('../../types/Item')(version)
|
||||
const port = 19132
|
||||
const server = new Server({ host: '0.0.0.0', port, version })
|
||||
let loop
|
||||
|
|
@ -4,7 +4,7 @@ const { LevelDB } = require('leveldb-zlib')
|
|||
const { join } = require('path')
|
||||
|
||||
async function loadWorld (version) {
|
||||
const path = join(__dirname, `../tools/bds-${version}/worlds/Bedrock level/db`)
|
||||
const path = join(__dirname, `../../tools/bds-${version}/worlds/Bedrock level/db`)
|
||||
console.log('Loading world at path', path) // Load world from testing server
|
||||
const db = new LevelDB(path, { createIfMissing: false })
|
||||
await db.open()
|
||||
|
|
@ -19,11 +19,8 @@ async function loadWorld (version) {
|
|||
|
||||
for (let cx = cxStart; cx < cxEnd; cx++) {
|
||||
for (let cz = czStart; cz < czEnd; cz++) {
|
||||
// console.log('reading chunk at ', cx, cz)
|
||||
|
||||
const cc = await wp.load(cx, cz, true)
|
||||
if (!cc) {
|
||||
// console.log('no chunk')
|
||||
continue
|
||||
}
|
||||
const cbuf = await cc.networkEncodeNoCache()
|
||||
|
|
@ -35,7 +32,6 @@ async function loadWorld (version) {
|
|||
blobs: [],
|
||||
payload: cbuf
|
||||
})
|
||||
// console.log('Ht',cc.sectionsLen,cc.sections)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -21,18 +21,13 @@
|
|||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@azure/msal-node": "^1.1.0",
|
||||
"@xboxreplay/xboxlive-auth": "^3.3.3",
|
||||
"debug": "^4.3.1",
|
||||
"jose-node-cjs-runtime": "^3.12.1",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"jsp-raknet": "^2.1.3",
|
||||
"minecraft-folder-path": "^1.2.0",
|
||||
"node-fetch": "^2.6.1",
|
||||
"prismarine-auth": "^1.1.0",
|
||||
"prismarine-nbt": "^1.5.0",
|
||||
"protodef": "^1.14.0",
|
||||
"smart-buffer": "^4.1.0",
|
||||
"uuid-1345": "^1.0.2"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
|
|
|
|||
|
|
@ -69,21 +69,3 @@ module.exports = {
|
|||
createOfflineSession,
|
||||
authenticate
|
||||
}
|
||||
|
||||
// async function msaTest () {
|
||||
// // MsAuthFlow.resetTokenCaches()
|
||||
|
||||
// await authenticateDeviceCode({
|
||||
// connect(...args) {
|
||||
// console.log('Connecting', args)
|
||||
// },
|
||||
// emit(...e) {
|
||||
// console.log('Event', e)
|
||||
// }
|
||||
// }, {})
|
||||
// }
|
||||
|
||||
// // debug with node microsoftAuth.js
|
||||
// if (!module.parent) {
|
||||
// msaTest()
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ module.exports = (client, server, options) => {
|
|||
|
||||
for (const token of chain) {
|
||||
const decoded = JWT.verify(token, pubKey, { algorithms: ['ES384'] })
|
||||
// console.log('Decoded', decoded)
|
||||
|
||||
// Check if signed by Mojang key
|
||||
const x5u = getX5U(token)
|
||||
|
|
@ -37,7 +36,6 @@ module.exports = (client, server, options) => {
|
|||
finalKey = decoded.identityPublicKey || finalKey // non pem
|
||||
data = { ...data, ...decoded }
|
||||
}
|
||||
// console.log('Result', data)
|
||||
|
||||
if (!didVerify && !options.offline) {
|
||||
client.disconnect('disconnectionScreen.notAuthenticated')
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ async function startServerAndWait (version, withTimeout, options) {
|
|||
|
||||
if (!module.parent) {
|
||||
// if (process.argv.length < 3) throw Error('Missing version argument')
|
||||
startServer(process.argv[2] || '1.16.201', null, process.argv[3] ? { 'server-port': process.argv[3], 'online-mode': !!process.argv[4] } : undefined)
|
||||
startServer(process.argv[2] || '1.17.10', null, process.argv[3] ? { 'server-port': process.argv[3], 'online-mode': !!process.argv[4] } : undefined)
|
||||
}
|
||||
|
||||
module.exports = { fetchLatestStable, startServer, startServerAndWait }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue