Skip to content

Commit

Permalink
Update some examples, cleanup (#136)
Browse files Browse the repository at this point in the history
* Update some examples, cleanup

* lint
  • Loading branch information
extremeheat authored Sep 18, 2021
1 parent 2056b7e commit 1f7e94e
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 38 deletions.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions examples/clientTest.js → examples/client/clientInternal.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
File renamed without changes.
File renamed without changes.
18 changes: 11 additions & 7 deletions examples/serverTest.js → examples/server/server.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 1 addition & 5 deletions examples/serverChunks.js → examples/server/serverChunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -35,7 +32,6 @@ async function loadWorld (version) {
blobs: [],
payload: cbuf
})
// console.log('Ht',cc.sectionsLen,cc.sections)
}
}

Expand Down
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
18 changes: 0 additions & 18 deletions src/client/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
// }
2 changes: 0 additions & 2 deletions src/handshake/loginVerify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tools/startVanillaServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

0 comments on commit 1f7e94e

Please sign in to comment.