gamedig / rust-gamedig

Game Server Query Library.
https://crates.io/crates/gamedig
MIT License
38 stars 11 forks source link

Issue with minecraft query #77

Closed Douile closed 1 year ago

Douile commented 1 year ago

While working on integration tests I noticed that Minecraft query doesn't work for popular servers such as mc.hypixel.net.

$ cargo run --example generic mc mc.hypixel.net
Querying 209.222.114.62 with game Game {
    name: "Minecraft",
    default_port: 25565,
    protocol: Minecraft(
        None,
    ),
}.
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: AutoQuery', examples/generic.rs:39:55
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Looking at the output of node-gamedig it succeeds with the "vanilla" protocol which is the equivalent of our java.

Using mc-java there is a packet underflow:

$ cargo run --example generic mc-java mc.hypixel.net
Querying 209.222.114.62 with game Game {
    name: "Minecraft (java)",
    default_port: 25565,
    protocol: Minecraft(
        Some(
            Java,
        ),
    ),
}.
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: PacketUnderflow', examples/generic.rs:39:55
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
CosminPerRam commented 1 year ago

Hmmm, I do recall when I implemented it that some popular/big servers use some 'anti-ddos' solutions and some queries return with made up data/straight up doesn't work. If you mentioned that it works with the node version, then yeah, this would probably would be a bug.

Douile commented 1 year ago

I believe they are using proxy software like https://papermc.io/software/velocity but i will have to test to confirm

Douile commented 1 year ago

Nevermind after looking into it I have found the issue. The difference between node and rust is that node sends the server address, while we use gamedig as the server address.

https://github.com/gamedig/rust-gamedig/blob/a4df444c86a305cc170200768c32e70b8a793ca2/src/protocols/minecraft/protocol/java.rs#L23-L24

Big servers (hypixel) will ignore the query if it doesn't have the correct server address.

The problem with this is that the server address needs to be the hostname of the server, in hypixels case mc.hypixel.net, but our query logic only passes IP address to the query function.

Douile commented 1 year ago

There are 2 solutions I can think of for this:

CosminPerRam commented 1 year ago

Hey, coming back to this a bit late, I couldn't make a working version, I'll look into this a bit further. Regarding the solutions, I do want to opt in for the 'additional arguments'.