mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-06 15:27:28 +00:00
feat: add valve protocol query example
This commit is contained in:
parent
f11a50a415
commit
adb2109aea
2 changed files with 24 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ Who knows what the future holds...
|
|||
- [Valheim](https://store.steampowered.com/app/892970/Valheim/) support.
|
||||
- [The Front](https://store.steampowered.com/app/2285150/The_Front/) support.
|
||||
- [Conan Exiles](https://store.steampowered.com/app/440900/Conan_Exiles/) support.
|
||||
- Added a valve protocol query example.
|
||||
|
||||
### Breaking:
|
||||
Game:
|
||||
|
|
|
|||
23
examples/valve_protocol_query.rs
Normal file
23
examples/valve_protocol_query.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
use std::time::Duration;
|
||||
use gamedig::protocols::types::TimeoutSettings;
|
||||
use gamedig::protocols::valve;
|
||||
use gamedig::protocols::valve::{Engine, GatheringSettings};
|
||||
|
||||
fn main() {
|
||||
let address = &SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 27015);
|
||||
let engine = Engine::Source(None); // We don't specify a steam app id, let the query try to find it.
|
||||
let gather_settings = GatheringSettings {
|
||||
players: true, // We want to query for players
|
||||
rules: false, // We don't want to query for rules
|
||||
check_app_id: false, // Loosen up the query a bit by not checking app id
|
||||
};
|
||||
|
||||
let read_timeout = Duration::from_secs(2);
|
||||
let write_timeout = Duration::from_secs(3);
|
||||
let retries = 1; // does another request if the first one fails.
|
||||
let timeout_settings = TimeoutSettings::new(Some(read_timeout), Some(write_timeout), retries).unwrap();
|
||||
|
||||
let response = valve::query(address, engine, Some(gather_settings), Some(timeout_settings));
|
||||
println!("{response:#?}");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue