hytale-server-status-query 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bruno Caitano
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Hytale Server Status Query
2
+
3
+ A library for querying Hytale server status using the QUIC protocol.
4
+
5
+ ## Overview
6
+
7
+ This library provides a simple and efficient way to check the status of Hytale game servers. It implements a QUIC client that can connect to Hytale servers and retrieve their online status and latency information.
8
+
9
+ ### Features
10
+
11
+ - ✅ QUIC protocol support
12
+ - ✅ Server status checking (online/offline)
13
+ - ✅ Ping measurement
14
+
15
+ ## Installation
16
+
17
+ Install the package using npm:
18
+
19
+ ```bash
20
+ npm install hytale-server-status-query
21
+ ```
22
+
23
+ ```bash
24
+ yarn add hytale-server-status-query
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ### Basic Usage
30
+
31
+ ```ts
32
+ import { HytaleQuicClient } from 'hytale-server-status-query';
33
+
34
+ const client = new HytaleQuicClient('your-server-address.com');
35
+
36
+ client.checkServerStatus()
37
+ .then(result => {
38
+ console.log('Server Status:', result);
39
+ })
40
+ .catch(error => {
41
+ console.error('Error:', error.message);
42
+ });
43
+ ```
44
+
45
+ ## License
46
+
47
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
48
+
49
+ ## Contributing
50
+
51
+ Contributions are welcome! Please feel free to submit a Pull Request.
52
+
53
+ ## Author
54
+
55
+ Made with ❤️ by the SnowDev
package/dist/index.js ADDED
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.HytaleQuicClient = void 0;
16
+ const dgram_1 = __importDefault(require("dgram"));
17
+ const crypto_1 = __importDefault(require("crypto"));
18
+ class HytaleQuicClient {
19
+ constructor(host, port = 5520, timeout = 5000) {
20
+ this.host = host;
21
+ this.port = port;
22
+ this.socket = null;
23
+ this.timeout = timeout;
24
+ }
25
+ createQuicInitialPacket() {
26
+ const buffer = Buffer.allocUnsafe(1200);
27
+ let offset = 0;
28
+ // Header Form (1 bit) = 1 (Long Header)
29
+ // Fixed Bit (1 bit) = 1
30
+ // Long Packet Type (2 bits) = 00 (Initial)
31
+ // Reserved Bits (2 bits) = 00
32
+ // Packet Number Length (2 bits) = 00 (1 byte)
33
+ const headerByte = 0b11000000; // 0xC0
34
+ buffer.writeUInt8(headerByte, offset++);
35
+ // Version (4 bytes) - QUIC v1 (RFC 9000)
36
+ buffer.writeUInt32BE(0x00000001, offset);
37
+ offset += 4;
38
+ // Destination Connection ID Length (1 byte)
39
+ const destConnIdLength = 8;
40
+ buffer.writeUInt8(destConnIdLength, offset++);
41
+ // Destination Connection ID (8 bytes - random)
42
+ const destConnId = crypto_1.default.randomBytes(8);
43
+ destConnId.copy(buffer, offset);
44
+ offset += destConnIdLength;
45
+ // Source Connection ID Length (1 byte)
46
+ const srcConnIdLength = 8;
47
+ buffer.writeUInt8(srcConnIdLength, offset++);
48
+ // Source Connection ID (8 bytes - random)
49
+ const srcConnId = crypto_1.default.randomBytes(8);
50
+ srcConnId.copy(buffer, offset);
51
+ offset += srcConnIdLength;
52
+ // Token Length (Variable Length Integer) - 0 para Initial sem token
53
+ buffer.writeUInt8(0, offset++);
54
+ // Length (Variable Length Integer)
55
+ // Tamanho do payload restante (simplificado)
56
+ const payloadLength = 100;
57
+ buffer.writeUInt16BE(0x4000 | payloadLength, offset); // 2-byte VarInt
58
+ offset += 2;
59
+ // Packet Number (1 byte)
60
+ buffer.writeUInt8(0, offset++);
61
+ // Payload - CRYPTO frame com ClientHello simplificado
62
+ // Frame Type: CRYPTO (0x06)
63
+ buffer.writeUInt8(0x06, offset++);
64
+ // Offset (VarInt) - 0
65
+ buffer.writeUInt8(0x00, offset++);
66
+ // Length (VarInt)
67
+ const cryptoDataLength = 50;
68
+ buffer.writeUInt8(cryptoDataLength, offset++);
69
+ // CRYPTO Data (TLS ClientHello simplificado)
70
+ // Este é um ClientHello mínimo para testar a conexão
71
+ const clientHello = Buffer.from([
72
+ 0x01,
73
+ 0x00, 0x00, 0x2e,
74
+ 0x03, 0x03,
75
+ // Random (32 bytes)
76
+ ...crypto_1.default.randomBytes(32),
77
+ 0x00,
78
+ 0x00, 0x02,
79
+ 0x13, 0x01,
80
+ 0x01,
81
+ 0x00, // Compression Method: none
82
+ ]);
83
+ clientHello.copy(buffer, offset, 0, Math.min(clientHello.length, cryptoDataLength));
84
+ offset += cryptoDataLength;
85
+ // Padding para atingir 1200 bytes mínimos
86
+ while (offset < 1200) {
87
+ buffer.writeUInt8(0, offset++);
88
+ }
89
+ return buffer.slice(0, 1200);
90
+ }
91
+ checkServerStatus() {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ return new Promise((resolve, reject) => {
94
+ const startTime = Date.now();
95
+ this.socket = dgram_1.default.createSocket('udp4');
96
+ const timeoutId = setTimeout(() => {
97
+ reject(new Error(`Timeout: Servidor não respondeu em ${this.timeout}ms`));
98
+ }, this.timeout);
99
+ this.socket.on('error', (err) => {
100
+ clearTimeout(timeoutId);
101
+ reject(new Error(`Erro na conexão: ${err.message}`));
102
+ });
103
+ this.socket.on('message', (msg, rinfo) => {
104
+ clearTimeout(timeoutId);
105
+ const ping = Date.now() - startTime;
106
+ resolve({
107
+ online: true,
108
+ ping: ping,
109
+ });
110
+ });
111
+ try {
112
+ const quicPacket = this.createQuicInitialPacket();
113
+ this.socket.send(quicPacket, 0, quicPacket.length, this.port, this.host, (err) => {
114
+ if (err) {
115
+ clearTimeout(timeoutId);
116
+ reject(new Error(`Erro ao enviar pacote: ${err.message}`));
117
+ }
118
+ });
119
+ }
120
+ catch (error) {
121
+ clearTimeout(timeoutId);
122
+ reject(new Error(`Erro ao criar pacote: ${error.message}`));
123
+ }
124
+ });
125
+ });
126
+ }
127
+ }
128
+ exports.HytaleQuicClient = HytaleQuicClient;
package/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ declare module "hytale-server-status-query" {
2
+ export interface ServerResponse {
3
+ online: boolean;
4
+ ping: number;
5
+ }
6
+
7
+ export class HytaleQuicClient {
8
+ constructor(host: string, port?: number, timeout?: number);
9
+
10
+ checkServerStatus(): Promise<ServerResponse>;
11
+ }
12
+ }
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "hytale-server-status-query",
3
+ "description": "Cliente QUIC para verificar status de servidores Hytale",
4
+ "version": "1.0.0",
5
+ "license": "MIT",
6
+ "main": "dist/index.js",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/SnowRunescape/hytale-server-status-query.git"
10
+ },
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "package-release": "npm run build && npm publish"
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "index.d.ts"
18
+ ],
19
+ "devDependencies": {
20
+ "@types/node": "^25.0.10",
21
+ "typescript": "^5.1.6"
22
+ },
23
+ "keywords": [
24
+ "hytale",
25
+ "server",
26
+ "status",
27
+ "query",
28
+ "quic"
29
+ ]
30
+ }