No description
Find a file
CosminPerRam 310b62664c
feat: http client and eco support (#175)
* feat: initial http and eco support

* http: Replace reqwest with ureq and add HTTPS support

ureq markets itself as a lightweight blocking HTTP client which might be
a good choice for rust-gamedig at the moment. However the main reason
for changing to ureq is that it allows setting a "resolver" function
which overrides the IP address to connect to. This is useful because it
allows us to pass a URL with the desired hostname without the HTTP
library doing an extra DNS lookup (this allows HTTPS to work when we
specify the exact IP and port to connect to external to the URL).

Other changes in this commit are:
- Feature gated things that depend on serde: this means that the eco
  game won't be available if the library is compiled without serde
- Added the TLS feature to enable TLS support in the HTTP library
- Added HTTPSettings to set the protocol (HTTP/HTTPS) and the hostname
- Setting a user-agent string on HTTP requests (allows the server to see
  what program is being used to query them)
- Store the address as a parsed Url so we don't re-parse it on every
  request
- Add a method to POST JSON data and parse response
- Renamed the request() method to get_json() in anticipation of a future
  method that will send a GET request and handle the raw bytes instead
  of using serde
- Improved documentation

* eco: Add generic impls

* eco: fixes

* http: Add headers to HttpSettings and rename from HTTPSettings

* eco: Add extra request settings

* http: Add support for querying raw bytes

* http: Add unit-tests

* http: Rename HttpProtocol

* crate: Make serde dependency non-optional

The serde feature now only enable serde derivations for our types that
don't need it for the library to function.

* http: Add helper for creating HttpClients to query APIs

Adds the from_url helper that should make working with master server web
APIs easier.

* Add/Update badge

* crate: Require games feature for eco example

* docs: Update changelog

---------

Co-authored-by: Douile <douile@douile.com>
2024-02-10 18:26:49 +00:00
.github feat: Add packet capture functionality and many more CLI improvements (#182) 2024-02-07 22:31:31 +00:00
crates feat: http client and eco support (#175) 2024-02-10 18:26:49 +00:00
.actrc [CI] Improvement and fixes (#161) 2023-11-25 00:34:26 +02:00
.gitignore [Crate] Add formatting (#22) 2023-03-14 10:31:37 +02:00
.pre-commit-config.yaml fix: various crate/clippy/ci changes (#181) 2024-01-18 15:34:05 +02:00
.rustfmt.toml [Crate] Bump rustfmt version to 1.6.0 (#69) 2023-07-10 18:32:17 +03:00
Cargo.toml Merge branch 'main' into feat/rootless-capture 2024-01-18 01:56:14 +00:00
CHANGELOG.md feat: http client and eco support (#175) 2024-02-10 18:26:49 +00:00
CONTRIBUTING.md docs: Add info about commits to CONTRIBUTING (#157) 2023-11-22 13:48:01 +02:00
GAMES.md feat(games): add zombie panic: source support 2024-01-11 01:48:05 +02:00
LICENSE.md Update license (#179) 2024-02-02 10:39:02 +02:00
PROTOCOLS.md fix: add jc2m in protocols.md 2023-12-10 19:43:32 +02:00
README.md fix: readme examples folder returning not found since monorepo merge 2023-12-10 23:32:12 +02:00
RESPONSES.md feat: add savage 2 support (#169) 2023-12-10 19:39:26 +02:00
SERVICES.md [Service] Add valve master server query service (#34) 2023-04-28 18:00:04 +03:00
VERSIONS.md [Crate] Add rich error type (#80) 2023-08-05 12:36:48 +03:00

rust-GameDig

The fast library for querying game servers/services.
This library brings what node-GameDig does (and not only), to pure Rust!

Warning: This project goes through frequent API breaking changes and hasn't been thoroughly tested.

Community

Checkout the GameDig Community Discord Server here.
Note that it isn't be a replacement for GitHub issues, if you have found a problem within the library or want to request a feature, it's better to do so here rather than on Discord.

Usage

Minimum Supported Rust Version is 1.65.0 and the code is cross-platform.

Pick a game/service/protocol (check the GAMES, SERVICES and PROTOCOLS files to see the currently supported ones), provide the ip and the port (be aware that some game servers use a separate port for the info queries, the port can also be optional if the server is running the default ports) then query on it.

Team Fortress 2 query example:

use gamedig::games::teamfortress2;

fn main() {
    let response = teamfortress2::query(&"127.0.0.1".parse().unwrap(), None); 
        // None is the default port (which is 27015), could also be Some(27015)
    
    match response { // Result type, must check what it is...
        Err(error) => println!("Couldn't query, error: {}", error),
        Ok(r) => println!("{:#?}", r)
    }
}

Response (note that some games have a different structure):

{
  protocol: 17,
  name: "Team Fortress 2 Dedicated Server.",
  map: "ctf_turbine",
  game: "tf2",
  appid: 440,
  players_online: 0,
  players_details: [],
  players_maximum: 69,
  players_bots: 0,
  server_type: Dedicated,
  has_password: false,
  vac_secured: true,
  version: "7638371",
  port: Some(27015),
  steam_id: Some(69753253289735296),
  tv_port: None,
  tv_name: None,
  keywords: Some("alltalk,nocrits"),
  rules: [
    "mp_autoteambalance": "1",
    "mp_maxrounds": "5",
    //....
  ]
}

Want to see more examples? Checkout the examples folder.

Documentation

The documentation is available at docs.rs.
Curious about the history and what changed between versions? Everything is in the CHANGELOG file.

Contributing

If you want to see your favorite game/service being supported here, open an issue, and I'll prioritize it (or do a pull request if you want to implement it yourself)!

Before contributing please read CONTRIBUTING.