https://github.com/maksimetny/minecraft-status
A observable-based Minecraft server status for Node.js
https://github.com/maksimetny/minecraft-status
minecraft ping protocol
Last synced: 6 months ago
JSON representation
A observable-based Minecraft server status for Node.js
- Host: GitHub
- URL: https://github.com/maksimetny/minecraft-status
- Owner: maksimetny
- License: mit
- Created: 2021-12-15T13:23:27.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-12-25T10:01:44.000Z (over 3 years ago)
- Last Synced: 2024-11-25T08:44:54.636Z (6 months ago)
- Topics: minecraft, ping, protocol
- Language: TypeScript
- Homepage:
- Size: 56.6 KB
- Stars: 2
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# minecraft-status
[](https://www.npmjs.com/package/node-minecraft-status)
[](LICENSE)A observable-based Minecraft server status for Node.js
## Features :dizzy:
1) Supports current and legacy Minecraft protocol
2) Resolves service (`SRV`) record
3) Auto-retry with other strategy on error## Installing :package:
`npm i node-minecraft-status`
## Usage :rocket:
### Sample
```typescript
import { PingContext } from 'node-minecraft-status';const client = new PingContext();
client.ping('hypixel.net')
.subscribe({
next(response) {
console.log(response);
},
error(err) {
console.error(err);
},
complete() {
console.log('pong!');
},
});
```### Ping Client
| Method | Description |
|---------------|-----------------------------------------------------------------------------------------|
| `ping` | Get server information via ping protocol. |
| `setStrategy` | Set the way to create the handshake package and parse the server response. |
| `setTimeout` | Set socket timeout. |#### ping
| Parameter | Type | Description | Required |
|-----------|----------|---------------------------------------------------------------------|----------|
| `address` | String | The server hostname or server hostname with port (`[host]:[port]`). | Yes |
| `port` | Number | The server port (defaults: `25565`). | |#### setStrategy
| Parameter | Type | Description | Required |
|------------|--------|---------------------------|----------|
| `strategy` | Object | The instance of strategy. | Yes |#### setTimeout
| Parameter | Type | Description | Required |
|------------|----------|---------------------|----------|
| `timeout` | Number | The socket timeout. | Yes |### Ping Response
```typescript
{
host: string, // resolved hostname
port: number, // resolved port
ip?: string, // when received domain name
version?: {
name: string,
protocol: string,
}, // only 1.6+
players: {
max: number,
online: number,
sample?: {
id: string,
name: string,
}, // only 1.6+
},
description: string, // string if < 1.6, if 1.6 < an object like chat (see: https://wiki.vg/Chat)
favicon?: string, // only 1.6+
}
```## TODO :memo:
- [x] ping
- [x] support legacy versions (< 1.6)
- [x] resolving srv records
- [ ] server latency
- [ ] formatting response
- [ ] query## License :page_with_curl:
The MIT License. See [LICENSE](LICENSE) file.