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
Copy file name to clipboardExpand all lines: README.md
+18-1Lines changed: 18 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ Note that only servers with the `server.properties` option `enable-query` set to
16
16
The main advantage of the Query protocol over the ping protocol ist that it returns the
17
17
full list of players on the server, not just a small sample. It does, however, also have a few disadvantages,
18
18
like the fact that servers will return broken response packets if the MOTD (or any other string) [contains null bytes](https://bugs.mojang.com/browse/MC-221987)
19
-
or [some other special characters](https://bugs.mojang.com/browse/MC-231035).
19
+
or [some other special characters](https://bugs.mojang.com/browse/MC-231035) in versions before 1.21.11.
20
20
This library makes an effort to interpret these broken response packets correctly, but it is not always possible to do so.
21
21
22
22
```js
@@ -34,6 +34,23 @@ and [`FullStatResponse`](src/Packet/Query/FullStatResponse.js) object respective
34
34
35
35
Note that the query client needs to be closed manually, since it keeps its UDP socket open to reuse it for future queries.
36
36
37
+
#### Query string encoding
38
+
39
+
Since string encoding in query responses switched to UTF-8 in Minecraft 1.21.11, this library makes an effort to detect
40
+
the correct encoding automatically.
41
+
- In full stat responses, this works pretty reliably based on the version field.
42
+
- Basic stat responses do not include the server version, so the library has to make a guess based on the content of the string.
43
+
If the whole string is valid UTF-8, it will be decoded as UTF-8. If it contains invalid UTF-8 sequences, it will be decoded as ISO-8859-1 instead.
44
+
45
+
You can force the string encoding using the `useLegacyStringEncoding` option, where `true` will force ISO-8859-1 encoding and `false` will force UTF-8 encoding.
46
+
By default, this option is set to `null`, which means that the library will try to detect the correct encoding automatically.
47
+
48
+
```js
49
+
let useLegacyStringEncoding =true; // true, false, or null
50
+
let basic =awaitclient.queryBasic('localhost', 25565, AbortSignal.timeout(5000), useLegacyStringEncoding);
51
+
let full =awaitclient.queryFull('localhost', 25565, AbortSignal.timeout(5000), useLegacyStringEncoding);
52
+
```
53
+
37
54
### Java Edition Ping
38
55
The [Server List Ping protocol](https://wiki.vg/Server_List_Ping) is what the Minecraft client uses to show the server status in the in-game server list.
39
56
This protocol changed multiple times over the years, so you'd ideally want to know the version of the server you are pinging to use the correct protocol version.
0 commit comments