feat: Add valve requestRulesRequired & requestPlayersRequired (#458)

* feat: add valve requestRulesRequired

* missing delete requestRulesRequired

* feat: add valve requestPlayersRequired

* update documentation

* update games list
This commit is contained in:
Pedro Ivo Hudson 2024-01-11 17:58:50 -03:00 committed by GitHub
parent 184e9b170c
commit 0b8ebc871f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 7 deletions

View file

@ -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).
### <a name="valve"></a>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.
### <a name="thefront"></a>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.

View file

@ -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

View file

@ -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) {

View file

@ -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

View file

@ -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)