mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-18 09:35:50 +00:00
Minecraft rework and some docs
This commit is contained in:
parent
d671bb0310
commit
7828bb9433
4 changed files with 37 additions and 14 deletions
|
|
@ -1,13 +1,34 @@
|
|||
use crate::GDResult;
|
||||
use crate::{GDError, GDResult};
|
||||
use crate::protocols::minecraft;
|
||||
use crate::protocols::minecraft::{Server, Response};
|
||||
use crate::protocols::minecraft::{Server, Response, LegacyGroup};
|
||||
|
||||
/// Query with all the protocol variants one by one (Java -> Legacy (1.6 -> 1.4 -> Beta 1.8)).
|
||||
pub fn query(address: &str, port: Option<u16>) -> GDResult<Response> {
|
||||
minecraft::query(address, port_or_default(port), None)
|
||||
}
|
||||
|
||||
pub fn query_specific(mc_type: Server, address: &str, port: Option<u16>) -> GDResult<Response> {
|
||||
minecraft::query_specific(mc_type, address, port_or_default(port), None)
|
||||
/// Query a Java Server.
|
||||
pub fn query_java(address: &str, port: Option<u16>) -> GDResult<Response> {
|
||||
minecraft::query_specific(Server::Java, address, port_or_default(port), None)
|
||||
}
|
||||
|
||||
/// Query a (Java) Legacy Server (1.6 -> 1.4 -> Beta 1.8).
|
||||
pub fn query_legacy(address: &str, port: Option<u16>) -> GDResult<Response> {
|
||||
let unwrapped_port = port_or_default(port);
|
||||
|
||||
if let Ok(response) = minecraft::query_specific(Server::Legacy(LegacyGroup::V1_6), address, unwrapped_port, None) {
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
if let Ok(response) = minecraft::query_specific(Server::Legacy(LegacyGroup::V1_4), address, unwrapped_port, None) {
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
if let Ok(response) = minecraft::query_specific(Server::Legacy(LegacyGroup::VB1_8), address, unwrapped_port, None) {
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
Err(GDError::AutoQuery)
|
||||
}
|
||||
|
||||
fn port_or_default(port: Option<u16>) -> u16 {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ mod legacy_v1_4;
|
|||
mod legacy_v1_6;
|
||||
mod legacy_bv1_8;
|
||||
|
||||
/// Queries a Minecraft server.
|
||||
/// Queries a Minecraft server with all the protocol variants one by one (Java -> 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()) {
|
||||
return Ok(response);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue