Skip to content

Commit

Permalink
feat: Add valve requestRulesRequired & requestPlayersRequired (#458)
Browse files Browse the repository at this point in the history
* feat: add valve requestRulesRequired

* missing delete requestRulesRequired

* feat: add valve requestPlayersRequired

* update documentation

* update games list
  • Loading branch information
podrivo authored Jan 11, 2024
1 parent 184e9b1 commit 0b8ebc8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
7 changes: 5 additions & 2 deletions GAMES_LIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | |
Expand Down Expand Up @@ -440,11 +440,14 @@ 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
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.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 11 additions & 1 deletion bin/gamedig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
})

Expand All @@ -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)) {
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion protocols/dayz.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions protocols/valve.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -214,15 +214,15 @@ 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()
rules[key] = reader.string()
}
} 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)
Expand Down

0 comments on commit 0b8ebc8

Please sign in to comment.