Skip to content

Commit 8ff614c

Browse files
authored
Merge pull request #122 from PrismarineJS/master
Update upstream
2 parents 827b6cd + 495eed5 commit 8ff614c

35 files changed

+525
-315
lines changed

.github/workflows/ci.yml

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,39 @@ on:
99
- master
1010

1111
jobs:
12-
test:
12+
Lint:
1313
runs-on: ubuntu-latest
14-
strategy:
15-
matrix:
16-
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']
17-
fail-fast: false
1814

1915
steps:
2016
- uses: actions/checkout@v2
2117
- name: Use Node.js 18.x
22-
uses: actions/setup-node@v1
18+
uses: actions/setup-node@v1.4.4
2319
with:
2420
node-version: 18.x
25-
- name: Setup Java JDK
26-
uses: actions/[email protected]
21+
- run: npm i && npm run lint
22+
PrepareSupportedVersions:
23+
runs-on: ubuntu-latest
24+
outputs:
25+
matrix: ${{ steps.set-matrix.outputs.matrix }}
26+
27+
steps:
28+
- uses: actions/checkout@v2
29+
- name: Use Node.js 18.x
30+
uses: actions/[email protected]
2731
with:
28-
java-version: '17'
29-
distribution: 'adopt'
30-
- name: Install dependencies
31-
run: npm install
32-
- name: Run tests
33-
run: npm test -- -g ${{ matrix.mcVersion }}
34-
packet-cycle-test:
32+
node-version: 18.x
33+
- id: set-matrix
34+
run: |
35+
node -e "
36+
const supportedVersions = require('./src/version').supportedVersions;
37+
console.log('matrix='+JSON.stringify({'include': supportedVersions.map(mcVersion => ({mcVersion}))}))
38+
" >> $GITHUB_OUTPUT
39+
test:
40+
needs: PrepareSupportedVersions
3541
runs-on: ubuntu-latest
42+
strategy:
43+
matrix: ${{fromJson(needs.PrepareSupportedVersions.outputs.matrix)}}
44+
fail-fast: false
3645

3746
steps:
3847
- uses: actions/checkout@v2
@@ -43,6 +52,9 @@ jobs:
4352
- name: Setup Java JDK
4453
uses: actions/[email protected]
4554
with:
46-
java-version: '16'
55+
java-version: '17'
4756
distribution: 'adopt'
48-
- run: npm install && npm run test-non-par
57+
- name: Install dependencies
58+
run: npm install
59+
- name: Run tests
60+
run: npm run mochaTest -- -g ${{ matrix.mcVersion }}v

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
node_modules
22
test/npm-debug.log
3-
test/server*
3+
test/server_*
44
package-lock.json
55
versions/
66
src/client/*.json

docs/API.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ automatically logged in and validated against mojang's auth.
1212
* kickTimeout : default to `10*1000` (10s), kick client that doesn't answer to keepalive after that time
1313
* checkTimeoutInterval : default to `4*1000` (4s), send keepalive packet at that period
1414
* online-mode : default to true
15-
* beforePing : allow customisation of the answer to ping the server does.
15+
* beforePing : allow customisation of the answer to ping the server does.
1616
It takes a function with argument response and client, response is the default json response, and client is client who sent a ping.
1717
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.
1818
If the result is `false` instead of a response object then the connection is terminated and no ping is returned to the client.
@@ -34,7 +34,8 @@ automatically logged in and validated against mojang's auth.
3434
* enforceSecureProfile (optional) : Kick clients that do not have chat signing keys from Mojang (1.19+)
3535
* 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)
3636
* 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.
37-
37+
* Server : You can pass a custom server class to use instead of the default one.
38+
3839
## mc.Server(version,[customPackets])
3940

4041
Create a server instance for `version` of minecraft.
@@ -88,6 +89,11 @@ Called when a client connects, but before any login has happened. Takes a
8889

8990
Called when a client is logged in against server. Takes a `Client` parameter.
9091

92+
### `playerJoin` event
93+
94+
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`.
95+
96+
9197
### `listening` event
9298

9399
Called when the server is listening for connections. This means that the server is ready to accept incoming connections.
@@ -112,7 +118,7 @@ Returns a `Client` instance and perform login.
112118
is blank, and `profilesFolder` is specified, we auth with the tokens there instead.
113119
If neither `password` or `profilesFolder` are specified, we connect in offline mode.
114120
* host : default to localhost
115-
* 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.
121+
* 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.
116122
* clientToken : generated if a password is given or can be set when when using createClient
117123
* accessToken : generated if a password or microsoft account is given or can be set when using createBot
118124
* 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.
@@ -129,21 +135,22 @@ Returns a `Client` instance and perform login.
129135
* hideErrors : do not display errors, default to false
130136
* skipValidation : do not try to validate given session, defaults to false
131137
* stream : a stream to use as connection
132-
* connect : a function taking the client as parameter and that should client.setSocket(socket)
138+
* connect : a function taking the client as parameter and that should client.setSocket(socket)
133139
and client.emit('connect') when appropriate (see the proxy examples for an example of use)
134-
* agent : a http agent that can be used to set proxy settings for yggdrasil authentication (see proxy-agent on npm)
140+
* agent : a http agent that can be used to set proxy settings for yggdrasil authentication (see proxy-agent on npm)
135141
* fakeHost : (optional) hostname to send to the server in the set_protocol packet
136142
* profilesFolder : optional
137-
* (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
143+
* (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
138144
* (microsoft account) the path to store authentication caches, defaults to .minecraft
139145
* onMsaCode(data) : (optional) callback called when signing in with a microsoft account
140146
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)
141147
* id : a numeric client id used for referring to multiple clients in a server
142148
* validateChannelProtocol (optional) : whether or not to enable protocol validation for custom protocols using plugin channels. Defaults to true
143149
* disableChatSigning (optional) : Don't try obtaining chat signing keys from Mojang (1.19+)
144-
* 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**
145-
* realmId : The id of the Realm to join.
146-
* pickRealm(realms) : A function which will have an array of the user Realms (joined/owned) passed to it. The function should return a Realm.
150+
* 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**
151+
* realmId : The id of the Realm to join.
152+
* pickRealm(realms) : A function which will have an array of the user Realms (joined/owned) passed to it. The function should return a Realm.
153+
* 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.
147154

148155

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

232239
### client.version
233240

234-
The client's version
241+
The client's version, as a string
235242

236243
### `packet` event
237244

238-
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)
245+
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)
239246

240247
### `raw` event
241248

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

269+
### `playerJoin` event
270+
271+
Emitted after the player enters the PLAY protocol state and can send and recieve game packets
272+
262273
### `error` event
263274

264275
Called when an error occurs within the client. Takes an Error as parameter.
@@ -272,7 +283,7 @@ Called when a chat message from another player arrives. The emitted object conta
272283
* 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)
273284
* sender -- the UUID of the player sending the message
274285
* senderTeam -- scoreboard team of the player (pre 1.19)
275-
* senderName -- Name of the sender
286+
* senderName -- Name of the sender
276287
* targetName -- Name of the target (for outgoing commands like /tell). Only in 1.19.2+
277288
* verified -- true if message is signed, false if not signed, undefined on versions prior to 1.19
278289

docs/HISTORY.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# History
22

3+
## 1.47.0
4+
* [1.20.3 / 1.20.4 support (#1275)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/1d9a38253a28a515d82fffa13806cb0874c5b36c) (thanks @wgaylord)
5+
6+
## 1.46.0
7+
* [Ensure `onReady` in client is called once (#1287)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/85a26a52944c89af273bc974380b438073280981) (thanks @extremeheat)
8+
* [Acknowledge returning to configuration state if in play state. (#1284)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/092e10c53d33a7b9be52b5cbb67b1e3e55ac2690) (thanks @wgaylord)
9+
* [Allow commands not to be signed (#1277)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/21240f8ab2fd41c76f50b64e3b3a945f50b25b5e) (thanks @forester302)
10+
* [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)
11+
* [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)
12+
* [Align supported versions with mineflayer (#1272)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/ccaf538ffd2ab1e25dabd752d721f97bd8bd188f) (thanks @rom1504)
13+
14+
## 1.45.0
15+
* [Pc1.20.2 (#1265)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/112926da0cb2490934d122dd8ed7b79f3f6de8eb) (thanks @extremeheat)
16+
* [Improve CI setup for per version tests (#1267)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/1740124c4722c2c49f8aed0d708ff5ebecc7743c) (thanks @rom1504)
17+
* [Allow to create custom client & communication between clients (#1254)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/9e991094761d51243cb28a33bb45630f3064511d) (thanks @zardoy)
18+
* [Fixed 'unsignedContent' field using nonexistent 'packet.unsignedContent' when emitting 'playerChat' event. (#1263)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/066a2b3646cb8bef6be1fa974597b975aaf08d42) (thanks @Ynfuien)
19+
* [Add chat typing to client (#1260)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/788bff289030fa66c980de82d82cb953bf76332b) (thanks @IceTank)
20+
* [chat: Only sign command args when profile keys defined (#1257)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/0ac8c087a28b3ccc73f8eea5941e4902e33c494e) (thanks @evan-goode)
21+
322
## 1.44.0
423
* [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)
524
* [Fix end bundle bundle_delimiter packet not being emitted (#1248)](https://github.com/PrismarineJS/node-minecraft-protocol/commit/35b2aa536a4739c11fe78f6e8e5c591abd0b0498) (thanks @PondWader)

0 commit comments

Comments
 (0)