feat: Add GatheringSettings on Valve macros (#128)

* Initial macro modification for gathering settings

* Initial Valheim support

* Remove unused use

* Fix macro

Thanks bunch @Douile

* docs: Add Valheim to CHANGELOG and GAMES

* Add commentary regarding gathering settings comment generation

* Add GatheringSettings to game!

* Remove unused stuff

* Fix tests and add comment regarding the game argument
This commit is contained in:
CosminPerRam 2023-10-19 23:15:10 +03:00 committed by GitHub
parent 1ca6e6e85c
commit 501524b0da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 89 additions and 21 deletions

View file

@ -2,23 +2,21 @@ use gamedig::{
protocols::types::{CommonResponse, ExtraRequestSettings, TimeoutSettings},
query_with_timeout_and_extra_settings,
GDResult,
Game,
GAMES,
};
use std::net::{IpAddr, SocketAddr, ToSocketAddrs};
/// Make a query given the name of a game
/// The `game` argument is taken from the [GAMES](gamedig::GAMES) map.
fn generic_query(
game_name: &str,
game: &Game,
addr: &IpAddr,
port: Option<u16>,
timeout_settings: Option<TimeoutSettings>,
extra_settings: Option<ExtraRequestSettings>,
) -> GDResult<Box<dyn CommonResponse>> {
let game = GAMES
.get(game_name)
.expect("Game doesn't exist, run without arguments to see a list of games");
println!("Querying {:#?} with game {:#?}.", addr, game);
let response = query_with_timeout_and_extra_settings(game, addr, port, timeout_settings, extra_settings)?;
@ -51,14 +49,18 @@ fn main() {
)
.unwrap();
let extra_settings = ExtraRequestSettings::default()
let game = GAMES
.get(&game_name)
.expect("Game doesn't exist, run without arguments to see a list of games");
let extra_settings = game
.request_settings
.clone()
.set_hostname(hostname.to_string())
.set_gather_rules(true)
.set_gather_players(true)
.set_check_app_id(false);
generic_query(
&game_name,
game,
&addr.ip(),
port,
Some(timeout_settings),
@ -67,8 +69,7 @@ fn main() {
.unwrap();
} else {
// Without arguments print a list of games
for (name, game) in gamedig::games::GAMES.entries() {
for (name, game) in GAMES.entries() {
println!("{}\t{}", name, game.name);
}
}
@ -95,7 +96,12 @@ mod test {
)
.unwrap(),
);
assert!(generic_query(game_name, &ADDR, None, timeout_settings, None).is_err());
let game = GAMES
.get(game_name)
.expect("Game doesn't exist, run without arguments to see a list of games");
assert!(generic_query(game, &ADDR, None, timeout_settings, None).is_err());
}
#[test]