mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-18 09:35:50 +00:00
* 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>
64 lines
1.9 KiB
Rust
64 lines
1.9 KiB
Rust
//! Game Server Query Library.
|
|
//!
|
|
//! # Usage example:
|
|
//!
|
|
//! ## For a specific game
|
|
//! ```
|
|
//! use gamedig::games::teamfortress2;
|
|
//!
|
|
//! 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)
|
|
//! }
|
|
//! ```
|
|
//!
|
|
//! ## Using a game definition
|
|
//! ```
|
|
//! use gamedig::{GAMES, query};
|
|
//!
|
|
//! let game = GAMES.get("teamfortress2").unwrap(); // Get a game definition, the full list can be found in src/games/mod.rs
|
|
//! let response = query(game, &"127.0.0.1".parse().unwrap(), None); // None will use the default port
|
|
//! match response {
|
|
//! Err(error) => println!("Couldn't query, error: {}", error),
|
|
//! Ok(r) => println!("{:#?}", r.as_json()),
|
|
//! }
|
|
//! ```
|
|
//!
|
|
//! # Crate features:
|
|
//! Enabled by default: `games`, `game_defs`, `services`
|
|
//!
|
|
//! `serde` - enables serde serialization/deserialization for many gamedig types
|
|
//! using serde derive. <br>
|
|
//! `games` - include games support. <br>
|
|
//! `services` - include services support. <br>
|
|
//! `game_defs` - include game definitions for programmatic access (enabled by
|
|
//! default). <br>
|
|
//! `clap` - enable clap derivations for gamedig settings types. <br>
|
|
//! `tls` - enable TLS support for the HTTP client.
|
|
|
|
pub mod errors;
|
|
#[cfg(feature = "games")]
|
|
pub mod games;
|
|
pub mod protocols;
|
|
#[cfg(feature = "services")]
|
|
pub mod services;
|
|
|
|
mod buffer;
|
|
mod http;
|
|
mod socket;
|
|
mod utils;
|
|
|
|
#[cfg(feature = "packet_capture")]
|
|
pub mod capture;
|
|
|
|
pub use errors::*;
|
|
#[cfg(feature = "games")]
|
|
pub use games::*;
|
|
#[cfg(feature = "games")]
|
|
pub use query::*;
|
|
#[cfg(feature = "services")]
|
|
pub use services::*;
|
|
|
|
// Re-export types needed to call games::query::query in the root
|
|
pub use protocols::types::{ExtraRequestSettings, TimeoutSettings};
|