diff --git a/lib/index.d.ts b/lib/index.d.ts new file mode 100644 index 0000000..cde0716 --- /dev/null +++ b/lib/index.d.ts @@ -0,0 +1,115 @@ +declare module 'minecraft-pinger' + +export interface pingPromiseInterface { + /** + * Server Description , May not exist + */ + description?: { + /** + * Raw Text + */ + text: string; + extra?: { + /** + * Color of the text + */ + color?: string; + /** + * Raw Text + */ + text: string; + /** + * If Text is bold + */ + bold?: boolean; + /** + * If Text is strikethroughed + */ + strikethrough?: boolean; + + extra?: { + /** + * Color + */ + color: string; + /** + * Raw Text + */ + text: string; + } + }; + }; + players: { + /** + * Current Number of players online + */ + online: number; + /** + * Maximum Number of players that could be online + */ + max: number; + }; + version: { + /** + * Server Software & Version Supports + */ + name: string; + /** + * Protocol Version + */ + protocol: number}; + /** + * RoundTrip Latency in milliseconds + */ + ping: number; + /** + * Moderator Info + */ + modinfo?: { + /** + * Mod list type + */ + type: string; + /** + * Moderator List May not exist + */ + modList: string[]}; + /** + * Server Favicon , Can be more than 1000 Characters + */ + favicon?: string; +} + + +/** + * Returns basic info about the server, asynchronously + * + * @param {string} hostname The host name of the server + * @param {number} port Port of the server most servers default to 25565 + * @returns {Promise} The information of the server + */ +export declare function pingPromise( + /** + * The Host Name + */ + hostname:string, + /** + * The Port of the server , most servers default to 25565 + */ + port:number): Promise; +/** + * Returns basic info about the server + * + * @param {string} hostname The host name of the server + * @param {number} port Port of the server most servers default to 25565 + * @returns The information of the server + */ +export declare function ping( + /** + * The Host Name + */ + hostname:string, + /** + * The Port of the server , most servers default to 25565 + */ + port:number):pingPromiseInterface \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index 84011fa..fd36724 100644 --- a/lib/index.js +++ b/lib/index.js @@ -49,11 +49,15 @@ function openConnection (address) { return new Promise((resolve, reject) => { let connection = net.createConnection(port, hostname, () => { - // Decode incoming packets + /** + * Decode incoming packets + */ let packetDecoder = new PacketDecoder() connection.pipe(packetDecoder) - // Write handshake packet + /** + * Write handshake packet + */ connection.write(createHandshakePacket(hostname, port)) packetDecoder.once('error', error => { @@ -89,14 +93,22 @@ function openConnection (address) { reject(new Error('Timed out')) }) - // Packet timeout (10 seconds) + /** + * Packet timeout (10 seconds) + */ let timeout = setTimeout(() => { connection.end() reject(new Error('Timed out (10 seconds passed)')) }, 10000) }) } - +/** + * + * @param {string} hostname Hostname of the website you want to check + * @returns Hostname & port + * + * Checks The Service Record Of the Hostname + */ function checkSrvRecord (hostname) { return new Promise((resolve, reject) => { if (net.isIP(hostname) !== 0) { diff --git a/package.json b/package.json index c4af753..f60d7a1 100644 --- a/package.json +++ b/package.json @@ -23,5 +23,6 @@ "dependencies": { "node-int64": "^0.4.0", "varint": "^4.0.1" - } + }, + "types": "lib/index.d.ts" }