${branchName} branch instead of master.
+ `,
+ branchName,
+ 'master'
+ )
+ console.log(`Pull request created`, pr)
+
+ // Ask mineflayer to handle new update
+ const nodeDispatchPayload = {
+ owner: 'PrismarineJS',
+ repo: 'mineflayer',
+ workflow: 'handle-update.yml',
+ branch: 'master',
+ inputs: {
+ new_mc_version: newVersion,
+ mcdata_branch: triggerBranch,
+ mcdata_pr_url: mcdataPrURL,
+ nmp_branch: branchName,
+ nmp_pr_url: pr.url
+ }
+ }
+ console.log('Sending workflow dispatch', nodeDispatchPayload)
+ await github.sendWorkflowDispatch(nodeDispatchPayload)
+}
+
+main().catch(err => {
+ console.error('Error during update process:', err)
+ process.exit(1)
+})
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 55c2dfce1..684924d02 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -2,33 +2,63 @@ name: CI
on:
push:
- branches: [ master ]
+ branches:
+ - master
pull_request:
- branches: [ master ]
+ branches:
+ - master
-jobs:
- build:
+concurrency:
+ group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || github.run_id }}
+ cancel-in-progress: true
+jobs:
+ Lint:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - name: Use Node.js 24.x
+ uses: actions/setup-node@v1.4.4
+ with:
+ node-version: 24.x
+ - run: npm i && npm run lint
+ PrepareSupportedVersions:
runs-on: ubuntu-latest
+ outputs:
+ matrix: ${{ steps.set-matrix.outputs.matrix }}
+ steps:
+ - uses: actions/checkout@v2
+ - name: Use Node.js 24.x
+ uses: actions/setup-node@v1.4.4
+ with:
+ node-version: 24.x
+ - id: set-matrix
+ run: |
+ node -e "
+ const supportedVersions = require('./src/version').supportedVersions;
+ console.log('matrix='+JSON.stringify({'include': supportedVersions.map(mcVersion => ({mcVersion}))}))
+ " >> $GITHUB_OUTPUT
+ test:
+ needs: PrepareSupportedVersions
+ runs-on: ubuntu-latest
strategy:
- matrix:
- node-version: [14.x]
- mcVersionIndex: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+ matrix: ${{fromJson(needs.PrepareSupportedVersions.outputs.matrix)}}
+ fail-fast: false
steps:
- uses: actions/checkout@v2
- - name: Use Node.js ${{ matrix.node-version }}
+ - name: Use Node.js 24.x
uses: actions/setup-node@v1
with:
- node-version: ${{ matrix.node-version }}
+ node-version: 24.x
- name: Setup Java JDK
- uses: actions/setup-java@v1.3.0
+ uses: actions/setup-java@v1.4.3
with:
- java-version: 1.8
- java-package: jre
- - run: npm install
- - env:
- CIRCLE_NODE_INDEX: ${{ matrix.mcVersionIndex }}
- CIRCLE_NODE_TOTAL: 10
- run: npm test
\ No newline at end of file
+ java-version: '25'
+ distribution: 'adopt'
+ - name: Install dependencies
+ run: npm install
+
+ - name: Run tests
+ run: npm run mochaTest -- -g ${{ matrix.mcVersion }}v
diff --git a/.github/workflows/commands.yml b/.github/workflows/commands.yml
new file mode 100644
index 000000000..40807af7f
--- /dev/null
+++ b/.github/workflows/commands.yml
@@ -0,0 +1,24 @@
+name: Repo Commands
+
+on:
+ issue_comment: # Handle comment commands
+ types: [created]
+ pull_request: # Handle renamed PRs
+ types: [edited]
+permissions:
+ contents: write
+
+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
\ No newline at end of file
diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml
index 7e90156fc..e694d60c4 100644
--- a/.github/workflows/npm-publish.yml
+++ b/.github/workflows/npm-publish.yml
@@ -3,6 +3,9 @@ on:
push:
branches:
- master # Change this to your default branch
+permissions:
+ id-token: write
+ contents: write
jobs:
npm-publish:
name: npm-publish
@@ -13,13 +16,19 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@master
with:
- node-version: 10.0.0
- - name: Publish if version has been updated
- uses: pascalgn/npm-publish-action@4f4bf159e299f65d21cd1cbd96fc5d53228036df
- with: # All of theses inputs are optional
- tag_name: "%s"
- tag_message: "%s"
- commit_pattern: "^Release (\\S+)"
- env: # More info about the environment variables in the README
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this as is, it's automatically generated
- NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} # You need to set this in your repo settings
+ node-version: 24
+ registry-url: 'https://registry.npmjs.org'
+ - id: publish
+ uses: JS-DevTools/npm-publish@v4
+ - name: Create Release
+ if: ${{ steps.publish.outputs.type }}
+ id: create_release
+ uses: actions/create-release@v1
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ with:
+ tag_name: ${{ steps.publish.outputs.version }}
+ release_name: Release ${{ steps.publish.outputs.version }}
+ body: ${{ steps.publish.outputs.version }}
+ draft: false
+ prerelease: false
\ No newline at end of file
diff --git a/.github/workflows/update-from-minecraft-data.yml b/.github/workflows/update-from-minecraft-data.yml
new file mode 100644
index 000000000..752aad543
--- /dev/null
+++ b/.github/workflows/update-from-minecraft-data.yml
@@ -0,0 +1,36 @@
+name: Update from minecraft-data
+
+on:
+ workflow_dispatch:
+ inputs:
+ new_mc_version:
+ description: New minecraft version number
+ required: true
+ type: string
+ mcdata_branch:
+ description: minecraft-data branch for this version
+ required: true
+ type: string
+ mcdata_pr_url:
+ description: minecraft-data PR number to open a PR here against
+ required: false
+ default: ''
+ type: string
+
+jobs:
+ update:
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v4
+ with:
+ token: ${{ secrets.PAT_PASSWORD }}
+
+ - name: Run updator script
+ run: cd .github/helper && npm install && node updator.js
+ env:
+ GITHUB_TOKEN: ${{ secrets.PAT_PASSWORD }}
+ MCDATA_BRANCH: ${{ github.event.inputs.mcdata_branch }}
+ MCDATA_PR_URL: ${{ github.event.inputs.mcdata_pr_url }}
+ NEW_MC_VERSION: ${{ github.event.inputs.new_mc_version }}
diff --git a/.gitignore b/.gitignore
index 3de5bac46..2661e97d9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,7 @@
node_modules
test/npm-debug.log
-test/server
+test/server_*
package-lock.json
versions/
+src/client/*.json
+test_*
\ No newline at end of file
diff --git a/.gitpod.yml b/.gitpod.yml
index 38fc373b5..13f366c56 100644
--- a/.gitpod.yml
+++ b/.gitpod.yml
@@ -1,2 +1,2 @@
tasks:
-- command: npm install
+- command: npm install && sdk install java
diff --git a/.npmrc b/.npmrc
new file mode 100644
index 000000000..43c97e719
--- /dev/null
+++ b/.npmrc
@@ -0,0 +1 @@
+package-lock=false
diff --git a/docs/API.md b/docs/API.md
index a9e684380..1cd652469 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -7,27 +7,51 @@ automatically logged in and validated against mojang's auth.
`options` is an object containing the properties :
* port : default to 25565
- * host : default to localhost
+ * host : default to undefined which means listen to all available ipv4 and ipv6 adresses
+ (see https://nodejs.org/api/net.html#net_server_listen_port_host_backlog_callback for details)
* kickTimeout : default to `10*1000` (10s), kick client that doesn't answer to keepalive after that time
* checkTimeoutInterval : default to `4*1000` (4s), send keepalive packet at that period
* online-mode : default to true
- * beforePing : allow customisation of the answer to ping the server does.
+ * beforePing : allow customisation of the answer to ping the server does.
It takes a function with argument response and client, response is the default json response, and client is client who sent a ping.
It can take as third argument a callback. If the callback is passed, the function should pass its result to the callback, if not it should return.
+ If the result is `false` instead of a response object then the connection is terminated and no ping is returned to the client.
+ * beforeLogin : allow customisation of client before the `success` packet is sent.
+ It takes a function with argument client and should be synchronous for the server to wait for completion before continuing execution.
* motd : default to "A Minecraft server"
+ * motdMsg : A json object of the chat message to use instead of `motd`. Can be build using [prismarine-chat](https://github.com/PrismarineJS/prismarine-chat) and calling .toJSON(). Not used with legacy pings.
* maxPlayers : default to 20
* keepAlive : send keep alive packets : default to true
- * version : 1.8 or 1.9 : default to 1.8
+ * version : the version of the server, defaults to the latest version. Set version to `false` to enable dynamic cross version support.
+ * fallbackVersion (optional) : the version that should be used as a fallback, if the client version isn't supported, only works with dynamic cross version support.
+ * favicon (optional) : the favicon to set, base64 encoded
* customPackets (optional) : an object index by version/state/direction/name, see client_custom_packet for an example
* errorHandler : A way to override the default error handler for client errors. A function that takes a Client and an error.
The default kicks the client.
* hideErrors : do not display errors, default to false
- * agent : a http agent that can be used to set proxy settings for yggdrasil authentication confirmation (see proxy-agent on npm)
+ * agent : a http agent that can be used to set proxy settings for yggdrasil authentication confirmation (see proxy-agent on npm)
+ * validateChannelProtocol (optional) : whether or not to enable protocol validation for custom protocols using plugin channels for the connected clients. Defaults to true
+ * enforceSecureProfile (optional) : Kick clients that do not have chat signing keys from Mojang (1.19+)
+ * generatePreview (optional) : Function to generate chat previews. Takes the raw message string and should return the message preview as a string. (1.19-1.19.2)
+ * socketType (optional) : either `tcp` or `ipc`. Switches from a tcp connection to a ipc socket connection (or named pipes on windows). With the `ipc` option `host` becomes the path off the ipc connection on the local filesystem. Example: `\\.\pipe\minecraft-ipc` (Windows) `/tmp/minecraft-ipc.sock` (unix based systems). See the ipcConnection example for an example.
+ * Server : You can pass a custom server class to use instead of the default one.
## mc.Server(version,[customPackets])
Create a server instance for `version` of minecraft.
+### server.writeToClients(clients, name, params)
+
+Write a packet to all `clients` but encode it only once.
+
+### client.verifyMessage(packet) : boolean
+
+(1.19-1.19.2) Verifies if player's chat message packet was signed with their Mojang provided key. Handled internally (and thus deprecated) in 1.19.3 and above
+
+### client.logSentMessageFromPeer(packet)
+(1.19.1+) You must call this function when the server receives a message from a player and that message gets
+broadcast to other players in player_chat packets. This function stores these packets so the server can then verify a player's lastSeenMessages field in inbound chat packets to ensure chain integrity. For more information, see [chat.md](chat.md).
+
### server.onlineModeExceptions
This is a plain old JavaScript object. Add a key with the username you want to
@@ -65,6 +89,19 @@ Called when a client connects, but before any login has happened. Takes a
Called when a client is logged in against server. Takes a `Client` parameter.
+### `playerJoin` event
+
+Emitted after a player joins and enters the PLAY protocol state and can send and recieve game packets. This is emitted after the `login` event. On 1.20.2 and above after we emit the `login` event, the player will enter a CONFIG state, as opposed to the PLAY state (where game packets can be sent), so you must instead now wait for `playerJoin`.
+
+
+### `listening` event
+
+Called when the server is listening for connections. This means that the server is ready to accept incoming connections.
+
+### `close` event
+
+Called when the server is no longer listening to incoming connections.
+
## mc.createClient(options)
@@ -73,20 +110,58 @@ Returns a `Client` instance and perform login.
`options` is an object containing the properties :
* username
* port : default to 25565
- * password : can be omitted (if the tokens are also omitted then it tries to connect in offline mode)
+ * auth : the type of account to use, either `microsoft`, `mojang`, `offline` or `function (client, options) => void`. defaults to 'offline'.
+ * password : can be omitted
+ * (microsoft account) leave this blank to use device code auth. If you provide
+ a password, we try to do username and password auth, but this does not always work.
+ * (mojang account) If provided, we auth with the username and password. If this
+ is blank, and `profilesFolder` is specified, we auth with the tokens there instead.
+ If neither `password` or `profilesFolder` are specified, we connect in offline mode.
* host : default to localhost
- * clientToken : generated if a password is given
- * accessToken : generated if a password is given
+ * session : An object holding clientToken, accessToken and selectedProfile. Generated after logging in using username + password with mojang auth or after logging in using microsoft auth. `clientToken`, `accessToken` and `selectedProfile: {name: 'Host:
+Port:
+Account Type:
+Username:
+Password:
+