mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-18 09:35:50 +00:00
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:
parent
1ca6e6e85c
commit
501524b0da
8 changed files with 89 additions and 21 deletions
|
|
@ -15,9 +15,21 @@ pub use types::*;
|
|||
/// * `steam_app`, `default_port` - Passed through to [game_query_fn].
|
||||
macro_rules! game_query_mod {
|
||||
($mod_name: ident, $pretty_name: expr, $steam_app: ident, $default_port: literal) => {
|
||||
crate::protocols::valve::game_query_mod!(
|
||||
$mod_name,
|
||||
$pretty_name,
|
||||
$steam_app,
|
||||
$default_port,
|
||||
GatheringSettings::default()
|
||||
);
|
||||
};
|
||||
|
||||
($mod_name: ident, $pretty_name: expr, $steam_app: ident, $default_port: literal, $gathering_settings: expr) => {
|
||||
#[doc = $pretty_name]
|
||||
pub mod $mod_name {
|
||||
crate::protocols::valve::game_query_fn!($steam_app, $default_port);
|
||||
use crate::protocols::valve::GatheringSettings;
|
||||
|
||||
crate::protocols::valve::game_query_fn!($steam_app, $default_port, $gathering_settings);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -36,19 +48,20 @@ pub(crate) use game_query_mod;
|
|||
/// game_query_fn!(TEAMFORTRESS2, 27015);
|
||||
/// ```
|
||||
macro_rules! game_query_fn {
|
||||
($steam_app: ident, $default_port: literal) => {
|
||||
($steam_app: ident, $default_port: literal, $gathering_settings: expr) => {
|
||||
// TODO: By using $gathering_settings, also add to doc if a game doesnt respond to certain gathering settings
|
||||
crate::protocols::valve::game_query_fn!{@gen $steam_app, $default_port, concat!(
|
||||
"Make a valve query for ", stringify!($steam_app), " with default timeout settings and default extra request settings.\n\n",
|
||||
"If port is `None`, then the default port (", stringify!($default_port), ") will be used.")}
|
||||
"If port is `None`, then the default port (", stringify!($default_port), ") will be used."), $gathering_settings}
|
||||
};
|
||||
|
||||
(@gen $steam_app: ident, $default_port: literal, $doc: expr) => {
|
||||
(@gen $steam_app: ident, $default_port: literal, $doc: expr, $gathering_settings: expr) => {
|
||||
#[doc = $doc]
|
||||
pub fn query(address: &std::net::IpAddr, port: Option<u16>) -> crate::GDResult<crate::protocols::valve::game::Response> {
|
||||
let valve_response = crate::protocols::valve::query(
|
||||
&std::net::SocketAddr::new(*address, port.unwrap_or($default_port)),
|
||||
crate::protocols::valve::SteamApp::$steam_app.as_engine(),
|
||||
None,
|
||||
Some($gathering_settings),
|
||||
None,
|
||||
)?;
|
||||
|
||||
|
|
|
|||
|
|
@ -341,6 +341,8 @@ pub enum SteamApp {
|
|||
HLL,
|
||||
/// Barotrauma
|
||||
BAROTRAUMA,
|
||||
/// Valheim
|
||||
VALHEIM,
|
||||
}
|
||||
|
||||
impl SteamApp {
|
||||
|
|
@ -383,6 +385,7 @@ impl SteamApp {
|
|||
Self::BAROTRAUMA => Engine::new_source(602960),
|
||||
Self::ROR2 => Engine::new_source(632_360),
|
||||
Self::OHD => Engine::new_source_with_dedicated(736_590, 950_900),
|
||||
Self::VALHEIM => Engine::new_source(892_970),
|
||||
Self::ONSET => Engine::new_source(1_105_810),
|
||||
Self::VRISING => Engine::new_source(1_604_030),
|
||||
Self::HLL => Engine::new_source(686_810),
|
||||
|
|
@ -422,15 +425,29 @@ pub struct GatheringSettings {
|
|||
pub check_app_id: bool,
|
||||
}
|
||||
|
||||
impl Default for GatheringSettings {
|
||||
impl GatheringSettings {
|
||||
/// Default values are true for both the players and the rules.
|
||||
fn default() -> Self {
|
||||
pub const fn default() -> Self {
|
||||
Self {
|
||||
players: true,
|
||||
rules: true,
|
||||
check_app_id: true,
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn into_extra(self) -> ExtraRequestSettings {
|
||||
ExtraRequestSettings {
|
||||
hostname: None,
|
||||
protocol_version: None,
|
||||
gather_players: Some(self.players),
|
||||
gather_rules: Some(self.rules),
|
||||
check_app_id: Some(self.check_app_id),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for GatheringSettings {
|
||||
fn default() -> Self { GatheringSettings::default() }
|
||||
}
|
||||
|
||||
impl From<ExtraRequestSettings> for GatheringSettings {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue