From 217ac2b4e8681dc8fd6cc6d5349a8592021bdc5b Mon Sep 17 00:00:00 2001 From: Grayson-code Date: Wed, 16 Feb 2022 20:45:02 +0530 Subject: [PATCH 1/8] type definitions --- lib/index.d.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ new/test.ts | 14 ++++++++++++++ package.json | 3 ++- 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 lib/index.d.ts create mode 100644 new/test.ts diff --git a/lib/index.d.ts b/lib/index.d.ts new file mode 100644 index 0000000..0dcf728 --- /dev/null +++ b/lib/index.d.ts @@ -0,0 +1,42 @@ +declare module 'minecraft-pinger' + +export interface pingPromiseInterface { + description: { + text: string; + extra?: { + color?: string; + text: string; + bold?: boolean; + strikethrough?: boolean; + extra?: { + color: string; + text: string; + }[]; + }[]; + }; + players: { + online: number; + max: number; + sample?: {name: string; id: string}[]; + }; + version: {name: string; protocol: number}; + ping: number; + modinfo?: {type: string; modList: string[]}; + favicon?: string; +} + + +/** + * 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 + */ +export declare function pingPromise(hostname:string,port:number): Promise; +/** + * + * @param { string } hostname The host name of the server + * @param { number } port Port of the server most servers default to 25565 + * @returns { pingPromiseInterface } The information of the server + */ +export declare function ping(hostname:string, port:number ,params:(error:Error, result:pingPromiseInterface) => void) \ No newline at end of file diff --git a/new/test.ts b/new/test.ts new file mode 100644 index 0000000..a15f45c --- /dev/null +++ b/new/test.ts @@ -0,0 +1,14 @@ +// Copyright 2022 Northern Star +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + 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" } From 05221c9dddd7e46e582683646948e60f563cc0cb Mon Sep 17 00:00:00 2001 From: Grayson-code Date: Wed, 16 Feb 2022 20:45:52 +0530 Subject: [PATCH 2/8] Type definitions --- new/test.ts | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 new/test.ts diff --git a/new/test.ts b/new/test.ts deleted file mode 100644 index a15f45c..0000000 --- a/new/test.ts +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2022 Northern Star -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - From 7b52a8bba7ef9a7ba19d675e0bf71e6029afbdde Mon Sep 17 00:00:00 2001 From: Grayson-code Date: Wed, 16 Feb 2022 21:02:36 +0530 Subject: [PATCH 3/8] fix bugs --- lib/index.d.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/index.d.ts b/lib/index.d.ts index 0dcf728..c814f3e 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -11,8 +11,8 @@ export interface pingPromiseInterface { extra?: { color: string; text: string; - }[]; - }[]; + }; + }; }; players: { online: number; @@ -35,8 +35,8 @@ export interface pingPromiseInterface { export declare function pingPromise(hostname:string,port:number): Promise; /** * - * @param { string } hostname The host name of the server - * @param { number } port Port of the server most servers default to 25565 - * @returns { pingPromiseInterface } The information of the server + * @param {string} hostname The host name of the server + * @param {number} port Port of the server most servers default to 25565 + * @returns {pingPromiseInterface} The information of the server */ export declare function ping(hostname:string, port:number ,params:(error:Error, result:pingPromiseInterface) => void) \ No newline at end of file From 3282eb5c0945e778648b24ecf2897ab22573a518 Mon Sep 17 00:00:00 2001 From: Grayson-code Date: Wed, 16 Feb 2022 21:08:27 +0530 Subject: [PATCH 4/8] commit --- lib/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.d.ts b/lib/index.d.ts index c814f3e..035fa94 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -39,4 +39,4 @@ export declare function pingPromise(hostname:string,port:number): Promise void) \ No newline at end of file +export declare function ping(hostname:string, port:number ,params:(error:Error, result:pingPromiseInterface) => null) \ No newline at end of file From 975845e1b7a67024aab53adf7074f95cdb59cbc7 Mon Sep 17 00:00:00 2001 From: Grayson-code Date: Wed, 16 Feb 2022 21:26:26 +0530 Subject: [PATCH 5/8] jsdoc --- lib/index.d.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/index.d.ts b/lib/index.d.ts index 035fa94..1c5c895 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -27,16 +27,18 @@ export interface pingPromiseInterface { /** - * Returns basic info about the server + * 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(hostname:string,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 {pingPromiseInterface} The information of the server + * @returns {Promise} The information of the server */ -export declare function ping(hostname:string, port:number ,params:(error:Error, result:pingPromiseInterface) => null) \ No newline at end of file +export declare function ping(hostname:string, port:number ,params?:(error?:Error, result?:pingPromiseInterface) => null):pingPromiseInterface \ No newline at end of file From 2c7e7f9fc71da0b556297768dc36bd0946055bd1 Mon Sep 17 00:00:00 2001 From: Grayson-code Date: Wed, 16 Feb 2022 21:29:56 +0530 Subject: [PATCH 6/8] removing unwanted stuff --- lib/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/index.d.ts b/lib/index.d.ts index 1c5c895..dbff565 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -31,7 +31,7 @@ export interface pingPromiseInterface { * * @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 + * @returns The information of the server */ export declare function pingPromise(hostname:string,port:number): Promise; /** @@ -39,6 +39,6 @@ export declare function pingPromise(hostname:string,port:number): Promise} The information of the server + * @returns The information of the server */ export declare function ping(hostname:string, port:number ,params?:(error?:Error, result?:pingPromiseInterface) => null):pingPromiseInterface \ No newline at end of file From f3e9e9ed6ddc81275e943c061052a01175cd794d Mon Sep 17 00:00:00 2001 From: Grayson-code Date: Thu, 24 Feb 2022 17:35:01 +0530 Subject: [PATCH 7/8] Final test Repo Closed --- lib/index.d.ts | 69 +++++++++++++++++++++++++++++++++++++------------- lib/index.js | 20 ++++++++++++--- 2 files changed, 67 insertions(+), 22 deletions(-) diff --git a/lib/index.d.ts b/lib/index.d.ts index dbff565..9e7f809 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -1,27 +1,44 @@ declare module 'minecraft-pinger' export interface pingPromiseInterface { - description: { - text: string; - extra?: { - color?: string; - text: string; - bold?: boolean; - strikethrough?: boolean; - extra?: { - color: string; - text: string; - }; - }; - }; players: { + /** + * Current Number of players online + */ online: number; + /** + * Maximum Number of players that could be online + */ max: number; - sample?: {name: string; id: string}[]; }; - version: {name: string; protocol: number}; + version: { + /** + * Server Software & Version Supports + */ + name: string; + /** + * Protocol Version + */ + protocol: number}; + /** + * RoundTrip Latency in milliseconds + */ ping: number; - modinfo?: {type: string; modList: string[]}; + /** + * 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; } @@ -33,7 +50,15 @@ export interface pingPromiseInterface { * @param {number} port Port of the server most servers default to 25565 * @returns The information of the server */ -export declare function pingPromise(hostname:string,port:number): Promise; +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 * @@ -41,4 +66,12 @@ export declare function pingPromise(hostname:string,port:number): Promise null):pingPromiseInterface \ No newline at end of file +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) { From af774793734f9cc1d2d621affb2a56cfcf10fd3e Mon Sep 17 00:00:00 2001 From: Grayson-code Date: Thu, 24 Feb 2022 17:42:57 +0530 Subject: [PATCH 8/8] FInalize --- lib/index.d.ts | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/index.d.ts b/lib/index.d.ts index 9e7f809..cde0716 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -1,6 +1,44 @@ 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 @@ -48,7 +86,7 @@ export interface pingPromiseInterface { * * @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 + * @returns {Promise} The information of the server */ export declare function pingPromise( /**