From 0b8ebc871f8986a61ad0ea43190a98ecc5e68d83 Mon Sep 17 00:00:00 2001 From: Pedro Ivo Hudson Date: Thu, 11 Jan 2024 17:58:50 -0300 Subject: [PATCH] feat: Add valve requestRulesRequired & requestPlayersRequired (#458) * feat: add valve requestRulesRequired * missing delete requestRulesRequired * feat: add valve requestPlayersRequired * update documentation * update games list --- GAMES_LIST.md | 7 +++++-- README.md | 2 ++ bin/gamedig.js | 12 +++++++++++- protocols/dayz.js | 2 +- protocols/valve.js | 6 +++--- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/GAMES_LIST.md b/GAMES_LIST.md index 1fae86a..510aad7 100644 --- a/GAMES_LIST.md +++ b/GAMES_LIST.md @@ -87,7 +87,7 @@ | daikatana | Daikatana | | | dal | Dark and Light | [Valve Protocol](#valve) | | dayofdragons | Day of Dragons | [Valve Protocol](#valve) | -| dayz | DayZ | | +| dayz | DayZ | [Valve Protocol](#valve) | | dayzmod | DayZ Mod | [Valve Protocol](#valve) | | ddd | Dino D-Day | [Valve Protocol](#valve) | | ddpt | Deadly Dozen: Pacific Theater | | @@ -440,7 +440,7 @@ additional option: `token` Valheim servers will only respond to queries if they are started in public mode (`-public 1`). ### DayZ -DayZ stores some of it's servers information inside the `tags` attribute. Make sure to set `requestRules: true` to access it. Some data inside `dayzMods` attribute may be fuzzy, due to how mods are loaded into the servers. Alternatively, some servers may have a [third party tool](https://dayzsalauncher.com/#/tools) that you can use to get the mods information. If it's installed, you can access it via browser with the game servers IP:PORT, but add up 10 to the port. (eg. if game port is 2302 then use 2312). +DayZ stores some of it's servers information inside the `tags` attribute. Make sure to set `requestRules: true` to access it. Some data inside `dayzMods` attribute may be fuzzy, due to how mods are loaded into the servers. Players can be fetched, but will not show ingame names. Alternatively, some servers may have a [third party tool](https://dayzsalauncher.com/#/tools) that you can use to get the mods information. If it's installed, you can access it via browser with the game servers IP:PORT, but add up 10 to the port. (eg. if game port is 2302 then use 2312). ### Valve Protocol For many valve games, additional 'rules' may be fetched into the unstable `raw` field by passing the additional @@ -448,3 +448,6 @@ option: `requestRules: true`. Beware that this may increase query time. ### The Front Responses with wrong `name` (gives out a steamid instead of the server name) and `maxplayers` (always 200, whatever the config would be) field values. + +### Conan Exiles +Conan Exiles never responds to player query. diff --git a/README.md b/README.md index 9c59806..24fea4d 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,8 @@ These fields are all optional. * **ipFamily**: number - IP family/version returned when looking up hostnames via DNS, can be 0 (IPv4 and IPv6), 4 (IPv4 only) or 6 (IPv6 only). (default 0) * **debug**: boolean - Enables massive amounts of debug logging to stdout. (default false) * **requestRules**: boolean - Valve games only. Additional 'rules' may be fetched into the `raw` field. (default false) +* **requestRulesRequired**: boolean - Valve games only. `requestRules` is always required to have a response or the query will timeout. (default false) +* **requestPlayersRequired**: boolean - 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. (default false) ## Return Value diff --git a/bin/gamedig.js b/bin/gamedig.js index 874d4bf..59bc801 100644 --- a/bin/gamedig.js +++ b/bin/gamedig.js @@ -6,7 +6,7 @@ import Minimist from 'minimist' import { GameDig } from './../lib/index.js' const argv = Minimist(process.argv.slice(2), { - boolean: ['pretty', 'debug', 'givenPortOnly', 'requestRules'], + boolean: ['pretty', 'debug', 'givenPortOnly', 'requestRules', 'requestRulesRequired', 'requestPlayersRequired'], string: ['guildId', 'listenUdpPort', 'ipFamily'] }) @@ -16,6 +16,10 @@ const pretty = !!argv.pretty || debug delete argv.pretty const givenPortOnly = argv.givenPortOnly delete argv.givenPortOnly +const requestRulesRequired = argv.requestRulesRequired +delete argv.requestRulesRequired +const requestPlayersRequired = argv.requestPlayersRequired +delete argv.requestPlayersRequired const options = {} for (const key of Object.keys(argv)) { @@ -40,6 +44,12 @@ if (debug) { if (givenPortOnly) { options.givenPortOnly = true } +if (requestRulesRequired) { + options.requestRulesRequired = true +} +if (requestPlayersRequired) { + options.requestPlayersRequired = true +} const printOnPretty = (object) => { if (pretty) { diff --git a/protocols/dayz.js b/protocols/dayz.js index a99ab2a..ce98f8a 100644 --- a/protocols/dayz.js +++ b/protocols/dayz.js @@ -25,7 +25,7 @@ export default class dayz extends valve { this.logger.debug('Requesting rules ...') const b = await this.sendPacket(0x56, null, 0x45, true) - if (b === null) return // timed out - the server probably has rules disabled + if (b === null && !this.options.requestRulesRequired) return // timed out - the server probably has rules disabled let dayZPayloadEnded = false diff --git a/protocols/valve.js b/protocols/valve.js index 6866c25..6c0fa04 100644 --- a/protocols/valve.js +++ b/protocols/valve.js @@ -170,7 +170,7 @@ export default class valve extends Core { true ) - if (b === null) { + if (b === null && !this.options.requestPlayersRequired) { // Player query timed out // CSGO doesn't respond to player query if host_players_show is not 2 // Conan Exiles never responds to player query @@ -214,7 +214,7 @@ export default class valve extends Core { if (this.goldsrcInfo) { const b = await this.udpSend('\xff\xff\xff\xffrules', b => b, () => null) - if (b === null) return // timed out - the server probably has rules disabled + if (b === null && !this.options.requestRulesRequired) return // timed out - the server probably has rules disabled const reader = this.reader(b) while (!reader.done()) { const key = reader.string() @@ -222,7 +222,7 @@ export default class valve extends Core { } } else { const b = await this.sendPacket(0x56, null, 0x45, true) - if (b === null) return // timed out - the server probably has rules disabled + if (b === null && !this.options.requestRulesRequired) return // timed out - the server probably has rules disabled const reader = this.reader(b) const num = reader.uint(2)