mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-06-01 09:42:41 +00:00
[Generic] Add struct for all extra request settings (#93)
* [Generic] Add struct for all extra request settings Adds a new struct `ExtraRequestSettings` that contains all possible extra settings for all protocols, and can be implicitly converted with `.into()` into each protocol's extra settings type. This is then used in a new query method `query_with_timeout_and_extra_settings()` that passes the object on to the selected protocol. This also updates the generic example to set some of these generic settings so that it can be used for certain queries like "mc.hypixel.net". * [Minecraft] Add `request_settings` parameter to auto query This allows generic queries to pass through request settings when using the `mc` game so that servers like `mc.hypixel.net` will still work when using auto query. * Fix generic examples tests (and enable example tests in pre-commit)
This commit is contained in:
parent
76a3ac2f78
commit
6c1fdb1159
9 changed files with 175 additions and 20 deletions
|
|
@ -118,7 +118,7 @@ pub mod warsow;
|
|||
|
||||
use crate::protocols::gamespy::GameSpyVersion;
|
||||
use crate::protocols::quake::QuakeVersion;
|
||||
use crate::protocols::types::{CommonResponse, ProprietaryProtocol, TimeoutSettings};
|
||||
use crate::protocols::types::{CommonResponse, ExtraRequestSettings, ProprietaryProtocol, TimeoutSettings};
|
||||
use crate::protocols::{self, Protocol};
|
||||
use crate::GDResult;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
|
@ -142,26 +142,50 @@ mod definitions;
|
|||
pub use definitions::GAMES;
|
||||
|
||||
/// Make a query given a game definition
|
||||
#[inline]
|
||||
pub fn query(game: &Game, address: &IpAddr, port: Option<u16>) -> GDResult<Box<dyn CommonResponse>> {
|
||||
query_with_timeout(game, address, port, None)
|
||||
query_with_timeout_and_extra_settings(game, address, port, None, None)
|
||||
}
|
||||
|
||||
/// Make a query given a game definition and timeout settings
|
||||
#[inline]
|
||||
pub fn query_with_timeout(
|
||||
game: &Game,
|
||||
address: &IpAddr,
|
||||
port: Option<u16>,
|
||||
timeout_settings: Option<TimeoutSettings>,
|
||||
) -> GDResult<Box<dyn CommonResponse>> {
|
||||
query_with_timeout_and_extra_settings(game, address, port, timeout_settings, None)
|
||||
}
|
||||
|
||||
/// Make a query given a game definition, timeout settings, and extra settings
|
||||
pub fn query_with_timeout_and_extra_settings(
|
||||
game: &Game,
|
||||
address: &IpAddr,
|
||||
port: Option<u16>,
|
||||
timeout_settings: Option<TimeoutSettings>,
|
||||
extra_settings: Option<ExtraRequestSettings>,
|
||||
) -> GDResult<Box<dyn CommonResponse>> {
|
||||
let socket_addr = SocketAddr::new(*address, port.unwrap_or(game.default_port));
|
||||
Ok(match &game.protocol {
|
||||
Protocol::Valve(steam_app) => {
|
||||
protocols::valve::query(&socket_addr, steam_app.as_engine(), None, timeout_settings).map(Box::new)?
|
||||
protocols::valve::query(
|
||||
&socket_addr,
|
||||
steam_app.as_engine(),
|
||||
extra_settings.map(ExtraRequestSettings::into),
|
||||
timeout_settings,
|
||||
)
|
||||
.map(Box::new)?
|
||||
}
|
||||
Protocol::Minecraft(version) => {
|
||||
match version {
|
||||
Some(protocols::minecraft::Server::Java) => {
|
||||
protocols::minecraft::query_java(&socket_addr, timeout_settings, None).map(Box::new)?
|
||||
protocols::minecraft::query_java(
|
||||
&socket_addr,
|
||||
timeout_settings,
|
||||
extra_settings.map(ExtraRequestSettings::into),
|
||||
)
|
||||
.map(Box::new)?
|
||||
}
|
||||
Some(protocols::minecraft::Server::Bedrock) => {
|
||||
protocols::minecraft::query_bedrock(&socket_addr, timeout_settings).map(Box::new)?
|
||||
|
|
@ -169,7 +193,14 @@ pub fn query_with_timeout(
|
|||
Some(protocols::minecraft::Server::Legacy(group)) => {
|
||||
protocols::minecraft::query_legacy_specific(*group, &socket_addr, timeout_settings).map(Box::new)?
|
||||
}
|
||||
None => protocols::minecraft::query(&socket_addr, timeout_settings).map(Box::new)?,
|
||||
None => {
|
||||
protocols::minecraft::query(
|
||||
&socket_addr,
|
||||
timeout_settings,
|
||||
extra_settings.map(ExtraRequestSettings::into),
|
||||
)
|
||||
.map(Box::new)?
|
||||
}
|
||||
}
|
||||
}
|
||||
Protocol::Gamespy(version) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue