diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..61743e4 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +examples/viewer \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..cd19a23 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +data/*/*.json linguist-generated \ No newline at end of file diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index a71776b..0000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1,3 +0,0 @@ -github: PrismarineJS -open_collective: prismarinejs -custom: https://rysolv.com/repos/detail/74691b23-938d-4b2f-b65a-5c47bf5b3f0f \ No newline at end of file diff --git a/.github/helper-bot/index.js b/.github/helper-bot/index.js deleted file mode 100644 index 8dffc6c..0000000 --- a/.github/helper-bot/index.js +++ /dev/null @@ -1,139 +0,0 @@ -// Automatic version update checker for Minecraft bedrock edition. -const fs = require('fs') -const cp = require('child_process') -const helper = require('gh-helpers')() -const latestVesionEndpoint = 'https://itunes.apple.com/lookup?bundleId=com.mojang.minecraftpe&time=' + Date.now() -const changelogURL = 'https://feedback.minecraft.net/hc/en-us/sections/360001186971-Release-Changelogs' - -// Relevant infomation for us is: -// "version": "1.17.10", -// "currentVersionReleaseDate": "2021-07-13T15:35:49Z", -// "releaseNotes": "What's new in 1.17.10:\nVarious bug fixes", - -function buildFirstIssue (title, result, externalPatches) { - let commitData = '' - let protocolVersion = '?' - const date = new Date(result.currentVersionReleaseDate).toUTCString() - - for (const name in externalPatches) { - const [patches, diff] = externalPatches[name] - commitData += '### ' + name + '\n' - for (const [name, url] of patches) { - commitData += `${name}\n` - } - if (diff) commitData += `\n**[See the diff between *${result.currentVersionReleaseDate}* and now](${diff})**\n` - else commitData += '\n(No changes so far)\n' - } - try { protocolVersion = getProtocolVersion() } catch (e) { console.log(e) } - - return { - title, - body: ` -A new Minecraft Bedrock version is available (as of ${date}), version **${result.version}** - -## Official Changelog -* ${result.releaseNotes} *(via App Store)* -* ${changelogURL} - -## 3rd party protocol patches -${commitData} - -## Protocol Details -(I will close this issue automatically if "${result.version}" is added to index.d.ts on "master" and there are no X's below) - - - - -
Name${result.version}
Protocol ID${protocolVersion}
- ------ - -🤖 I am a bot, I check for updates every 2 hours without a trigger. You can close this issue to prevent any further updates. - ` - } -} - -function getCommitsInRepo (repo, containing, since) { - const endpoint = `https://api.github.com/repos/${repo}/commits` - console.log('Getting', endpoint) - cp.execSync(`curl -L ${endpoint} -o commits.json`, { stdio: 'inherit', shell: true }) - const commits = JSON.parse(fs.readFileSync('./commits.json', 'utf-8')) - const relevant = [] - for (const commit of commits) { - if (commit.commit.message.includes(containing)) { - console.log('commit url', commit.html_url) - relevant.push([commit.commit.message, commit.html_url]) - } - } - if (since) { - cp.execSync(`curl -L ${endpoint}?since=${since} -o commits.json`, { stdio: 'inherit', shell: true }) - const commits = JSON.parse(fs.readFileSync('./commits.json', 'utf-8')) - if (commits.length) { - const head = commits[0].sha - const tail = commits[commits.length - 1].sha - return [relevant, `https://github.com/${repo}/compare/${tail}..${head}`] - } - } - return [relevant] -} - -function getProtocolVersion () { - if (!fs.existsSync('./ProtocolInfo.php')) cp.execSync('curl -LO https://raw.githubusercontent.com/pmmp/PocketMine-MP/stable/src/pocketmine/network/mcpe/protocol/ProtocolInfo.php', { stdio: 'inherit', shell: true }) - const currentApi = fs.readFileSync('./ProtocolInfo.php', 'utf-8') - const [, latestProtocolVersion] = currentApi.match(/public const CURRENT_PROTOCOL = (\d+);/) - return latestProtocolVersion -} - -async function fetchLatest () { - if (!fs.existsSync('./results.json')) cp.execSync(`curl -L "${latestVesionEndpoint}" -o results.json`, { stdio: 'inherit', shell: true }) - const json = require('./results.json') - const result = json.results[0] - // console.log(json) - - if (!fs.existsSync('./index.d.ts')) cp.execSync('curl -LO https://raw.githubusercontent.com/PrismarineJS/bedrock-protocol/master/index.d.ts', { stdio: 'inherit', shell: true }) - const currentApi = fs.readFileSync('./index.d.ts', 'utf-8') - const supportedVersions = currentApi.match(/type Version = ([^\n]+)/)[1].replace(/\||'/g, ' ').split(' ').map(k => k.trim()).filter(k => k.length) - console.log(supportedVersions) - - let { version, currentVersionReleaseDate, releaseNotes } = result - console.log(version, currentVersionReleaseDate, releaseNotes) - - const title = `Support Minecraft ${result.version}` - const issueStatus = await helper.findIssue({ titleIncludes: title }) || {} - - if (supportedVersions.includes(version)) { - if (issueStatus.isOpen) { - helper.close(issueStatus.id, `Closing as ${version} is now supported`) - } - console.log('Latest version is supported.') - return - } - - - if (issueStatus.isClosed) { - // We already made an issue, but someone else already closed it, don't do anything else - console.log('I already made an issue, but it was closed') - return - } - - version = version.replace('.0', '') - const issuePayload = buildFirstIssue(title, result, { - PocketMine: getCommitsInRepo('pmmp/PocketMine-MP', version, currentVersionReleaseDate), - gophertunnel: getCommitsInRepo('Sandertv/gophertunnel', version, currentVersionReleaseDate), - CloudburstMC: getCommitsInRepo('CloudburstMC/Protocol', version, currentVersionReleaseDate) - }) - - if (issueStatus.isOpen) { - helper.updateIssue(issueStatus.id, issuePayload) - } else { - helper.createIssue(issuePayload) - } - - fs.writeFileSync('./issue.md', issuePayload.body) - console.log('OK, wrote to ./issue.md', issuePayload) -} - -fetchLatest() diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4176a31..7803afb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,32 +5,21 @@ on: branches: [ '*', '!gh-pages' ] pull_request: branches: [ '*', '!gh-pages' ] - workflow_dispatch: - inputs: - via: - description: 'trigger origin' - required: true jobs: build: + runs-on: ubuntu-latest + timeout-minutes: 10 + strategy: - fail-fast: false matrix: - os: [ubuntu-latest, windows-latest] - node-version: [22.x] - runs-on: ${{ matrix.os }} - timeout-minutes: 14 + node-version: [14.x] + steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - # Old versions of bedrock use old libssl that Ubuntu no longer ships with; need manual install - - name: (Linux) Install libssl 1.1 - if: runner.os == 'Linux' - run: | - wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb - sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb - run: npm install - run: npm test diff --git a/.github/workflows/commands.yml b/.github/workflows/commands.yml deleted file mode 100644 index 111d139..0000000 --- a/.github/workflows/commands.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Repo Commands - -on: - issue_comment: # Handle comment commands - types: [created] - pull_request_target: # Handle renamed PRs - types: [edited] - -jobs: - comment-trigger: - runs-on: ubuntu-latest - steps: - - name: Check out repository - uses: actions/checkout@v3 - - name: Run command handlers - uses: PrismarineJS/prismarine-repo-actions@master - with: - # NOTE: You must specify a Personal Access Token (PAT) with repo access here. While you can use the default GITHUB_TOKEN, actions taken with it will not trigger other actions, so if you have a CI workflow, commits created by this action will not trigger it. - token: ${{ secrets.PAT_PASSWORD }} - # See `Options` section below for more info on these options - install-command: npm install - /fixlint.fix-command: npm run fix diff --git a/.github/workflows/update-helper.yml b/.github/workflows/update-helper.yml deleted file mode 100644 index d9380da..0000000 --- a/.github/workflows/update-helper.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Update Helper -on: - workflow_dispatch: - schedule: - - cron: "0 */2 * * *" - -jobs: - helper: - name: update-checker - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@master - - name: Set up Node.js - uses: actions/setup-node@master - with: - node-version: 22.0.0 - - name: Install Github Actions helper - run: npm i gh-helpers - # The env vars contain the relevant trigger information, so we don't need to pass it - - name: Runs helper - run: cd .github/helper-bot && node index.js - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index c14d132..8bdb3f2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,10 @@ node_modules/ npm-debug.log package-lock.json __* +src/**/*.json # Runtime generated data -data/ -tools/bds* -tools/pmmp* \ No newline at end of file +data/**/sample +data/**/read.js +data/**/write.js +data/**/size.js +tools/bds* \ No newline at end of file diff --git a/.npmignore b/.npmignore index da98b5e..a085593 100644 --- a/.npmignore +++ b/.npmignore @@ -1,10 +1,7 @@ node_modules/ npm-debug.log __* +src/**/*.json # Runtime generated data -data/ -tools/bds* -# Extra data -examples -test -.github +data/**/sample +tools/bds* \ No newline at end of file diff --git a/docs/AUTHORS.md b/AUTHORS.md similarity index 100% rename from docs/AUTHORS.md rename to AUTHORS.md diff --git a/docs/CONTRIBUTING.md b/CONTRIBUTING.md similarity index 67% rename from docs/CONTRIBUTING.md rename to CONTRIBUTING.md index 56d8f52..746f349 100644 --- a/docs/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,31 +1,16 @@ CONTRIBUTING.md -Contributions are always welcome :). If you have any questions, please discuss on the Discord or in a Discussion. +Contributions are always welcome :) ## Updating Good sources for the Minecraft bedrock protocol are [gophertunnel](https://github.com/Sandertv/gophertunnel/tree/master/minecraft/protocol/packet), [ClouburstMC's protocol library](https://github.com/CloudburstMC/Protocol) and [PocketMine](https://github.com/pmmp/PocketMine-MP/tree/stable/src/pocketmine/network/mcpe/protocol). -Protocol updates need to happen in two places: in minecraft-data to update the protocol schema (the actual data structures for the packets) and here in the protocol library side. If no changes to the underlying protocol are made aside from packet structure changes (add, remove, modify packets) then the only change needed in bedrock-protocol is to update the README documentation and some constants in `src/options.js` (update the CURRENT_VERSION). - Steps to update: -* Update the protocol data in minecraft-data : see the instructions [here](https://github.com/PrismarineJS/minecraft-data/blob/master/doc/bedrock.md). - * Find the relevant changes to the protocol for the current version - * Update the [.YML files](https://github.com/PrismarineJS/minecraft-data/tree/master/data/bedrock/latest) in minecraft-data accordingly (see the [Packet serialization](#Packet_serialization) notes at the bottom here for info on syntax) - * Then follow the steps to build the protocol .YML files into JSON - * Do a release of the minecraft-data package -* Add the version to `src/options.js` here -* Run `npm run build` and `npm test` to test that everything is OK - -### Development - -For development purposes, you can easily alter the protocol locally without a remote minecraft-data release : -* Run `npm install` on the root of this repo after git cloning -* Open `node_modules/minecraft-data/minecraft-data/data/bedrock/latest/` and update the .YML files as you need, following the schema at the bottom (make sure to update '!version' if you are changing version) -* Go back to the root of this repo and run `npm run build`. -* Then `npm test` ; the protocol changes should be automatically applied - -For example, [here](https://github.com/PrismarineJS/minecraft-data/pull/467/files) is a PR for the update to 1.17.30 in minecraft-data - [here](https://github.com/PrismarineJS/bedrock-protocol/pull/150/files) is an accompanying change for bedrock-protocol. +* Add the version to src/options.js +* Open [data/latest/proto.yml](https://github.com/PrismarineJS/bedrock-protocol/tree/new/data/latest) and add, remove or modify the updated packets (see the [Packet serialization](#Packet_serialization) notes at the bottom for info on syntax) +* Save and make sure to update the !version field at the top of the file +* Run `npm run build` and `npm test` to test ## Code structure @@ -110,39 +95,37 @@ The above roughly translates to the following JavaScript code to read a packet: ```js function read_position(stream) { const ret = {} - ret.x = stream.readLI32() - ret.z = stream.readLU32() - ret.y = stream.readLF32() + ret.x = stream.readSignedInt32LE() + ret.z = stream.readUnsignedInt32LE() + ret.y = stream.readFloat32LE() return ret } function read_player_position(stream) { const ret = {} ret.on_ground = Boolean(stream.readU8()) - ret.position = read_position(stream) + ret.position = read_player_position(stream) let __movement_reason = stream.readU8() let movement_reason = { 0: 'player_jump', 1: 'player_autojump', 2: 'player_sneak', 3: 'player_sprint', 4: 'player_fall' }[__movement_reason] switch (movement_reason) { case 'player_jump': case 'player_autojump': - ret.original_position = read_position(stream) - ret.jump_tick = stream.readLI64() + ret.original_position = read_player_position(stream) + ret.jump_tick = stream.readInt64LE(stream) break case 'player_fall': - ret.original_position = read_position(stream) + ret.original_position = read_player_position(stream) break default: break } ret.player_hunger = undefined if (movement_reason == 'player_sprint') ret.player_hunger = stream.readU8() ret.last_positions = [] - let __latest_positions_len = stream.readUnsignedVarInt() - for (let i = 0; i < __latest_positions_len; i++) { + for (let i = 0; i < stream.readUnsignedVarInt(); i++) { ret.last_positions.push(read_player_position(stream)) } ret.keys_down = [] - let __keys_down_len = stream.readZigZagVarInt() - for (let i = 0; i < __keys_down_len; i++) { + for (let i = 0; i < stream.readZigZagVarInt(); i++) { const ret1 = {} ret1.up = Boolean(stream.readU8()) ret1.down = Boolean(stream.readU8()) diff --git a/HISTORY.md b/HISTORY.md index 799d0a9..d6f0347 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,250 +1,10 @@ -## 3.49.0 -* [1.21.111 (#649)](https://github.com/PrismarineJS/bedrock-protocol/commit/b48518a6e79e72101fe7136433cbd6277339fc5c) (thanks @Slauh) -* [Skin Data Changes (#647)](https://github.com/PrismarineJS/bedrock-protocol/commit/407756b93880cdda4fdbff194fc4163ceedf4e82) (thanks @thejfkvis) - -## 3.48.1 -* [Update login client skinData (#635)](https://github.com/PrismarineJS/bedrock-protocol/commit/6b1474d2c6f93b47dee9d4816de59579f82ed5a9) (thanks @TSL534) - -## 3.48.0 -* [1.21.100 (#632)](https://github.com/PrismarineJS/bedrock-protocol/commit/06fb3de3a0023d03201dbcee7e9178c269462766) (thanks @extremeheat) - -## 3.47.0 -* [1.21.93 support (#623)](https://github.com/PrismarineJS/bedrock-protocol/commit/14daa2d95aac90ffcc7b42d625e270020ec2f162) (thanks @CreeperG16) - -## 3.46.0 -* [1.21.90 support (#617)](https://github.com/PrismarineJS/bedrock-protocol/commit/c66cdd3d62d2fa9c581693d8c70d7b41f355b63e) (thanks @CreeperG16) - -## 3.45.0 -* [1.21.80 (#602)](https://github.com/PrismarineJS/bedrock-protocol/commit/e71fd513ddbd432983f221980080b61e11576965) (thanks @extremeheat) - -## 3.44.0 -* [1.21.70 (#594)](https://github.com/PrismarineJS/bedrock-protocol/commit/065f41db8cfc8cbd8106bd9e376c899ec25f3f77) (thanks @CreeperG16) - -## 3.43.1 -* [Fix server not correctly removing clients (#588)](https://github.com/PrismarineJS/bedrock-protocol/commit/47f342ca958ba87a7719783bd5c855cebdd4aa65) (thanks @EntifiedOptics) - -## 3.43.0 -* [1.21.60 support (#570)](https://github.com/PrismarineJS/bedrock-protocol/commit/eeb5e47e35f31cc571a9a8a491f5a89b27e637f1) (thanks @CreeperG16) -* [Fix version feature handling (#572)](https://github.com/PrismarineJS/bedrock-protocol/commit/0ed8e32be85f05926cd97d5f0317ed004ae5eefa) (thanks @ItsMax123) - -## 3.42.3 -* [Fix Server `maxPlayers` option (#565)](https://github.com/PrismarineJS/bedrock-protocol/commit/38dc5a256105a44786d5455570d5a130e64ef561) (thanks @extremeheat) - -## 3.42.2 -* Fix missing type serialization error - -## 3.42.1 -* [Add 1.21.40 login fields (#553)](https://github.com/PrismarineJS/bedrock-protocol/commit/24d3200181c060162b04fb233fef6e0d6d1a93aa) (thanks @extremeheat) -* [Remove protodef varint types (#552)](https://github.com/PrismarineJS/bedrock-protocol/commit/347e303ce422bdb6f6dfd4cba57d7d3937214707) (thanks @extremeheat) - -## 3.42.0 -* [1.21.50 support](https://github.com/PrismarineJS/bedrock-protocol/commit/1c0836bff03d50cb12a3e45763eac6c9f605e00c) (thanks @extremeheat) -* [Dynamic compression & batch header (#544)](https://github.com/PrismarineJS/bedrock-protocol/commit/911e0e890febc00102cd1e5406731e66f7bad0ef) (thanks @LucienHH) - -## 3.41.0 -* [1.21.42 support](https://github.com/PrismarineJS/bedrock-protocol/commit/dd5c4de4f2624c3654af66e9a40a65eb13de0850) (thanks @CreeperG16) - -## 3.40.0 -* [1.21.30 support (#527)](https://github.com/PrismarineJS/bedrock-protocol/commit/fc30c96135ec20dca1257f702152cba61d4a59be) (thanks @pokecosimo) -* [Update tests (#528)](https://github.com/PrismarineJS/bedrock-protocol/commit/cb530c8b45bf505f75e0e39241d88085c5564ae8) (thanks @extremeheat) - -## 3.39.0 -* [1.21.20](https://github.com/PrismarineJS/bedrock-protocol/commit/3be55777fab4949179d3a7108ee29bbd8fada5a7) (thanks @extremeheat) -* [update disconnect packet](https://github.com/PrismarineJS/bedrock-protocol/commit/4c3f62567e0f6ce20b70ea23238fce8606011e95) (thanks @extremeheat) - -## 3.38.0 -* [Support 1.21.2, and add missing versions to type definitions (#510)](https://github.com/PrismarineJS/bedrock-protocol/commit/5d3986924d3f262708d7c7e55a7f410f12c7903c) (thanks @CreeperG16) -* [Fix example in README.md for 1.21 (#506)](https://github.com/PrismarineJS/bedrock-protocol/commit/c4593aa355d6ce9e2ac65cc2102cd9285a6b6449) (thanks @Ant767) -* [Don't send now deprecated tick sync packets on 1.21 and newer (#504)](https://github.com/PrismarineJS/bedrock-protocol/commit/84c5231b92df9f5f1a09b29a05e7abfed62f1c2b) (thanks @w0ahL) - -## 3.37.0 -* [Support 1.21.0](https://github.com/PrismarineJS/bedrock-protocol/commit/5b2d78792c9b4c070d727a9028a6b3a266483e1c) (thanks @CreeperG16) -* [Fix typo in types (#501)](https://github.com/PrismarineJS/bedrock-protocol/commit/16e15d80a5084a19ed2fbabc023789ee38922b3a) (thanks @Kaaaaii) - -## 3.36.0 -* [Support 1.20.80](https://github.com/PrismarineJS/bedrock-protocol/commit/bd32aa8d04555fa2fdc4ecd6abbeb6124e2ae8bb) (thanks @extremeheat) - -## 3.35.0 -* [Support 1.20.71](https://github.com/PrismarineJS/bedrock-protocol/commit/d8e707112acc038b6c9564d9a21b2f977326e47f) (thanks @extremeheat) -* [Note `npm update` command in readme](https://github.com/PrismarineJS/bedrock-protocol/commit/ab93d0d0824bd0ace250fb73f703dc7b60ecd780) (thanks @extremeheat) - -## 3.34.0 -* [1.20.61 support (#480)](https://github.com/PrismarineJS/bedrock-protocol/commit/c278a03f952d23320b80f8c09b6372d41eeff26a) (thanks @extremeheat) -* [Compressor handling update for 1.20.60 (#479)](https://github.com/PrismarineJS/bedrock-protocol/commit/d3161badc65f2eba4b6e7c9e974ca4e3529a7e94) (thanks @extremeheat) -* [Update and rename CONTRIBUTING.md to docs/CONTRIBUTING.md (#475)](https://github.com/PrismarineJS/bedrock-protocol/commit/be6f0cde9f7970a4f9aa376c589c58d8cb4187c3) (thanks @extremeheat) -* [Add flow and deviceType options to relay (#464)](https://github.com/PrismarineJS/bedrock-protocol/commit/842e66266f09e8670a644a618d0ac4157746cd43) (thanks @GameParrot) - -## 3.33.1 -* [Fix zigzag type move in prismarine-nbt (#471)](https://github.com/PrismarineJS/bedrock-protocol/commit/7b74cbf7129646adc80d50304afce6240848cfae) (thanks @extremeheat) - -## 3.33.0 -* [1.20.50 (#466)](https://github.com/PrismarineJS/bedrock-protocol/commit/d53211c6a1fe5f941ce547886ad6ec031ae05d9d) (thanks @extremeheat) -* [Add 1.20.30 and 1.20.40 to index.d.ts (#461)](https://github.com/PrismarineJS/bedrock-protocol/commit/2ecf01d63e64b910b87f303fc4fb2b30f392cb28) (thanks @CreeperG16) - -## 3.32.0 -* [1.20.40 support (#459)](https://github.com/PrismarineJS/bedrock-protocol/commit/63eb673c1f30beb58f97e3b37295129000bf6a10) (thanks @CreeperG16) -* [Update Minecraft wiki link to new domain (#455)](https://github.com/PrismarineJS/bedrock-protocol/commit/689658c4ab1ccb3ef1ae812d78d090212b1acf3f) (thanks @Spongecade) - -## 3.31.0 -* [1.20.30](https://github.com/PrismarineJS/bedrock-protocol/commit/22502b90fdc29f6327239c6c201370c8f839c892) (thanks @extremeheat) -* [Add links field to server resource_packs_info](https://github.com/PrismarineJS/bedrock-protocol/commit/f92db61c89851dfbdbc906f926fc1433162854d0) (thanks @extremeheat) -* [Update API.md (#448)](https://github.com/PrismarineJS/bedrock-protocol/commit/8f3b6c5aecf24d6f8d235afe2a9d911840e6a3f8) (thanks @Laamy) - -## 3.30.1 -* [Update Mojang public key used for logins (#443)](https://github.com/PrismarineJS/bedrock-protocol/commit/f0f1351d40966192e38ee9fe21b7c37754abba04) (thanks @GameParrot) -* [index.d.ts: Fixed a typo (#441)](https://github.com/PrismarineJS/bedrock-protocol/commit/2c00402a9e9a0a283e712bf4f52190a57ea12c3f) (thanks @kotinash) -* [Mark `listen` and `close` as async (#440)](https://github.com/PrismarineJS/bedrock-protocol/commit/50cd489f6e16fa6fe04b1825617d8246bd3935f4) (thanks @MrSterdy) -* [Stop disconnecting when upstream packet deserialization fails (#435)](https://github.com/PrismarineJS/bedrock-protocol/commit/141442057464b3247ace8468863f27a3c334306e) (thanks @MrSterdy) -* [Add 1.20.0 and 1.20.10 to index.d.ts (#431)](https://github.com/PrismarineJS/bedrock-protocol/commit/010d57e78a9130c612e48db7a32f841de83e9c68) (thanks @CreeperG16) - -## 3.30.0 -* 1.20.10 support (thanks @CreeperG16) -* [Fix upstream relay batchingInterval (#425)](https://github.com/PrismarineJS/bedrock-protocol/commit/b2c141c25f3fad9641644742b6cc1a71bc601d61) (thanks @GameParrot) - -## 3.29.1 -* Add missing data to client login user chain (#420) -* Add FAQ entry and replit warning on client ping error (#415) -* Types: Fix Relay authTitle type (#418) - -## 3.29.0 -* 1.20.0 support - -## 3.28.1 -* Fix `followPort` option (@LucienHH) -* Typescript definition fixes (@hvlxh) - -## 3.28.0 -* 1.19.80 support - -## 3.27.1 -* Fix `raknetBackend` option not being applied correctly - -## 3.27.0 -* Corrections to types (@stevarino) -* Expose ServerAdvertisement class (#368) @hvlxh -* Update mc-data links - -## 3.26.0 -* 1.19.70 support (@CreeperG16) -* types: add some type hints (#354) @hvlxh - -## 3.25.0 -* 1.19.63 support (@stevarino) -* Add close packet in server player API doc (#347) @hvlxh - -## 3.24.0 -* 1.19.62 support (@CreeperG16) - -## 3.23.0 -* 1.19.60 support (@CreeperG16) -* added onMsaCode, profilesFolder to ClientOptions (@jarco-dev) - -## 3.22.0 -* 1.19.50 support (@WillQizza) - -## 3.21.0 -* 1.19.40 support (#314) -* types: Fix missing field in ServerAdvertisement (#313) (@minerj101) - -## 3.20.1 -* Fix buffer length calculation in ServerAdvertisement (#292) (thanks @KurtThiemann) -* Handle Relay serialization errors by kicking (#290) - -## 3.20.0 -* Preliminary 1.19.30 support, improve error handling and server pong data (#284) - -## 3.19.0 -* Add option for port redirection, fix Realm handling (#282) -* Add Port Redirect Functionality (#278) @stevarino -* Add Get-AppxPackage command to FAQ.md (#276) @stevarino -* Remove viewer example - -## 3.18.0 -* 1.19.21 support (#266) - -## 3.17.0 -* relay: Add multi-user login support (#258) -* Add fields from 1.19.20 to login chain data (#259) @CleSucre -* Fix nbt encoding size on single null tag NBT (#264) -* test: Add -u flag unzipping vanilla server (#262) - -## 3.16.0 -* 1.19.20 support (#251) -* Add new raknet library option (raknet-node) (#211) @b23r0 - -## 3.15.0 -* 1.19.10 support -* Remove Realm fetch when joining via invite (#228) @LucienHH -* Add Realm support to Relay (#226) @ATXLtheAxolotl - -## 3.14.0 -* 1.19 support -* Better handle ping timeout, update documentation (#218) @stevarino - -## 3.13.0 -* Update API documentation -* Emit generic 'packet' event for server clients (#205) @ATXLtheAxolotl -* Add XUID field for client offline mode client chain (#203) - -## 3.12.0 -* 1.18.30 support - -## 3.11.1 -* Bump minecraft-data version - -## 3.11.0 -* Implement Realm joining (#193) @LucienHH -* Refactor client connection sequence (#189) @extremeheat -* Add profilesFolder to Relay (#192) @CreeperG16 -* Emit error from relay when server can't be pinged (#191) -* Pass relay onMsaCode to client (#190) @Heath123 -* Mark raknet-native as required dependency (#188) -* Ignore unconnected packets, remove babel (#185) - -## 3.10.0 -* Support 1.18.11 (#179) @extremeheat -* Switch to sync zlib with 512k chunks, adjustable compression level (#174) @extremeheat - -## 3.9.0 -* Proxy fixes, logging and doc updates [#169](https://github.com/PrismarineJS/bedrock-protocol/pull/169) - -## 3.8.0 -* 1.18.0 support - -## 3.7.0 -* 1.17.40 support - -## 3.6.0 -* 1.17.30 support -* minecraft-data used for protocol data - -## 3.5.1 -* Fix 1.17.10 npc packet serialization (#119) - -## 3.5.0 -* Add 1.17.10 support [#109](https://github.com/PrismarineJS/bedrock-protocol/pull/109) -* You can switch to the JS implementation of raknet by setting `useNativeRaknet: false` in options. - -## 3.4.0 -* Initial 1.17 support [#99](https://github.com/PrismarineJS/bedrock-protocol/pull/99) -* update connect version based on ping response & fix typings (u9g) [#101](https://github.com/PrismarineJS/bedrock-protocol/pull/101) -* fix: ping types. (JammSpread) [#100](https://github.com/PrismarineJS/bedrock-protocol/pull/100) - -## 3.3.0 -* Protocol updates for 1.16, with some minor breaking changes to protocol fields [#95](https://github.com/PrismarineJS/bedrock-protocol/pull/95) -* Fix npm install issues - -## 3.2.1 -* Add `authTitle` option to Relay proxy [#92](https://github.com/PrismarineJS/bedrock-protocol/pull/92) -* Protocol, type definition fixes - ## 3.2.0 -* Fix empty chunks on proxy spawn [#89](https://github.com/PrismarineJS/bedrock-protocol/pull/89) -* Send skin data to server [#88](https://github.com/PrismarineJS/bedrock-protocol/pull/88) -* Support xbox title + live.com auth [#86](https://github.com/PrismarineJS/bedrock-protocol/pull/86) +* Fix empty chunks on proxy spawn (#89) +* Send skin data to server (#88) +* Support xbox title + live.com auth (#86) * Protocol updates and fixes -* Fix third party servers, optional client encryption [#83](https://github.com/PrismarineJS/bedrock-protocol/pull/83) +* Fix third party servers, optional client encryption (#83) ## 3.1.0 * Add support for 1.16 diff --git a/README.md b/README.md index 5e3add2..124f1b2 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,20 @@ # bedrock-protocol [![NPM version](https://img.shields.io/npm/v/bedrock-protocol.svg)](http://npmjs.com/package/bedrock-protocol) [![Build Status](https://github.com/PrismarineJS/bedrock-protocol/workflows/CI/badge.svg)](https://github.com/PrismarineJS/bedrock-protocol/actions?query=workflow%3A%22CI%22) +[![Discord](https://img.shields.io/badge/chat-on%20discord-brightgreen.svg)](https://discord.gg/GsEFRM8) [![Try it on gitpod](https://img.shields.io/badge/try-on%20gitpod-brightgreen.svg)](https://gitpod.io/#https://github.com/PrismarineJS/bedrock-protocol) -[![Official Discord](https://img.shields.io/static/v1.svg?label=OFFICIAL&message=DISCORD&color=blue&logo=discord&style=for-the-badge)](https://discord.gg/GsEFRM8) -Minecraft Bedrock Edition (aka MCPE) protocol library, supporting authentication and encryption. Help [contribute](docs/CONTRIBUTING.md). +Minecraft Bedrock Edition (aka MCPE) protocol library, supporting authentication and encryption. Help [contribute](CONTRIBUTING.md). -[Protocol doc](https://prismarinejs.github.io/minecraft-data/?v=bedrock_1.19.10&d=protocol) +This is a work in progress. You can track the progress in https://github.com/PrismarineJS/bedrock-protocol/pull/34. ## Features - - Supports Minecraft Bedrock version 1.16.201, 1.16.210, 1.16.220, 1.17.0, 1.17.10, 1.17.30, 1.17.40, 1.18.0, 1.18.11, 1.18.30, 1.19.1, 1.19.10, 1.19.20, 1.19.21, 1.19.30, 1.19.40, 1.19.41, 1.19.50, 1.19.60, 1.19.62, 1.19.63, 1.19.70, 1.19.80, 1.20.0, 1.20.10, 1.20.30, 1.20.40, 1.20.50, 1.20.61, 1.20.71, 1.20.80, 1.21.0, 1.21.2, 1.21.21, 1.21.30, 1.21.42, 1.21.50, 1.21.60, 1.21.70, 1.21.80, 1.21.90, 1.21.93, 1.21.100, 1.21.111 + - Supports Minecraft Bedrock version 1.16.201, 1.16.210, 1.16.220 - Parse and serialize packets as JavaScript objects - Automatically respond to keep-alive packets - - [Proxy and mitm connections](docs/API.md#proxy-docs) + - [Proxy and mitm connections](docs/API.md) - Client - Authentication - Encryption @@ -34,55 +34,40 @@ Want to contribute on something important for PrismarineJS ? go to https://githu `npm install bedrock-protocol` -To update bedrock-protocol (or any Node.js package) and its dependencies after a previous install, you must run `npm update --depth 9999` - ## Usage ### Client example -Example to connect to a server in offline mode, and relay chat messages back: - ```js const bedrock = require('bedrock-protocol') const client = bedrock.createClient({ host: 'localhost', // optional port: 19132, // optional, default 19132 username: 'Notch', // the username you want to join as, optional if online mode - offline: true // optional, default false. if true, do not login with Xbox Live. You will not be asked to sign-in if set to true. + offline: true // optional, default false. if true, do not login with Xbox Live. You will not be asked to sign-in if set to true. + // Optional for some servers which verify the title ID: + // authTitle: bedrock.title.MinecraftNintendoSwitch }) -client.on('text', (packet) => { // Listen for chat messages from the server and echo them back. - if (packet.source_name != client.username) { +client.on('text', (packet) => { // Listen for chat messages and echo them back. + if (packet.source_name != client.options.username) { client.queue('text', { - type: 'chat', needs_translation: false, source_name: client.username, xuid: '', platform_chat_id: '', filtered_message: '', + type: 'chat', needs_translation: false, source_name: client.username, xuid: '', platform_chat_id: '', message: `${packet.source_name} said: ${packet.message} on ${new Date().toLocaleString()}` }) } }) ``` -### Client example joining a Realm - -Example to connect to a Realm that the authenticating account is owner of or has been invited to: - -```js -const bedrock = require('bedrock-protocol') -const client = bedrock.createClient({ - realms: { - pickRealm: (realms) => realms[0] // Function which recieves an array of joined/owned Realms and must return a single Realm. Can be async - } -}) -``` - ### Server example *Can't connect locally on Windows? See the [faq](docs/FAQ.md)* ```js const bedrock = require('bedrock-protocol') -const server = bedrock.createServer({ +const server = new bedrock.createServer({ host: '0.0.0.0', // optional. host to bind as. port: 19132, // optional - version: '1.17.10', // optional. The server version, latest if not specified. + version: '1.16.220', // optional. The server version, latest if not specified. }) server.on('connect', client => { @@ -104,11 +89,11 @@ ping({ host: 'play.cubecraft.net', port: 19132 }).then(res => { ## Documentation -For documentation on the protocol, and packets/fields see the [protocol documentation](https://prismarinejs.github.io/minecraft-data/protocol). +For documentation on the protocol, and packets/fields see the [proto.yml](data/latest/proto.yml) and [types.yml](data/latest/proto.yml) files. -* See [API documentation](docs/API.md) +See [API documentation](docs/API.md) -* See [frequently asked questions and answers](docs/FAQ.md) +See [faq](docs/FAQ.md)