From 938905068bcd99d4c26da388edf031c9a9bb97c8 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 6 May 2019 16:00:01 -0700 Subject: [PATCH] Add command-line option to change default protocol version Previously, we would send the latest supported protocol version in the server ping packet. This normally works fine since the server will respond with the protocol version it supports, which we'll use. However, some server software such as BungeeCord supports _multiple_ protocols, and the server will match what the client sent in the ping (if it supports it). Since BungeeCord is a proxy, it forwards to backend servers which can be of various versions, which won't necessarily be the latest. This change adds a command-line option to change the "default" protocol version, -p or --default-protocol-version, which is used in the ping packet instead. Current default is 477 (1.14), but if you pass for example -p 404 (1.13.2), then BungeeCord will respond accordingly: packet = Some(StatusResponse(StatusResponse { status: "{\"version\":{\"name\":\"BungeeCord 1.8.x-1.14.x\",\"protocol\":404},\"players\":{\"max\":1,\"online\":0},\"description\":{\"extra\":[{\"color\":\"dark_blue\",\"text\":\"Another Bungee server\"}],\"text\":\"\"},\"modinfo\":{\"type\":\"FML\",\"modList\":[]}}" })) [main.rs:95][INFO] Detected server protocol version 404 and this protocol will be used. Effectively, this option lets you masquerade as any supported client version. See https://github.com/iceiix/stevenarella/issues/125#issuecomment-489484701 --- src/main.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index a469931..77d3ba5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,19 +84,20 @@ pub struct Game { last_mouse_xrel: f64, last_mouse_yrel: f64, is_fullscreen: bool, + default_protocol_version: i32, } impl Game { pub fn connect_to(&mut self, address: &str) { - let (protocol_version, forge_mods) = match protocol::Conn::new(&address, protocol::SUPPORTED_PROTOCOLS[0]) + let (protocol_version, forge_mods) = match protocol::Conn::new(&address, self.default_protocol_version) .and_then(|conn| conn.do_status()) { Ok(res) => { info!("Detected server protocol version {}", res.0.version.protocol); (res.0.version.protocol, res.0.forge_mods) }, Err(err) => { - warn!("Error pinging server {} to get protocol version: {:?}, defaulting to {}", address, err, protocol::SUPPORTED_PROTOCOLS[0]); - (protocol::SUPPORTED_PROTOCOLS[0], vec![]) + warn!("Error pinging server {} to get protocol version: {:?}, defaulting to {}", address, err, self.default_protocol_version); + (self.default_protocol_version, vec![]) }, }; @@ -174,6 +175,10 @@ struct Opt { /// Log decoded packets received from network #[structopt(short = "n", long = "network-debug")] network_debug: bool, + + /// Protocol version to use in the autodetection ping + #[structopt(short = "p", long = "default-protocol-version")] + default_protocol_version: Option, } cfg_if! { @@ -272,6 +277,7 @@ pub fn main() { last_mouse_xrel: 0.0, last_mouse_yrel: 0.0, is_fullscreen: false, + default_protocol_version: opt.default_protocol_version.unwrap_or(protocol::SUPPORTED_PROTOCOLS[0]), }; game.renderer.camera.pos = cgmath::Point3::new(0.5, 13.2, 0.5);