Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: output gamedig options in a "dry-run" and add protocol and type to output #644

Open
dgibbs64 opened this issue Sep 20, 2024 · 1 comment

Comments

@dgibbs64
Copy link
Contributor

What is this feature about?
I have an issue whereby I would like to query a master server such as Steam or 333networks. However, I only want to query if using the relevant protocol.

I query the master servers to try and identify the query port first to cut down on query guesses (relates this this request #484). I noticed that --debug outputs all the gamedig options for the query before running it. Part of it outputs procotol: valve which is exactly the info I need.

Would it be possible to add a feature that simply outputs to json the gamedig options without running a query? Almost like a dry-run. This way I could check gamedig to confirm the protocol, then query the master server if valve, or gamespy , and finally do an actual query with the query port gathered from the master server.

This will create a lot of flexibility as currently, I would have to manually list all GameSpy games in an if statement to prevent non-gamespy servers from checking 333networks.

Finally it would also be good to add the protocol and type to the query output as I would like to display the protocol type used for users to see.

Thank you

@CosminPerRam
Copy link
Member

CosminPerRam commented Jan 20, 2025

The library exports publicly the games definitions, one could do their own wrapper around this:
A CLI that takes one argument, a game name, then looks into this object and if it is present output it into the console:

import { games } from '../lib/index.js' // this would be 'gamedig'
import process from 'node:process'

const relevantArgs = process.argv.slice(2) // skip 'node options_script.js'
const gameName = relevantArgs[0] // get out game name arg

if (!gameName) {
  console.error('No game name provided.')
  process.exit(1)
}

const gameOptions = games[gameName]
if (!gameOptions) {
  console.error('Game name not found.')
  process.exit(1)
}

const asJson = JSON.stringify(gameOptions)
console.log(asJson)

Example usage:

PS D:\GitHub\node-gamedig> node .\tools\lookup_options.js        
No game name provided.
PS D:\GitHub\node-gamedig> node .\tools\lookup_options.js non_exitent_game
Game name not found.
PS D:\GitHub\node-gamedig> node .\tools\lookup_options.js teamfortress2   
{"name":"Team Fortress 2","release_year":2007,"options":{"port":27015,"protocol":"valve"},"extra":{"old_id":"tf2"}}

This method is limited to the game-defined entry (which as far as I understand this is what you need).
When you run a query there are other default values, they cannot be accesed at this time (but are documented in the readme).

But nevertheless, I do think this might come in handy, will look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants