|
1 | | -# QueryServer |
| 1 | +# QueryServer (virion + plugin) |
2 | 2 |
|
3 | | -A lightweight PocketMine-MP plugin that queries Bedrock servers using the public `api.mcsrvstat.us` v3 endpoint with a UDP fallback (libpmquery). It includes a small API so other plugins can request queries asynchronously without blocking the main thread. |
| 3 | +Two deliverables in one repo: |
| 4 | +- **QueryServerCore (virion/library)**: async HTTP (api.mcsrvstat.us v3) + UDP fallback (libpmquery) with a tiny callback-based API for other plugins. |
| 5 | +- **QueryServer (plugin)**: thin wrapper exposing `/query` command that uses the core. |
4 | 6 |
|
5 | 7 | ## Features |
6 | | -- `/query <host[:port]> [port]` — fetch server status via HTTP; automatically falls back to UDP. |
7 | | -- Built-in UDP fallback uses an embedded, namespaced copy of **libpmquery**. |
8 | | -- Non-blocking: both HTTP and UDP queries run on async workers. |
9 | | -- Simple API for other plugins to trigger queries programmatically. |
| 8 | +- Async HTTP query (no main-thread blocking) with automatic UDP fallback. |
| 9 | +- Embedded, namespaced **libpmquery**. |
| 10 | +- Callback API for other plugins (no promises/futures needed). |
10 | 11 |
|
11 | | -## Installation |
12 | | -1. Drop the plugin phar into your `plugins/` folder. |
13 | | -2. Ensure `php` version matches PocketMine-MP 5.x (PHP 8.1+). |
14 | | - |
15 | | -## Command |
| 12 | +## Command (plugin) |
16 | 13 | - `/query <domain/ip[:port]> [port]` |
17 | 14 | Example: `/query test.pmmp.io 19132` |
18 | 15 |
|
19 | | -## API Usage (for other plugins) |
| 16 | +## API Usage (virion) |
20 | 17 | ```php |
21 | 18 | use NhanAZ\QueryServer\Main; |
22 | 19 |
|
23 | 20 | $api = Main::getInstance()->getApi(); |
24 | 21 | $api->query("test.pmmp.io", 19132, function(array $result): void { |
25 | 22 | if (($result['ok'] ?? false) === true) { |
26 | | - // $result['data'] contains either API status (object) or UDP fields (array) |
| 23 | + // $result['source'] === 'api' or 'udp' |
| 24 | + // $result['data'] : API status object (api) or UDP array (udp) |
27 | 25 | } else { |
28 | | - // handle $result['error'] |
| 26 | + // $result['error'] |
29 | 27 | } |
30 | 28 | }); |
31 | 29 | ``` |
32 | 30 |
|
| 31 | +## Installation |
| 32 | +### As plugin |
| 33 | +1. Download the `QueryServer` phar. |
| 34 | +2. Drop into `plugins/` (PocketMine-MP 5.x / PHP 8.1+). |
| 35 | + |
| 36 | +### As virion |
| 37 | +Add dependency in `.poggit.yml`: |
| 38 | +```yaml |
| 39 | +libs: |
| 40 | + - src: NhanAZ-Libraries/QueryServer/QueryServerCore |
| 41 | + version: ^0.0.3 |
| 42 | +``` |
| 43 | +
|
33 | 44 | ## License & Attribution |
34 | | -- This plugin is licensed under **LGPL-3.0-or-later**. |
35 | | -- Embedded library **libpmquery** (LGPL-3.0-or-later) by [jasonw4331/libpmquery](https://github.com/jasonw4331/libpmquery). |
| 45 | +- LGPL-3.0-or-later. |
| 46 | +- Bundled **libpmquery** (LGPL-3.0-or-later) by [jasonw4331/libpmquery](https://github.com/jasonw4331/libpmquery). |
0 commit comments