mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-18 09:35:50 +00:00
[Protocol] Fix Minecraft Java query not being able to specify a hostname (#91)
* Make initial fix * Fix imports * Rename query_address to hostname and add this to the mc example * Fix master_querant example not compiling * Add extra safety on converting strings to Minecraft Varint strings * Add docs to RequestSettings * Fix formatting
This commit is contained in:
parent
211cd5fd5f
commit
a56ca45de6
8 changed files with 118 additions and 28 deletions
|
|
@ -126,7 +126,7 @@ fn main() -> GDResult<()> {
|
|||
)
|
||||
}
|
||||
"mc" => println!("{:#?}", mc::query(ip, port)?),
|
||||
"mc_java" => println!("{:#?}", mc::query_java(ip, port)?),
|
||||
"mc_java" => println!("{:#?}", mc::query_java(ip, port, None)?),
|
||||
"mc_bedrock" => println!("{:#?}", mc::query_bedrock(ip, port)?),
|
||||
"mc_legacy" => println!("{:#?}", mc::query_legacy(ip, port)?),
|
||||
"mc_legacy_vb1_8" => {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,28 @@
|
|||
use gamedig::games::mc;
|
||||
use gamedig::protocols::minecraft::RequestSettings;
|
||||
|
||||
fn main() {
|
||||
// or Some(<port>), None is the default protocol port (which is 25565 for java
|
||||
// and 19132 for bedrock)
|
||||
let response = mc::query(&"127.0.0.1".parse().unwrap(), None);
|
||||
// This will fail if no server is available locally!
|
||||
|
||||
match response {
|
||||
Err(error) => println!("Couldn't query, error: {}", error),
|
||||
Ok(r) => println!("{:#?}", r),
|
||||
}
|
||||
|
||||
// This is an example to query a server with a hostname to be specified in the
|
||||
// packet. Passing -1 on the protocol_version means anything, note that
|
||||
// an invalid value here might result in server not responding.
|
||||
let response = mc::query_java(
|
||||
&"209.222.114.62".parse().unwrap(),
|
||||
Some(25565),
|
||||
Some(RequestSettings {
|
||||
hostname: "mc.hypixel.net".to_string(),
|
||||
protocol_version: -1,
|
||||
}),
|
||||
);
|
||||
|
||||
match response {
|
||||
Err(error) => println!("Couldn't query, error: {}", error),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue