Skip to content
This repository was archived by the owner on Nov 15, 2022. It is now read-only.

Commit 4bc6ab7

Browse files
committed
Merge upstream
2 parents af64aa9 + b47675f commit 4bc6ab7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+919
-399
lines changed

.github/FUNDING.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
# These are supported funding model platforms
2-
3-
issuehunt: PrismarineJS/node-minecraft-protocol

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
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']
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']
17+
fail-fast: false
1718

1819
steps:
1920
- uses: actions/checkout@v2

docs/API.md

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,23 @@ automatically logged in and validated against mojang's auth.
1515
* 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.
18+
If the result is `false` instead of a response object then the connection is terminated and no ping is returned to the client.
1819
* beforeLogin : allow customisation of client before the `success` packet is sent.
1920
It takes a function with argument client and should be synchronous for the server to wait for completion before continuing execution.
2021
* motd : default to "A Minecraft server"
22+
* 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.
2123
* maxPlayers : default to 20
2224
* keepAlive : send keep alive packets : default to true
23-
* version : 1.8 or 1.9 : default to 1.8
25+
* version : the version of the server, defaults to the latest version. Set version to `false` to enable dynamic cross version support.
26+
* 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.
27+
* favicon (optional) : the favicon to set, base64 encoded
2428
* customPackets (optional) : an object index by version/state/direction/name, see client_custom_packet for an example
2529
* errorHandler : A way to override the default error handler for client errors. A function that takes a Client and an error.
2630
The default kicks the client.
2731
* hideErrors : do not display errors, default to false
28-
* agent : a http agent that can be used to set proxy settings for yggdrasil authentication confirmation (see proxy-agent on npm)
32+
* agent : a http agent that can be used to set proxy settings for yggdrasil authentication confirmation (see proxy-agent on npm)
33+
* validateChannelProtocol (optional) : whether or not to enable protocol validation for custom protocols using plugin channels for the connected clients. Defaults to true
34+
* enforceSecureProfile (optional) : Kick clients that do not have chat signing keys from Mojang (1.19+)
2935

3036
## mc.Server(version,[customPackets])
3137

@@ -35,6 +41,10 @@ Create a server instance for `version` of minecraft.
3541

3642
Write a packet to all `clients` but encode it only once.
3743

44+
### client.verifyMessage(packet) : boolean
45+
46+
Verifies if player's chat message packet was signed with their Mojang provided key
47+
3848
### server.onlineModeExceptions
3949

4050
This is a plain old JavaScript object. Add a key with the username you want to
@@ -72,6 +82,14 @@ Called when a client connects, but before any login has happened. Takes a
7282

7383
Called when a client is logged in against server. Takes a `Client` parameter.
7484

85+
### `listening` event
86+
87+
Called when the server is listening for connections. This means that the server is ready to accept incoming connections.
88+
89+
### `close` event
90+
91+
Called when the server is no longer listening to incoming connections.
92+
7593

7694
## mc.createClient(options)
7795

@@ -80,16 +98,20 @@ Returns a `Client` instance and perform login.
8098
`options` is an object containing the properties :
8199
* username
82100
* port : default to 25565
83-
* auth : the type of account to use, either `microsoft` or `mojang`. default to 'mojang'
101+
* auth : the type of account to use, either `microsoft`, `mojang`, `offline` or `function (client, options) => void`. defaults to 'offline'.
84102
* password : can be omitted
85103
* (microsoft account) leave this blank to use device code auth. If you provide
86104
a password, we try to do username and password auth, but this does not always work.
87105
* (mojang account) If provided, we auth with the username and password. If this
88106
is blank, and `profilesFolder` is specified, we auth with the tokens there instead.
89107
If neither `password` or `profilesFolder` are specified, we connect in offline mode.
90108
* host : default to localhost
91-
* clientToken : generated if a password is given
92-
* accessToken : generated if a password or microsoft account is given
109+
* 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.
110+
* clientToken : generated if a password is given or can be set when when using createClient
111+
* accessToken : generated if a password or microsoft account is given or can be set when using createBot
112+
* 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.
113+
* name : The selected profiles in game name needed for logging in with access and client Tokens.
114+
* id : The selected profiles uuid in short form (without `-`) needed for logging in with access and client Tokens.
93115
* authServer : auth server, default to https://authserver.mojang.com
94116
* sessionServer : session server, default to https://sessionserver.mojang.com
95117
* keepAlive : send keep alive packets : default to true
@@ -111,7 +133,8 @@ Returns a `Client` instance and perform login.
111133
* onMsaCode(data) : (optional) callback called when signing in with a microsoft account
112134
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)
113135
* id : a numeric client id used for referring to multiple clients in a server
114-
136+
* validateChannelProtocol (optional) : whether or not to enable protocol validation for custom protocols using plugin channels. Defaults to true
137+
* disableChatSigning (optional) : Don't try obtaining chat signing keys from Mojang (1.19+)
115138

116139
## mc.Client(isServer,version,[customPackets])
117140

@@ -250,6 +273,13 @@ Start emitting channel events of the given name on the client object.
250273

251274
Unregister a channel `name` and send the unregister packet if `custom` is true.
252275

276+
### client.signMessage(message: string, timestamp: BigInt, salt?: number) : Buffer
277+
278+
Generate a signature for a chat message to be sent to server
279+
280+
### client.verifyMessage(publicKey: Buffer | KeyObject, packet) : boolean
281+
282+
Verifies a player chat packet sent by another player against their public key
253283

254284
## Not Immediately Obvious Data Type Formats
255285

@@ -318,6 +348,10 @@ The minecraft protocol states.
318348

319349
The supported minecraft versions.
320350

351+
## mc.defaultVersion
352+
353+
The current default minecraft version.
354+
321355
## mc.createSerializer({ state = states.HANDSHAKING, isServer = false , version})
322356

323357
Returns a minecraft protocol [serializer](https://github.com/roblabla/ProtoDef#serializerprotomaintype) for these parameters.

docs/FAQ.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
1-
## FAQ
1+
# FAQ
22

33
This Frequently Asked Question document is meant to help people for the most common things.
44

5-
### How to hide errors ?
5+
## How to hide errors ?
66

77
Use `hideErrors: true` in createClient options
88
You may also choose to add these listeners :
9+
910
```js
1011
client.on('error', () => {})
1112
client.on('end', () => {})
1213
```
1314

14-
### How can I make a proxy with this ?
15+
## How can I make a proxy with this ?
16+
17+
* Check out our WIP proxy lib <https://github.com/PrismarineJS/prismarine-proxy>
18+
* See this example <https://github.com/PrismarineJS/node-minecraft-protocol/tree/master/examples/proxy>
19+
* Read this issue <https://github.com/PrismarineJS/node-minecraft-protocol/issues/712>
20+
* check out <https://github.com/Heath123/pakkit>
21+
* Check out this app <https://github.com/wvffle/minecraft-packet-debugger>
22+
23+
## Can you support alternative auth methods?
24+
25+
Supporting alternative authentcation methods has been a long standing issue with Prismarine for awhile. We do add support for using your own custom authentication method by providing a function to the `options.auth` property. In order to keep the legitimacy of the project, and to prevent bad attention from Mojang, we will not be supporting any custom authentication methods in the official repositories.
26+
27+
It is up to the end user to support and maintain the authentication protocol if this is used as support in many of the official channels will be limited.
1528

16-
* Check out our WIP proxy lib https://github.com/PrismarineJS/prismarine-proxy
17-
* See this example https://github.com/PrismarineJS/node-minecraft-protocol/tree/master/examples/proxy
18-
* Read this issue https://github.com/PrismarineJS/node-minecraft-protocol/issues/712
19-
* check out https://github.com/Heath123/pakkit
20-
* Check out this app https://github.com/wvffle/minecraft-packet-debugger
29+
If you still wish to proceed, please make sure to throughly read and attempt to understand all implementations of the authentcation you wish to implement. Using an non-official authentication server can make you vulnerable to all different kinds of attacks which are not limited to insecure and/or malicious code! We will not be held responsible for anything you mess up.

docs/HISTORY.md

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

3+
* Fix new types not being optional. (@IceTank) [#1033](https://github.com/PrismarineJS/node-minecraft-protocol/pull/1033)
4+
5+
## 1.36.0
6+
7+
* Use offline mode as default authentication, fallback to offline mode if invalid option. (@Kashalls)
8+
* Provide interface for using not at all supported alternative accounts. (@Kashalls)
9+
* 1.19 support (@extremeheat)
10+
* Fix unhandled promise rejection on ms auth (@IceTank)
11+
12+
## 1.35.1
13+
14+
* add custom minecraft type varlong which aliases to varint @rob9315
15+
16+
## 1.35.0
17+
18+
* Add option to not answer to pings (@matthi4s)
19+
* Add fallback version for dynamic version (@matthi4s)
20+
* Add motdMsg to createServer (@IceTank & @U9G)
21+
* Bump mocha to 10.x
22+
* Bump standard to 17.x
23+
24+
## 1.34.0
25+
26+
* Export defaultVersion (@matthi4s)
27+
* Fix missing readable-stream types (@IceTank)
28+
29+
## 1.33.0
30+
31+
* Bump mcdata
32+
33+
## 1.32.2
34+
35+
* fix: cross version ping
36+
37+
## 1.32.1
38+
39+
* fix protocolValidation not being optional in .d.ts typings (@IceTank)
40+
41+
## 1.32.0
42+
43+
* add protocolValidation field to server and client options (@RichardDorian)
44+
* fix plugin channel registration (@RichardDorian)
45+
* allows false value for profilesFolder (@Robbilie)
46+
47+
## 1.31.0
48+
49+
* 1.18.2
50+
51+
## 1.30.0
52+
53+
* add reasons for client.end() & fix issues (@U5B)
54+
55+
## 1.29.1
56+
57+
* Remove entitlement check in microsoftAuth (#929)
58+
359
## 1.29.0
460

561
* 1.18.0 support

docs/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Parse and serialize minecraft packets, plus authentication and encryption.
1313

1414
* Supports Minecraft PC version 1.7.10, 1.8.8, 1.9 (15w40b, 1.9, 1.9.1-pre2, 1.9.2, 1.9.4),
1515
1.10 (16w20a, 1.10-pre1, 1.10, 1.10.1, 1.10.2), 1.11 (16w35a, 1.11, 1.11.2), 1.12 (17w15a, 17w18b, 1.12-pre4, 1.12, 1.12.1, 1.12.2), and 1.13 (17w50a, 1.13, 1.13.1, 1.13.2-pre1, 1.13.2-pre2, 1.13.2), 1.14 (1.14, 1.14.1, 1.14.3, 1.14.4)
16-
, 1.15 (1.15, 1.15.1, 1.15.2) and 1.16 (20w13b, 20w14a, 1.16-rc1, 1.16, 1.16.1, 1.16.2, 1.16.3, 1.16.4), 1.17 (21w07a, 1.17, 1.17.1), 1.18
16+
, 1.15 (1.15, 1.15.1, 1.15.2) and 1.16 (20w13b, 20w14a, 1.16-rc1, 1.16, 1.16.1, 1.16.2, 1.16.3, 1.16.4), 1.17 (21w07a, 1.17, 1.17.1), 1.18 (1.18, 1.18.1 and 1.18.2), 1.19
1717
* Parses all packets and emits events with packet fields as JavaScript
1818
objects.
1919
* Send a packet by supplying fields as a JavaScript object.
@@ -51,9 +51,10 @@ node-minecraft-protocol is pluggable.
5151
create bots.
5252
* [flying-squid](https://github.com/PrismarineJS/flying-squid) - Create minecraft
5353
servers with a high level API, also a minecraft server by itself.
54-
* [pakkit](https://github.com/Heath123/pakkit) - A GUI tool to monitor Minecraft packets in real time, allowing you to view their data and interactively edit and resend them
55-
* [minecraft-packet-debugger](https://github.com/wvffle/minecraft-packet-debugger) - A tool to capture Minecraft packets in a buffer then view them in a browser
56-
* [aresrpg](https://github.com/aresrpg/aresrpg) - An open-source mmorpg minecraft server
54+
* [pakkit](https://github.com/Heath123/pakkit) - A GUI tool to monitor Minecraft packets in real time, allowing you to view their data and interactively edit and resend them.
55+
* [minecraft-packet-debugger](https://github.com/wvffle/minecraft-packet-debugger) - A tool to capture Minecraft packets in a buffer then view them in a browser.
56+
* [aresrpg](https://github.com/aresrpg/aresrpg) - An open-source mmorpg minecraft server.
57+
* [SteveProxy](https://github.com/SteveProxy/proxy) - Proxy for Minecraft with the ability to change the gameplay using plugins.
5758
* and [several thousands others](https://github.com/PrismarineJS/node-minecraft-protocol/network/dependents?package_id=UGFja2FnZS0xODEzMDk0OQ%3D%3D)
5859

5960
## Installation
@@ -77,7 +78,7 @@ var client = mc.createClient({
7778
port: 25565, // optional
7879
username: "[email protected]",
7980
password: "12345678",
80-
auth: 'mojang' // optional; by default uses mojang, if using a microsoft account, set to 'microsoft'
81+
auth: 'microsoft' // optional; by default uses offline mode, if using a microsoft account, set to 'microsoft'
8182
});
8283
client.on('chat', function(packet) {
8384
// Listen for chat messages and echo them back.
@@ -91,7 +92,7 @@ client.on('chat', function(packet) {
9192
});
9293
```
9394

94-
If the server is in offline mode, you may leave out the `password` option.
95+
If the server is in offline mode, you may leave out the `password` option and switch auth to `offline`.
9596
You can also leave out `password` when using a Microsoft account. If provided, password based auth will be attempted first which may fail. *Note:* if using a Microsoft account, your account age must be >= 18 years old.
9697

9798
### Hello World server example

0 commit comments

Comments
 (0)