Skip to content

Commit 495eed5

Browse files
authored
Update doc (PrismarineJS#1300)
* Update README.md * Update index.d.ts
1 parent ccab9fb commit 495eed5

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

docs/README.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ Parse and serialize minecraft packets, plus authentication and encryption.
2222
- Encryption
2323
- Compression
2424
- Both online and offline mode
25-
- Respond to keep-alive packets.
25+
- Respond to keep-alive packets
26+
- Follow DNS service records (SRV)
2627
- Ping a server for status
2728
* Server
2829
- Online/Offline mode
@@ -75,29 +76,30 @@ node-minecraft-protocol is pluggable.
7576
const mc = require('minecraft-protocol');
7677
const client = mc.createClient({
7778
host: "localhost", // optional
78-
port: 25565, // optional
79-
username: "[email protected]",
80-
password: "12345678",
81-
auth: 'microsoft' // optional; by default uses offline mode, if using a microsoft account, set to 'microsoft'
79+
port: 25565, // set if you need a port that isn't 25565
80+
username: 'Bot', // username to join as if auth is `offline`, else a unique identifier for this account. Switch if you want to change accounts
81+
// version: false, // only set if you need a specific version or snapshot (ie: "1.8.9" or "1.16.5"), otherwise it's set automatically
82+
// password: '12345678' // set if you want to use password-based auth (may be unreliable). If specified, the `username` must be an email
8283
});
8384

84-
client.on('chat', function(packet) {
85+
client.on('playerChat', function (ev) {
8586
// Listen for chat messages and echo them back.
86-
const jsonMsg = JSON.parse(packet.message);
87-
88-
if (jsonMsg.translate == 'chat.type.announcement' || jsonMsg.translate == 'chat.type.text') {
89-
const username = jsonMsg.with[0].text;
90-
const msg = jsonMsg.with[1];
91-
92-
if (username === client.username) return;
93-
94-
client.write('chat', {message: msg.text});
95-
}
87+
const content = ev.formattedMessage
88+
? JSON.parse(ev.formattedMessage)
89+
: ev.unsignedChat
90+
? JSON.parse(ev.unsignedContent)
91+
: ev.plainMessage
92+
const jsonMsg = JSON.parse(packet.message)
93+
if (ev.senderName === client.username) return
94+
client.chat(JSON.stringify(content))
9695
});
9796
```
9897

99-
If the server is in offline mode, you may leave out the `password` option and switch auth to `offline`.
100-
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.
98+
Set `auth` to `offline` if the server is in offline mode. If `auth` is set to `microsoft`, you will be prompted to login to microsoft.com with a code in your browser. After signing in on your browser, the client will automatically obtain and cache authentication tokens (under your specified username) so you don't have to sign-in again.
99+
100+
To switch the account, update the supplied username. By default, cached tokens will be stored in your user's .minecraft folder, or if profilesFolder is specified, they'll instead be stored there. For more information on bot options see the [API doc](./API.md).
101+
102+
Note: SRV records will only be looked up if the port is unspecified or set to 25565 and if the `host` is a valid non-local domain name.
101103

102104
### Client example joining a Realm
103105

@@ -125,7 +127,7 @@ const server = mc.createServer({
125127
encryption: true, // optional
126128
host: '0.0.0.0', // optional
127129
port: 25565, // optional
128-
version: '1.20.4'
130+
version: '1.18'
129131
})
130132
const mcData = require('minecraft-data')(server.version)
131133

src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ declare module 'minecraft-protocol' {
4949
on(event: 'connect', handler: () => PromiseLike): this
5050
on(event: string, handler: (data: any, packetMeta: PacketMeta) => PromiseLike): this
5151
on(event: `raw.${string}`, handler: (buffer: Buffer, packetMeta: PacketMeta) => PromiseLike): this
52-
on(event: 'playerChat', handler: (data: { formattedMessage: string, message: string, type: string, sender: string, senderName: string, senderTeam: string, verified?: boolean }) => PromiseLike): this
52+
on(event: 'playerChat', handler: (data: { formattedMessage: string, plainMessage: string, type: string, sender: string, senderName: string, senderTeam: string, verified?: boolean }) => PromiseLike): this
5353
on(event: 'systemChat', handler: (data: { positionId: number, formattedMessage: string }) => PromiseLike): this
5454
// Emitted after the player enters the PLAY state and can send and recieve game packets
5555
on(event: 'playerJoin', handler: () => void): this

0 commit comments

Comments
 (0)