You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 15, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: docs/API.md
+40-6Lines changed: 40 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,17 +15,23 @@ automatically logged in and validated against mojang's auth.
15
15
* beforePing : allow customisation of the answer to ping the server does.
16
16
It takes a function with argument response and client, response is the default json response, and client is client who sent a ping.
17
17
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.
18
19
* beforeLogin : allow customisation of client before the `success` packet is sent.
19
20
It takes a function with argument client and should be synchronous for the server to wait for completion before continuing execution.
20
21
* 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.
* 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
24
28
* customPackets (optional) : an object index by version/state/direction/name, see client_custom_packet for an example
25
29
* errorHandler : A way to override the default error handler for client errors. A function that takes a Client and an error.
26
30
The default kicks the client.
27
31
* 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+)
29
35
30
36
## mc.Server(version,[customPackets])
31
37
@@ -35,6 +41,10 @@ Create a server instance for `version` of minecraft.
35
41
36
42
Write a packet to all `clients` but encode it only once.
37
43
44
+
### client.verifyMessage(packet) : boolean
45
+
46
+
Verifies if player's chat message packet was signed with their Mojang provided key
47
+
38
48
### server.onlineModeExceptions
39
49
40
50
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
72
82
73
83
Called when a client is logged in against server. Takes a `Client` parameter.
74
84
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
+
75
93
76
94
## mc.createClient(options)
77
95
@@ -80,16 +98,20 @@ Returns a `Client` instance and perform login.
80
98
`options` is an object containing the properties :
81
99
* username
82
100
* 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'.
84
102
* password : can be omitted
85
103
* (microsoft account) leave this blank to use device code auth. If you provide
86
104
a password, we try to do username and password auth, but this does not always work.
87
105
* (mojang account) If provided, we auth with the username and password. If this
88
106
is blank, and `profilesFolder` is specified, we auth with the tokens there instead.
89
107
If neither `password` or `profilesFolder` are specified, we connect in offline mode.
90
108
* 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.
93
115
* authServer : auth server, default to https://authserver.mojang.com
94
116
* sessionServer : session server, default to https://sessionserver.mojang.com
@@ -111,7 +133,8 @@ Returns a `Client` instance and perform login.
111
133
* onMsaCode(data) : (optional) callback called when signing in with a microsoft account
112
134
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)
113
135
* 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
This Frequently Asked Question document is meant to help people for the most common things.
4
4
5
-
###How to hide errors ?
5
+
## How to hide errors ?
6
6
7
7
Use `hideErrors: true` in createClient options
8
8
You may also choose to add these listeners :
9
+
9
10
```js
10
11
client.on('error', () => {})
11
12
client.on('end', () => {})
12
13
```
13
14
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.
15
28
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.
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.
57
58
* and [several thousands others](https://github.com/PrismarineJS/node-minecraft-protocol/network/dependents?package_id=UGFja2FnZS0xODEzMDk0OQ%3D%3D)
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`.
95
96
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.
0 commit comments