Skip to content

Commit 7b3a871

Browse files
committed
1.2.2: Fixed bug issue #4, added CommonJS export, bumped protocol version
- 🛠️ Fixed bug from issue #4 that caused incorrect parsing of status responses from modded servers. - ⚙️ Added support for both CommonJS and ES module exports, and updated the module target to ESNext. - ⚙️ Bumped the default protocol version from `767` (1.21.1) to `769` (1.21.4) view CHANGELOG.md
1 parent 310c3f7 commit 7b3a871

File tree

7 files changed

+64
-51
lines changed

7 files changed

+64
-51
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog!
22

3+
<h2>v1.2.2</h2>
4+
5+
<sup>[NPM](https://www.npmjs.com/package/minecraftstatuspinger/v/1.2.2) | [JSR](https://jsr.io/@minecraft/[email protected])</sup>
6+
7+
- 🛠️ Fixed bug from issue [#4](https://github.com/woodendoors7/MinecraftStatusPinger/issues/4) that caused incorrect parsing of status responses from modded servers.
8+
- ⚙️ Added support for both CommonJS and ES module exports, and updated the module target to ESNext.
9+
- ⚙️ Bumped the default protocol version from `767` (1.21.1) to `769` (1.21.4)
10+
311
<h2>v1.2.1</h2>
412

513
<sup>[NPM](https://www.npmjs.com/package/minecraftstatuspinger/v/1.2.1) | [JSR](https://jsr.io/@minecraft/[email protected])</sup>

README.md

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
![TS Types](https://badgen.net/npm/types/minecraftstatuspinger)
1616
![License](https://badgen.net/npm/license/minecraftstatuspinger)
1717
![NPM Downloads](https://badgen.net/npm/dy/minecraftstatuspinger/?color=00a600)
18-
![Maintained?](https://badgen.net/static/Maintained%3F/Yes/00a600)
18+
![Maintained?](https://badgen.net/static/Maintained%3F/Yes!/00a600)
1919

2020
### What can this be used for?
2121

@@ -28,8 +28,8 @@
2828
**And in general, checking the status of Minecraft servers!**
2929
## Getting started
3030
### Requirements
31-
- NodeJS or Deno (used to run JavaScript code)
32-
- NPM (used to install Node packages)
31+
- NodeJS, Deno or Bun (used to run JavaScript code)
32+
- NPM/JSR (used to install JavaScript packages)
3333

3434
### Installation
3535
```bat
@@ -40,27 +40,28 @@ npm install minecraftstatuspinger
4040
```typescript
4141
import mc from "minecraftstatuspinger";
4242

43-
let result = await mc.lookup({ host: "mc.hypixel.net" })
43+
let result = await mc.lookup({ host: "mc.hypixel.net" });
4444
console.log(result);
4545
```
4646

47-
<details>
47+
<details open>
4848
<summary><h3>Advanced Example</h3></summary>
49-
<br>
5049

5150
```typescript
5251
import mc from "minecraftstatuspinger";
52+
//OR
53+
const mc = require("minecraftstatuspinger");
5354

5455
let result = await mc.lookup({
55-
host: "mc.hypixel.net",
56-
port: 25565,
57-
ping: true,
58-
protocolVersion: 767,
59-
timeout: 10000,
60-
throwOnParseError: true,
61-
SRVLookup: true,
62-
JSONParse: true
63-
})
56+
host: "mc.hypixel.net", // A hostname, or an IP of your server.
57+
port: 25565, // Port of the server.
58+
ping: true, // Whether to get the latency of the server, or skip that part.
59+
protocolVersion: 769, // Minecraft version - 769 is 1.21.4
60+
timeout: 10000, // Time in milliseconds to wait for a response before throwing an error.
61+
throwOnParseError: true, // Whether to throw an error if parsing of the status response fails.
62+
SRVLookup: true, // Whether to do a SRV lookup before doing a normal lookup.
63+
JSONParse: true // Whether to skip parsing the JSON response entirely.
64+
});
6465

6566
console.log(result);
6667
```
@@ -74,49 +75,52 @@ console.log(result);
7475
* <b id="lookupOptions">.lookup(): </b>*`((options: ServerStatusOptions) => Promise<ServerStatus>)`*
7576
* **options:** ServerStatusOptions
7677
* <b>`host:`</b> string
77-
> Either an IP, or a hostname of the server. (alias: hostname)
78+
> An IP address or hostname of the server. (alias: hostname)
7879
* <b>`port?:`</b> number <i> `default: 25565`</i>
7980
> Port of the server. SRV lookup is disabled when using ports other than 25565.
8081
* <b>`timeout?:`</b> number <i>`default: 10000`</i>
81-
> How long until an error is thrown if the transaction still hasn't finished. Default is 10 seconds.
82+
> The time (in milliseconds) to wait for a response before throwing an error if the transaction isn’t completed. (Default: 10 seconds)
8283
* <b>`ping?:`</b> boolean <i>`default: true`</i>
8384
> Whether to send a payload at the end to measure the server latency. If false, the `latency` field will be null.
84-
* <b>`protocolVersion?:`</b> number <i>`default: 767`</i>
85-
> Protocol version to send to the server to simulate different Minecraft client versions. Here, you can see the [Protocol Version Numbers](https://wiki.vg/Protocol_version_numbers). The current default protocol version is for 1.21.1 (767) and will be irregularly updated to newer versions.
85+
* <b>`protocolVersion?:`</b> number <i>`default: 769`</i>
86+
> The protocol version sent to the server to simulate different Minecraft client versions. Refer to the [Protocol Version Numbers](https://wiki.vg/Protocol_version_numbers) for details. It is recommended to set this explicitly, as it will be updated periodically through minor version bumps. The default is 769 (Minecraft 1.21.4).
8687
* <b>`throwOnParseError?:`</b> boolean <i>`default: true`</i>
87-
> Whether to throw an error if the status packet fails to parse the status field. The `statusRaw` field is always included.
88+
> If true, an error will be thrown when the the status field fails to parse. The raw status response is always provided in the `statusRaw` field.
8889
* <b>`SRVLookup?:`</b> boolean <i>`default: true`</i>
89-
> Whether to perform a SRV lookup on the provided hostname. Set to `true` in order to skip. Useful to disable when you're only looking up the basic DNS records and a server with a specific port.
90+
> Whether to perform a SRV lookup on the provided hostname. Set to `false` to skip the lookup, which is useful when you're only looking for basic DNS records. It is automatically disabled when you define a port different from 25565.
9091
* <b>`JSONParse?:`</b> boolean <i>`default: true`</i>
9192
> Whether to parse the JSON `status` field. Useful to disable when you only need the raw plaintext response. If false, the `status` field will be null.
9293
* ServerStatus
9394
* <b>`latency?:`</b> number
9495
> The time it takes to receive back a response after sending a small payload to a server, in milliseconds. Will be null if the `ping` option is false.
9596
* <b>`status?:`</b> DynamicObject
96-
> Parsed status response from the server. Will be null if the status fails to parse, or if disableJSONParse is true. <a href="https://pinger.floppa.hair/responses/">Example of a valid Status Response.</a>
97+
> Parsed status response from the server. This field will be null if parsing fails or if `JSONParse` is false. <a href="https://pinger.floppa.hair/responses/">Example of a valid Status Response.</a>
9798
* <b>`statusRaw:`</b> string
9899
> Plaintext status response in the form of JSON. Useful when `status` fails to parse.
99100
100101
* <b id="setDnsOptions">.setDnsServers(): `((serverArray: string[]) => Promise<boolean>)`</b>
101-
> It wraps the `dns.setServers` function, useful for looking up SRV records through different DNS servers. <br>
102+
> Wraps the `dns.setServers` function, useful for quicker lookups through different DNS servers. <br>
102103
The first IP in the array will always be used first, others will be tried if the first one is unreachable. <br><br>
103-
Accepts an array of hostnames or IP addresses of DNS servers. It will either return true, or throw an error.
104-
104+
Accepts an array of hostnames or IP addresses of DNS servers. It will either return true, or throw an error, otherwise, it uses the default DNS servers of your computer.<br><br>
105+
❗ Changing the default DNS servers is recommended, if you're doing tons of lookups at once.
106+
105107

108+
106109
Usage:
107110
```js
108111
// For example:
109112
mc.setDnsServers(["9.9.9.9", "1.1.1.1", "8.8.8.8"])
110113
// (Quad9, Cloudflare, Google)
111-
// Cloudflare is usually the fastest for DNS queries.
114+
// Note: Cloudflare is typically the fastest for DNS queries.
112115
```
113-
If you never changed the DNS settings of your computer, the default DNS server will be your ISP's.<br>
114-
<code style="color : darkorange">❗ I recommend changing your default DNS servers if you're doing thousands of lookups, such as for mass scanning.</code><br>
116+
117+
118+
<hr>
115119

116120
### Changelog
117121

118122
**[View Changelog](https://pinger.floppa.hair/changelog/)**,
119-
Latest version: <b><i><code>v1.2.1</code></i></b>
123+
Latest version: <b><i><code>v1.2.2</code></i></b>
120124

121125

122126

@@ -130,12 +134,12 @@ If you have some questions, you can message me through Discord - **woodendoors7*
130134

131135

132136
### To-do
133-
134137
- [x] Do SRV lookups
135138
- [ ] Parse MOTDs
136139
- [ ] Support versions less than 1.7.
137140
- [ ] Support Bedrock
138141

142+
(I plan to add these over summer!)
139143

140144
### License
141145

jsr.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@minecraft/minecraftstatuspinger",
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"exports": "./src/index.ts",
55
"compilerOptions": {
66
"strictNullChecks": false

package.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"CHANGELOG.md",
1010
"README.md"
1111
],
12-
"version": "1.2.1",
12+
"version": "1.2.2",
1313
"description": "A modern library for pinging Minecraft servers and getting their status and playerlist, written in TypeScript with zero dependencies.",
1414
"keywords": [
1515
"minecraft status",
@@ -23,24 +23,23 @@
2323
"bugs": {
2424
"url": "https://github.com/woodendoors7/MinecraftStatusPinger/issues"
2525
},
26-
"main": "./dist/index.js",
27-
"types": "./dist/index.d.ts",
26+
"main": "dist/cjs/index.js",
27+
"module": "dist/esm/index.js",
28+
"types": "dist/types/index.d.ts",
2829
"scripts": {
29-
"test": "cls && tsc && cd test && tsc --target ES2021 --strictNullChecks true --moduleResolution node test.ts && node test.js",
30-
"start": "node dist/index.js",
31-
"build": "tsc -p tsconfig.json",
32-
"dev": "ts-node-dev src/index.ts"
30+
"build:cjs": "tsc --module CommonJS --outDir ./dist/cjs",
31+
"build:esm": "tsc --module ESNext --outDir ./dist/esm",
32+
"build": "npm run build:cjs && npm run build:esm"
3333
},
3434
"engines": {
35-
"node": ">=16.0.0"
35+
"node": ">=14.0.0"
3636
},
3737
"license": "GPL-3.0-or-later",
38-
"type": "module",
3938
"devDependencies": {
4039
"@types/express": "^4.17.16",
4140
"@types/node": "^18.11.18",
4241
"@types/varint": "^6.0.1",
4342
"typedoc": "^0.23.25",
44-
"typescript": "^5.7.0-beta"
43+
"typescript": "^5.8.2"
4544
}
4645
}

src/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { promises as dns } from "node:dns";
1616
* port: 25565,
1717
* timeout: 10000,
1818
* ping: true,
19-
* protocolVersion: 767
19+
* protocolVersion: 769
2020
* throwOnParseError: false,
2121
* SRVLookup: true,
2222
* JSONParse: true
@@ -34,7 +34,7 @@ export async function lookup(options?: ServerStatusOptions): Promise<ServerStatu
3434

3535
let timeout = options.timeout != null ? options.timeout : 10000;
3636
let ping = options.ping != null ? options.ping : true;
37-
let protocolVersion = options.protocolVersion != null ? options.protocolVersion : 767;
37+
let protocolVersion = options.protocolVersion != null ? options.protocolVersion : 769;
3838
let throwOnParseError = options.throwOnParseError != null ? options.throwOnParseError : true;
3939
let SRVLookup = options.SRVLookup != null ? options.SRVLookup : true;
4040
let JSONParse = options.JSONParse != null ? options.JSONParse : true;
@@ -84,9 +84,10 @@ export async function lookup(options?: ServerStatusOptions): Promise<ServerStatu
8484
return resolve(serverStatus);
8585
}
8686

87+
8788
/*
88-
If the handshake and status request were sent out and replied to,
89-
generate the ping packet, log the time it was sent out on and send it.
89+
If the handshake and status request have been successfully completed,
90+
generate the ping packet, record the time it is sent, and then send it.
9091
*/
9192

9293
if (packet.status.handshakeBaked && !packet.status.pingSent) {
@@ -118,7 +119,7 @@ export async function lookup(options?: ServerStatusOptions): Promise<ServerStatu
118119
// Recommended servers
119120
mc.setDnsServers(["9.9.9.9", "1.1.1.1", "8.8.8.8"])
120121
// (Quad9, Cloudflare, Google)
121-
// Cloudflare is the fastest for DNS queries in most of the world.
122+
// Note: Cloudflare is typically the fastest for DNS queries.
122123
```
123124
*/
124125
export async function setDnsServers(serverArray: Array<string>): Promise<boolean> {
@@ -138,8 +139,8 @@ async function customLookup(hostname: string, options: DynamicObject, callback:
138139

139140
async function processSRV(hostname: string, port: number) {
140141
/*
141-
* Tries to get a SRV record from the provided hostname, unless disabled with the disableSRV flag.
142-
* The hostname can't be localhostname, the port always has to be 25565, and the hostname cannot be an IP.
142+
* Tries to get a SRV record from the provided hostname, unless disabled with the SRVLookup flag.
143+
* The hostname can't be a local one, the port has to always be 25565, and the hostname cannot be an IP.
143144
*/
144145

145146

src/packetDecoder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async function craftData(packet: Packet) {
4040
// This crafts the first and only data field. It slices off the meta fields.
4141
packet.fieldsBuffer = packet.dataBuffer.slice(packet.meta.metaLength)
4242
let fieldLength = varint.decode(packet.fieldsBuffer)
43-
packet.fieldsBuffer = packet.fieldsBuffer.slice(varint.encodingLength(fieldLength));
43+
packet.fieldsBuffer = packet.fieldsBuffer.slice(varint.encodingLength(fieldLength), fieldLength + varint.encodingLength(fieldLength));
4444
packet.crafted.data = new TextDecoder().decode(packet.fieldsBuffer);
4545
packet.status.handshakeBaked = true;
4646
return packet;

tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"compilerOptions": {
3-
"target": "es2021",
4-
"module": "ES2020",
3+
"target": "ES2020",
4+
"module": "ESNext",
55
"rootDir": "./src",
66
"moduleResolution": "node",
77
"declaration": true,
88
"declarationMap": true,
99
"sourceMap": true,
1010
"outDir": "./dist",
11+
"declarationDir":"./dist/types",
1112
"forceConsistentCasingInFileNames": true,
1213
"strict": true,
1314
"noImplicitAny": true,

0 commit comments

Comments
 (0)