Skip to content

Commit 9389050

Browse files
committed
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 #125 (comment)
1 parent 327efcf commit 9389050

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/main.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,20 @@ pub struct Game {
8484
last_mouse_xrel: f64,
8585
last_mouse_yrel: f64,
8686
is_fullscreen: bool,
87+
default_protocol_version: i32,
8788
}
8889

8990
impl Game {
9091
pub fn connect_to(&mut self, address: &str) {
91-
let (protocol_version, forge_mods) = match protocol::Conn::new(&address, protocol::SUPPORTED_PROTOCOLS[0])
92+
let (protocol_version, forge_mods) = match protocol::Conn::new(&address, self.default_protocol_version)
9293
.and_then(|conn| conn.do_status()) {
9394
Ok(res) => {
9495
info!("Detected server protocol version {}", res.0.version.protocol);
9596
(res.0.version.protocol, res.0.forge_mods)
9697
},
9798
Err(err) => {
98-
warn!("Error pinging server {} to get protocol version: {:?}, defaulting to {}", address, err, protocol::SUPPORTED_PROTOCOLS[0]);
99-
(protocol::SUPPORTED_PROTOCOLS[0], vec![])
99+
warn!("Error pinging server {} to get protocol version: {:?}, defaulting to {}", address, err, self.default_protocol_version);
100+
(self.default_protocol_version, vec![])
100101
},
101102
};
102103

@@ -174,6 +175,10 @@ struct Opt {
174175
/// Log decoded packets received from network
175176
#[structopt(short = "n", long = "network-debug")]
176177
network_debug: bool,
178+
179+
/// Protocol version to use in the autodetection ping
180+
#[structopt(short = "p", long = "default-protocol-version")]
181+
default_protocol_version: Option<i32>,
177182
}
178183

179184
cfg_if! {
@@ -272,6 +277,7 @@ pub fn main() {
272277
last_mouse_xrel: 0.0,
273278
last_mouse_yrel: 0.0,
274279
is_fullscreen: false,
280+
default_protocol_version: opt.default_protocol_version.unwrap_or(protocol::SUPPORTED_PROTOCOLS[0]),
275281
};
276282
game.renderer.camera.pos = cgmath::Point3::new(0.5, 13.2, 0.5);
277283

0 commit comments

Comments
 (0)