mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-18 09:35:50 +00:00
Minecraft bedrock support (#7)
* Added needed ground stuff * Minecraft bedrock support! * Documentation acknowledgements! * Added utf8_le_undended test, some docs and modified master_querant * Modified query function to comply with the others Before: game query -> protocol query (get port or default port) After: game query (get port or default port) -> protocol query * Modified md files
This commit is contained in:
parent
ae14e37e60
commit
91f8bbb9fe
13 changed files with 319 additions and 107 deletions
|
|
@ -1,5 +1,6 @@
|
|||
use crate::{GDError, GDResult};
|
||||
use crate::protocols::minecraft::{LegacyGroup, Response, Server};
|
||||
use crate::protocols::minecraft::{BedrockResponse, LegacyGroup, Response};
|
||||
use crate::protocols::minecraft::protocol::bedrock::Bedrock;
|
||||
use crate::protocols::minecraft::protocol::java::Java;
|
||||
use crate::protocols::minecraft::protocol::legacy_v1_4::LegacyV1_4;
|
||||
use crate::protocols::minecraft::protocol::legacy_v1_6::LegacyV1_6;
|
||||
|
|
@ -10,36 +11,57 @@ mod java;
|
|||
mod legacy_v1_4;
|
||||
mod legacy_v1_6;
|
||||
mod legacy_bv1_8;
|
||||
mod bedrock;
|
||||
|
||||
/// Queries a Minecraft server with all the protocol variants one by one (Java -> Legacy (1.6 -> 1.4 -> Beta 1.8)).
|
||||
/// 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: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response> {
|
||||
if let Ok(response) = query_specific(Server::Java, address, port, timeout_settings.clone()) {
|
||||
if let Ok(response) = query_java(address, port, timeout_settings.clone()) {
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
if let Ok(response) = query_specific(Server::Legacy(LegacyGroup::V1_6), address, port, timeout_settings.clone()) {
|
||||
return Ok(response);
|
||||
if let Ok(response) = query_bedrock(address, port, timeout_settings.clone()) {
|
||||
return Ok(Response::from_bedrock_response(response));
|
||||
}
|
||||
|
||||
if let Ok(response) = query_specific(Server::Legacy(LegacyGroup::V1_4), address, port, timeout_settings.clone()) {
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
if let Ok(response) = query_specific(Server::Legacy(LegacyGroup::VB1_8), address, port, timeout_settings.clone()) {
|
||||
if let Ok(response) = query_legacy(address, port, timeout_settings) {
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
Err(GDError::AutoQuery)
|
||||
}
|
||||
|
||||
/// Queries a specific Minecraft Server type.
|
||||
pub fn query_specific(mc_type: Server, address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response> {
|
||||
match mc_type {
|
||||
Server::Java => Java::query(address, port, timeout_settings),
|
||||
Server::Legacy(category) => match category {
|
||||
LegacyGroup::V1_6 => LegacyV1_6::query(address, port, timeout_settings),
|
||||
LegacyGroup::V1_4 => LegacyV1_4::query(address, port, timeout_settings),
|
||||
LegacyGroup::VB1_8 => LegacyBV1_8::query(address, port, timeout_settings),
|
||||
}
|
||||
/// Query a Java Server.
|
||||
pub fn query_java(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response> {
|
||||
Java::query(address, port, timeout_settings)
|
||||
}
|
||||
|
||||
/// Query a (Java) Legacy Server (1.6 -> 1.4 -> Beta 1.8).
|
||||
pub fn query_legacy(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response> {
|
||||
if let Ok(response) = query_legacy_specific(LegacyGroup::V1_6, address, port, timeout_settings.clone()) {
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
if let Ok(response) = query_legacy_specific(LegacyGroup::V1_4, address, port, timeout_settings.clone()) {
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
if let Ok(response) = query_legacy_specific(LegacyGroup::VB1_8, address, port, timeout_settings) {
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
Err(GDError::AutoQuery)
|
||||
}
|
||||
|
||||
/// Query a specific (Java) Legacy Server.
|
||||
pub fn query_legacy_specific(group: LegacyGroup, address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<Response> {
|
||||
match group {
|
||||
LegacyGroup::V1_6 => LegacyV1_6::query(address, port, timeout_settings),
|
||||
LegacyGroup::V1_4 => LegacyV1_4::query(address, port, timeout_settings),
|
||||
LegacyGroup::VB1_8 => LegacyBV1_8::query(address, port, timeout_settings)
|
||||
}
|
||||
}
|
||||
|
||||
/// Query a Bedrock Server.
|
||||
pub fn query_bedrock(address: &str, port: u16, timeout_settings: Option<TimeoutSettings>) -> GDResult<BedrockResponse> {
|
||||
Bedrock::query(address, port, timeout_settings)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue