|
1 | | -# minestat-es |
| 1 | +# git-clone-sparse |
2 | 2 |
|
3 | | -[](https://www.npmjs.com/package/minestat-es) |
4 | | -[](https://codecov.io/gh/ayan4m1/minestat-es) |
| 3 | +[](https://www.npmjs.com/package/git-clone-sparse) |
5 | 4 |
|
6 | 5 | ## features |
7 | 6 |
|
8 | 7 | - Written in TypeScript |
9 | | -- Less than 5kB of code |
10 | | -- No runtime dependencies |
11 | | -- Supports ESM and CommonJS |
12 | | -- Comprehensive unit tests |
| 8 | +- Small footprint |
13 | 9 |
|
14 | 10 | ## requirements |
15 | 11 |
|
16 | | -- Node 16+ |
| 12 | +- Node 18+ |
17 | 13 |
|
18 | 14 | ## usage |
19 | 15 |
|
20 | | -### by address/port |
21 | | - |
22 | | -To query a Minecraft server using an IP/hostname and a port, use: |
23 | | - |
24 | | -```ts |
25 | | -fetchServerInfo({ |
26 | | - address: '1.2.3.4', |
27 | | - port: 25565, |
28 | | - timeout: 1000 |
29 | | -}); |
30 | | -``` |
31 | | - |
32 | | -### by hostname |
33 | | - |
34 | | -To perform an SRV record lookup and query a Minecraft server using only a hostname, use: |
35 | | - |
36 | | -```ts |
37 | | -fetchServerInfo({ |
38 | | - hostname: 'example.com', |
39 | | - timeout: 1000 |
40 | | -}); |
41 | | -``` |
42 | | - |
43 | | -Regardless of which way it was invoked, `fetchServerInfo` returns a promise which will resolve with an object containing the following properties: |
44 | | - |
45 | | -| Key | Type | Description | |
46 | | -| ------ | --------- | ----------------------------------- | |
47 | | -| online | `boolean` | Whether the server is online or not | |
48 | | - |
49 | | -If the server is offline, the object will also contain the properties: |
50 | | - |
51 | | -| Key | Type | Description | |
52 | | -| ----- | ------- | ----------------------------------------------------- | |
53 | | -| error | `Error` | A communications or validation error, if one occurred | |
54 | | - |
55 | | -If the server is online, the object will also contain the following properties: |
56 | | - |
57 | | -| Key | Type | Description | |
58 | | -| ---------- | -------- | ------------------------------------------------- | |
59 | | -| version | `string` | The server's version string | |
60 | | -| motd | `string` | The server's Message of the Day | |
61 | | -| players | `number` | The number of players on the server | |
62 | | -| maxPlayers | `number` | The maximum number of players the server supports | |
63 | | - |
64 | | -`fetchServerInfo` rejects if an error occurs during SRV record resolution. |
65 | | - |
66 | | -## example |
67 | | - |
68 | | -```ts |
69 | | -import { fetchServerInfo } from 'minestat-es'; |
70 | | - |
71 | | -(async () => { |
72 | | - try { |
73 | | - // query by hostname (SRV lookup) |
74 | | - const { online, error, players } = await fetchServerInfo({ |
75 | | - hostname: 'mc.example.com' |
76 | | - }); |
77 | | - |
78 | | - // OR |
79 | | - |
80 | | - // query by address/port |
81 | | - const { online, error, players } = await fetchServerInfo({ |
82 | | - address: 'example.com', // could also be an IP address |
83 | | - port: 25565 |
84 | | - }); |
85 | | - |
86 | | - // interpret the results |
87 | | - console.log(`Server is ${online ? 'Online' : 'Offline'}`); |
88 | | - if (online) { |
89 | | - console.log(`There are ${players} player(s) online.`); |
90 | | - } else if (error) { |
91 | | - // either the SRV record failed to resolve, a socket error occurred, |
92 | | - // or the response from the server was invalid |
93 | | - console.error(error); |
94 | | - } |
95 | | - } catch (error) { |
96 | | - // an unexpected error occurred |
97 | | - console.error(error); |
98 | | - } |
99 | | -})(); |
100 | | -``` |
| 16 | +**TODO** |
0 commit comments