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
This commit is contained in:
ice_iix 2019-05-06 16:00:01 -07:00
parent 327efcf043
commit 938905068b
1 changed files with 9 additions and 3 deletions

View File

@ -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<i32>,
}
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);