13 Commits

Author SHA1 Message Date
371fb9daa7
feat: skip SRV lookup for IP addresses and localhost
Performing DNS SRV lookups for hosts that are already direct IP
addresses or special-case hostnames like 'localhost' is
unnecessary.

In addition, several related test suite improvements
have been included:

- A bug in the Bedrock mock packet creation was fixed where the magic
  GUID was being written to an incorrect buffer offset.
- The DNS mocking strategy in the Java tests has been refactored for
  better accuracy by mocking the `dns.promises.Resolver` class.
- An error test for the Bedrock pinger was corrected to properly
  handle a promise rejection instead of a synchronous throw.
2025-06-25 01:46:53 +03:00
23299a9a07
fix: add timeout to SRV record lookup
The `dns.promises.resolveSrv` function used for SRV record lookups
does not have a user-configurable timeout. This could cause the entire
`pingJava` operation to hang for an extended period if the target's
DNS server unresponsive.

To make the SRV lookup more robust and respect the user-provided
timeout, this commit switches to using the `dns.promises.Resolver`
class.
2025-06-25 01:09:07 +03:00
a1b999ca4e
refactor: introduce typescript for static type checking
We use JSDoc for documentation, but these annotations
were not being validated. This meant that type information
could become outdated or incorrect without any warning.

This commit introduces the TypeScript compiler (`tsc`) as a static
analysis tool to leverage our existing JSDoc comments.

To support this, JSDoc annotations across the codebase have been
improved for accuracy. Additionally, the `varint` module now uses a
custom `VarIntError` class for better type inference and error handling.
A new `typecheck` script has been added to `package.json` to run this
validation.
2025-06-19 03:55:24 +03:00
7322034aba
feat: add debug logging
Add debug logs using the `debug` library.

To use this new feature, set the `DEBUG` environment variable:
- `DEBUG=mineping:*` enables all logs from this library.
- `DEBUG=mineping:java` enables logs for the Java module only.
- `DEBUG=mineping:bedrock` enables logs for the Bedrock module only.
2025-06-19 02:14:04 +03:00
c7b99cb6db
feat: implement SRV record lookup and improve ping logic
Add support for DNS SRV record lookups (`_minecraft._tcp`) to
automatically resolve the correct server host and port, falling back
to the provided address if no record is found. This makes server
discovery compliant with standard Minecraft client behavior.

The Java ping implementation has been refactored:
- The `varint` module is rewritten to throw specific error codes and
  its `decodeVarInt` function now returns bytes read, which simplifies
  parsing logic.
- The core ping logic is now promise-based and modular, breaking out
  packet creation and response processing into helper functions.
- The TCP stream handler now robustly processes chunked data by
  catching recoverable decoder errors and waiting for more data,
  preventing crashes on incomplete packets.
- Error handling is improved.
2025-06-19 01:45:27 +03:00
ef2bebe755
fix: only perform cleanup and fire the callback on the first error 2025-06-15 02:56:07 +03:00
envizar
73a2fffe8b
feat: add virtualHost option (#6) 2025-02-07 08:01:12 +03:00
9469564736
docs: update references to wiki.vg
wiki.vg has been shut down and is in the process of being merged into minecraft.wiki
2024-12-28 22:47:11 +03:00
502029869a
style: use "node:" prefix for imports 2024-10-09 21:59:16 +03:00
Egornya
354fa212a6
fix(javaPing): default protocolVersion value 2023-12-08 16:16:30 +04:00
Egornya
d9bf4cfb3f feat(pingJava): add protocolVersion
feat(types): `PingOptions` for Java

fix(types): type names

fix(types): type names
2023-12-08 16:04:35 +04:00
910184bf5f
refactoring and comments
fix(cli.js): refactor help and error handling logic for better readability and maintainability
feat(cli.js): add support for custom port and timeout options
fix(parallel.js): update list of hosts to ping
fix(bedrock.js): add comments and improve error handling in ping function
fix(java.js): add comments and improve error handling in ping function
fix(varint.js): add comments to functions and improve readability
fix(index.d.ts): export all functions from java.js and bedrock.js
fix(lib/bedrock.d.ts): update source link
fix(lib/java.d.ts): update source link
2023-10-22 21:32:00 +03:00
e9cd348935
initial commit 2022-01-10 23:21:47 +03:00