mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-06 15:27:28 +00:00
* [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)
91 lines
2.7 KiB
Rust
91 lines
2.7 KiB
Rust
use crate::protocols::minecraft::types::RequestSettings;
|
|
use crate::{
|
|
protocols::minecraft::{
|
|
protocol::{
|
|
bedrock::Bedrock,
|
|
java::Java,
|
|
legacy_bv1_8::LegacyBV1_8,
|
|
legacy_v1_4::LegacyV1_4,
|
|
legacy_v1_6::LegacyV1_6,
|
|
},
|
|
BedrockResponse,
|
|
JavaResponse,
|
|
LegacyGroup,
|
|
},
|
|
protocols::types::TimeoutSettings,
|
|
GDErrorKind::AutoQuery,
|
|
GDResult,
|
|
};
|
|
use std::net::SocketAddr;
|
|
|
|
mod bedrock;
|
|
mod java;
|
|
mod legacy_bv1_8;
|
|
mod legacy_v1_4;
|
|
mod legacy_v1_6;
|
|
|
|
/// Queries a Minecraft server with all the protocol variants one by one (Java
|
|
/// -> Bedrock -> Legacy (1.6 -> 1.4 -> Beta 1.8)).
|
|
pub fn query(
|
|
address: &SocketAddr,
|
|
timeout_settings: Option<TimeoutSettings>,
|
|
request_settings: Option<RequestSettings>,
|
|
) -> GDResult<JavaResponse> {
|
|
if let Ok(response) = query_java(address, timeout_settings.clone(), request_settings) {
|
|
return Ok(response);
|
|
}
|
|
|
|
if let Ok(response) = query_bedrock(address, timeout_settings.clone()) {
|
|
return Ok(JavaResponse::from_bedrock_response(response));
|
|
}
|
|
|
|
if let Ok(response) = query_legacy(address, timeout_settings) {
|
|
return Ok(response);
|
|
}
|
|
|
|
Err(AutoQuery.into())
|
|
}
|
|
|
|
/// Query a Java Server.
|
|
pub fn query_java(
|
|
address: &SocketAddr,
|
|
timeout_settings: Option<TimeoutSettings>,
|
|
request_settings: Option<RequestSettings>,
|
|
) -> GDResult<JavaResponse> {
|
|
Java::query(address, timeout_settings, request_settings)
|
|
}
|
|
|
|
/// Query a (Java) Legacy Server (1.6 -> 1.4 -> Beta 1.8).
|
|
pub fn query_legacy(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<JavaResponse> {
|
|
if let Ok(response) = query_legacy_specific(LegacyGroup::V1_6, address, timeout_settings.clone()) {
|
|
return Ok(response);
|
|
}
|
|
|
|
if let Ok(response) = query_legacy_specific(LegacyGroup::V1_4, address, timeout_settings.clone()) {
|
|
return Ok(response);
|
|
}
|
|
|
|
if let Ok(response) = query_legacy_specific(LegacyGroup::VB1_8, address, timeout_settings) {
|
|
return Ok(response);
|
|
}
|
|
|
|
Err(AutoQuery.into())
|
|
}
|
|
|
|
/// Query a specific (Java) Legacy Server.
|
|
pub fn query_legacy_specific(
|
|
group: LegacyGroup,
|
|
address: &SocketAddr,
|
|
timeout_settings: Option<TimeoutSettings>,
|
|
) -> GDResult<JavaResponse> {
|
|
match group {
|
|
LegacyGroup::V1_6 => LegacyV1_6::query(address, timeout_settings),
|
|
LegacyGroup::V1_4 => LegacyV1_4::query(address, timeout_settings),
|
|
LegacyGroup::VB1_8 => LegacyBV1_8::query(address, timeout_settings),
|
|
}
|
|
}
|
|
|
|
/// Query a Bedrock Server.
|
|
pub fn query_bedrock(address: &SocketAddr, timeout_settings: Option<TimeoutSettings>) -> GDResult<BedrockResponse> {
|
|
Bedrock::query(address, timeout_settings)
|
|
}
|