Skip to content

Commit

Permalink
Merge pull request #122 from PrismarineJS/master
Browse files Browse the repository at this point in the history
Update upstream
  • Loading branch information
matthi4s authored Jul 8, 2024
2 parents 827b6cd + 495eed5 commit 8ff614c
Show file tree
Hide file tree
Showing 35 changed files with 525 additions and 315 deletions.
46 changes: 29 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,39 @@ on:
- master

jobs:
test:
Lint:
runs-on: ubuntu-latest
strategy:
matrix:
mcVersion: ['1.7', '1.8', '1.9', '1.10', '1.11.2', '1.12.2', '1.13.2', '1.14.4', '1.15.2', '1.16.5', '1.17', '1.17.1', '1.18.2', '1.19', '1.19.2', '1.19.3', '1.19.4', '1.20', '1.20.1']
fail-fast: false

steps:
- uses: actions/checkout@v2
- name: Use Node.js 18.x
uses: actions/setup-node@v1
uses: actions/setup-node@v1.4.4
with:
node-version: 18.x
- name: Setup Java JDK
uses: actions/setup-java@v1.4.3
- 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 18.x
uses: actions/setup-node@v1.4.4
with:
java-version: '17'
distribution: 'adopt'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test -- -g ${{ matrix.mcVersion }}
packet-cycle-test:
node-version: 18.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: ${{fromJson(needs.PrepareSupportedVersions.outputs.matrix)}}
fail-fast: false

steps:
- uses: actions/checkout@v2
Expand All @@ -43,6 +52,9 @@ jobs:
- name: Setup Java JDK
uses: actions/setup-java@v1.4.3
with:
java-version: '16'
java-version: '17'
distribution: 'adopt'
- run: npm install && npm run test-non-par
- name: Install dependencies
run: npm install
- name: Run tests
run: npm run mochaTest -- -g ${{ matrix.mcVersion }}v
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
node_modules
test/npm-debug.log
test/server*
test/server_*
package-lock.json
versions/
src/client/*.json
35 changes: 23 additions & 12 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ automatically logged in and validated against mojang's auth.
* 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.
Expand All @@ -34,7 +34,8 @@ automatically logged in and validated against mojang's auth.
* 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.
Expand Down Expand Up @@ -88,6 +89,11 @@ 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.
Expand All @@ -112,7 +118,7 @@ Returns a `Client` instance and perform login.
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
* 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: '<username>', id: '<selected profile uuid>'}` can be set inside of `session` when using createClient to login with a client and access Token instead of a password. `session` is also emitted by the `Client` instance with the event 'session' after successful authentication.
* 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: '<username>', id: '<selected profile uuid>'}` can be set inside of `session` when using createClient to login with a client and access Token instead of a password. `session` is also emitted by the `Client` instance with the event 'session' after successful authentication.
* clientToken : generated if a password is given or can be set when when using createClient
* accessToken : generated if a password or microsoft account is given or can be set when using createBot
* selectedProfile : generated if a password or microsoft account is given. Can be set as a object with property `name` and `id` that specifies the selected profile.
Expand All @@ -129,21 +135,22 @@ Returns a `Client` instance and perform login.
* hideErrors : do not display errors, default to false
* skipValidation : do not try to validate given session, defaults to false
* stream : a stream to use as connection
* connect : a function taking the client as parameter and that should client.setSocket(socket)
* connect : a function taking the client as parameter and that should client.setSocket(socket)
and client.emit('connect') when appropriate (see the proxy examples for an example of use)
* agent : a http agent that can be used to set proxy settings for yggdrasil authentication (see proxy-agent on npm)
* agent : a http agent that can be used to set proxy settings for yggdrasil authentication (see proxy-agent on npm)
* fakeHost : (optional) hostname to send to the server in the set_protocol packet
* profilesFolder : optional
* (mojang account) the path to the folder that contains your `launcher_profiles.json`. defaults to your minecraft folder if it exists, otherwise the local directory. set to `false` to disable managing profiles
* (mojang account) the path to the folder that contains your `launcher_profiles.json`. defaults to your minecraft folder if it exists, otherwise the local directory. set to `false` to disable managing profiles
* (microsoft account) the path to store authentication caches, defaults to .minecraft
* onMsaCode(data) : (optional) callback called when signing in with a microsoft account
with device code auth. `data` is an object documented [here](https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-device-code#device-authorization-response)
* id : a numeric client id used for referring to multiple clients in a server
* validateChannelProtocol (optional) : whether or not to enable protocol validation for custom protocols using plugin channels. Defaults to true
* disableChatSigning (optional) : Don't try obtaining chat signing keys from Mojang (1.19+)
* realms : An object which should contain one of the following properties: `realmId` or `pickRealm`. When defined will attempt to join a Realm without needing to specify host/port. **The authenticated account must either own the Realm or have been invited to it**
* realmId : The id of the Realm to join.
* pickRealm(realms) : A function which will have an array of the user Realms (joined/owned) passed to it. The function should return a Realm.
* realms : An object which should contain one of the following properties: `realmId` or `pickRealm`. When defined will attempt to join a Realm without needing to specify host/port. **The authenticated account must either own the Realm or have been invited to it**
* realmId : The id of the Realm to join.
* pickRealm(realms) : A function which will have an array of the user Realms (joined/owned) passed to it. The function should return a Realm.
* Client : You can pass a custom client class to use instead of the default one, which would allow you to create completely custom communication. Also note that you can use the `stream` option instead where you can supply custom duplex, but this will still use serialization/deserialization of packets.


## mc.Client(isServer,version,[customPackets])
Expand Down Expand Up @@ -231,11 +238,11 @@ The client's protocol version

### client.version

The client's version
The client's version, as a string

### `packet` event

Called with every packet parsed. Takes four paramaters, the JSON data we parsed, the packet metadata (name, state), the buffer (raw data) and the full buffer (includes surplus data and may include the data of following packets on versions below 1.8)
Called with every packet parsed. Takes four paramaters, the JSON data we parsed, the packet metadata (name, state), the buffer (raw data) and the full buffer (includes surplus data and may include the data of following packets on versions below 1.8)

### `raw` event

Expand All @@ -259,6 +266,10 @@ Called when user authentication is resolved. Takes session data as parameter.
Called when the protocol changes state. Takes the new state and old state as
parameters.

### `playerJoin` event

Emitted after the player enters the PLAY protocol state and can send and recieve game packets

### `error` event

Called when an error occurs within the client. Takes an Error as parameter.
Expand All @@ -272,7 +283,7 @@ Called when a chat message from another player arrives. The emitted object conta
* type -- the message type - on 1.19, which format string to use to render message ; below, the place where the message is displayed (for example chat or action bar)
* sender -- the UUID of the player sending the message
* senderTeam -- scoreboard team of the player (pre 1.19)
* senderName -- Name of the sender
* senderName -- Name of the sender
* targetName -- Name of the target (for outgoing commands like /tell). Only in 1.19.2+
* verified -- true if message is signed, false if not signed, undefined on versions prior to 1.19

Expand Down
19 changes: 19 additions & 0 deletions docs/HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# History

## 1.47.0
* [1.20.3 / 1.20.4 support (#1275)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/1d9a38253a28a515d82fffa13806cb0874c5b36c) (thanks @wgaylord)

## 1.46.0
* [Ensure `onReady` in client is called once (#1287)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/85a26a52944c89af273bc974380b438073280981) (thanks @extremeheat)
* [Acknowledge returning to configuration state if in play state. (#1284)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/092e10c53d33a7b9be52b5cbb67b1e3e55ac2690) (thanks @wgaylord)
* [Allow commands not to be signed (#1277)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/21240f8ab2fd41c76f50b64e3b3a945f50b25b5e) (thanks @forester302)
* [Add test to make sure version that are tested are mentioned in the RE… (#1276)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/80d038bd61d1933daa1e5e3251635be9ce2116b6) (thanks @rom1504)
* [Print if there is a diff in packets in the cycle packet test (#1273)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/614be919d0f20a43e238751c829a6d584ae636cd) (thanks @rom1504)
* [Align supported versions with mineflayer (#1272)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/ccaf538ffd2ab1e25dabd752d721f97bd8bd188f) (thanks @rom1504)

## 1.45.0
* [Pc1.20.2 (#1265)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/112926da0cb2490934d122dd8ed7b79f3f6de8eb) (thanks @extremeheat)
* [Improve CI setup for per version tests (#1267)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/1740124c4722c2c49f8aed0d708ff5ebecc7743c) (thanks @rom1504)
* [Allow to create custom client & communication between clients (#1254)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/9e991094761d51243cb28a33bb45630f3064511d) (thanks @zardoy)
* [Fixed 'unsignedContent' field using nonexistent 'packet.unsignedContent' when emitting 'playerChat' event. (#1263)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/066a2b3646cb8bef6be1fa974597b975aaf08d42) (thanks @Ynfuien)
* [Add chat typing to client (#1260)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/788bff289030fa66c980de82d82cb953bf76332b) (thanks @IceTank)
* [chat: Only sign command args when profile keys defined (#1257)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/0ac8c087a28b3ccc73f8eea5941e4902e33c494e) (thanks @evan-goode)

## 1.44.0
* [Send chat commands as chat commands instead of chat messages for 1.19.3-1.20.1 (#1241)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/41f9e4ac4a35b0ce241264a3f964c4874d96a119) (thanks @lkwilson)
* [Fix end bundle bundle_delimiter packet not being emitted (#1248)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/35b2aa536a4739c11fe78f6e8e5c591abd0b0498) (thanks @PondWader)
Expand Down
Loading

0 comments on commit 8ff614c

Please sign in to comment.