Merge branch 'main' into feat/cli

This commit is contained in:
Cain 2023-11-08 20:42:07 +00:00
commit 963040fb84
28 changed files with 1071 additions and 348 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]
@ -108,7 +114,7 @@ mod test {
fn teamfortress2() { test_game("teamfortress2"); }
#[test]
fn quake() { test_game("quake3"); }
fn quake2() { test_game("quake2"); }
#[test]
fn all_games() {