feat: add query port to the results (#476)

This commit is contained in:
CosminPerRam 2024-01-17 00:20:56 +02:00 committed by GitHub
parent 2ffff5e7d6
commit ec708d7219
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 5 additions and 0 deletions

View File

@ -29,6 +29,7 @@
* Minimum Supported Deno Version: `1.39.2`.
* `deno run --allow-net bin/gamedig.js --type tf2 127.0.0.1`
* Added code examples.
* New stable field: `queryPort` - this number indicates what was the port that the query was done on, 0 indicates none if not applicable.
* New option: `stripColors` (defaults to `true`) for protocols that strips colors: unreal2, savage2, quake3, nadeo, gamespy2, doom3, armagetron.
* New option: `requestRulesRequired` (defaults to `false`) Valve games only. `requestRules` is always required to have a response or the query will timeout.
* New option: `requestPlayersRequired` (defaults to `false`) Valve games only. Querying players is always required to have a response or the query will timeout. Some [games](GAMES_LIST.md) may not provide a players response.

View File

@ -68,6 +68,7 @@ The returned state object will contain the following keys:
| **bots** | array of objects | Same schema as `players`. |
| **connect** | string | This will typically include the game's `IP:PORT`. The port will reflect the server's game port, even if your request specified the game's query port in the request. For some games, this may be a server ID or connection URL if an IP:PORT is not appropriate for end-users. |
| **ping** | number | Round trip time to the server (in milliseconds). Note that this is not the RTT of an ICMP echo, as ICMP packets are often blocked by NATs and node has poor support for raw sockets. This value is derived from the RTT of one of the query packets, which is usually quite accurate, but may add a bit due to server lag. |
| **queryPort** | number | Indicates on which port the query was done on, 0 if this is not applicable. |
| **raw** | object | Contains all information received from the server in a disorganized format. |
Note that `raw` (or **unstable**) objects contents MAY change on a per-protocol basis between GameDig patch releases (although not typical).

View File

@ -29,4 +29,6 @@ export class Results {
maxplayers = 0
players = new Players()
bots = new Players()
queryPort = 0
}

View File

@ -78,6 +78,7 @@ export default class Core extends EventEmitter {
const state = new Results()
await this.run(state)
state.queryPort = options.port
// because lots of servers prefix with spaces to try to appear first
state.name = (state.name || '').trim()