timvisee / lazymc

💤 Put your Minecraft server to rest when idle.
GNU General Public License v3.0
579 stars 16 forks source link

Add Floodgate support #68

Open NyaomiDEV opened 6 months ago

NyaomiDEV commented 6 months ago

As I mentioned in https://github.com/timvisee/lazymc/issues/1#issuecomment-2032205079 proxy setups work if they have GeyserMC installed, but at one condition: the Floodgate data cannot be forwarded back to the server if it is sleeping.

I don't exactly know if Floodgate sends extra data with the login packet in a way that breaks Lazymc, but probably this is worth supporting.

[17:39:14 INFO] [geyser]: /192.168.1.220:53171 tried to connect!
[17:39:15 INFO] [geyser]: Player connected with username NyaomiPLAY
[17:39:15 INFO] [geyser]: NyaomiPLAY (logged in as: NyaomiPLAY) has connected to the Java server
[17:39:15 INFO] [floodgate]: Floodgate player who is logged in as NyaomiPLAY <UUID> joined
[17:39:15 INFO]: [connected player] NyaomiPLAY (/192.168.1.220:0) has connected
[17:39:15 INFO]: [server connection] NyaomiPLAY -> server has connected
[17:39:15 INFO]: [server connection] NyaomiPLAY -> server has disconnected
[17:39:15 ERROR]: [connected player] NyaomiPLAY (/192.168.1.220:0): unable to connect to server server
com.velocitypowered.proxy.util.except.QuietRuntimeException: The connection to the remote server was unexpectedly closed.
[17:39:15 INFO]: [connected player] NyaomiPLAY (/192.168.1.220:0) has disconnected: Unable to connect you to server. Please try again later.
[17:39:15 INFO] [floodgate]: Floodgate player logged in as NyaomiPLAY disconnected
[17:39:15 INFO] [geyser]: NyaomiPLAY has disconnected from the Java server because of §r§cUnable to connect you to server. Please try again later.
NyaomiDEV commented 6 months ago
 DEBUG lazymc > Got malformed handshake from client, disconnecting

Hmmmm

NyaomiDEV commented 6 months ago

It was easy!

https://github.com/timvisee/rust-minecraft-protocol/blob/4a4f2e2a1c04d23db99e178d5144e17889eaa8bf/protocol/src/version/v1_14_4/handshake.rs#L32

pub struct Handshake {
    #[data_type(with = "var_int")]
    pub protocol_version: i32,
    #[data_type(max_length = 65535)] // was max_length = 255
    pub server_addr: String,
    pub server_port: u16,
    #[data_type(with = "var_int")]
    pub next_state: i32,
}

@timvisee please add this change :pleading_face:


Okay, I feel as though it should be noted that it seems Velocity, BungeeCord and Floodgate like to append stuff into server_addr for player forwarding and authentication purposes. While it may seem "a lot" to allow for a 65535 bytes long string, we don't even know if tomorrow there will be another player proxy that appends a ton of extra information to this packet. So, while we're left wondering, this seems safe enough to keep around.

(Also I am currently using a self-compiled version of Lazymc, so while it doesn't break I'm happy)