Add --network-parse-packet option
This commit is contained in:
parent
47dd9ac112
commit
37f55e2c57
|
@ -1308,6 +1308,44 @@ impl Conn {
|
|||
}
|
||||
}
|
||||
|
||||
/// Parse a clientbound packet, for debugging packet parsing issues (Conn::read_packet)
|
||||
pub fn try_parse_packet(ibuf: Vec<u8>, protocol_version: i32) {
|
||||
println!("trying to parse packet data {:?}", ibuf);
|
||||
|
||||
let mut buf = io::Cursor::new(ibuf);
|
||||
|
||||
let id = VarInt::read_from(&mut buf).unwrap().0;
|
||||
let dir = Direction::Clientbound;
|
||||
let state = State::Play; // TODO: allow parsing other states
|
||||
|
||||
println!(
|
||||
"about to parse id={:x}, dir={:?} state={:?}",
|
||||
id, dir, state
|
||||
);
|
||||
|
||||
let packet = packet::packet_by_id(protocol_version, state, dir, id, &mut buf).unwrap();
|
||||
|
||||
println!("packet = {:?}", packet);
|
||||
|
||||
match packet {
|
||||
Some(_val) => {
|
||||
let pos = buf.position() as usize;
|
||||
let ibuf = buf.into_inner();
|
||||
if ibuf.len() != pos {
|
||||
println!("pos = {:?}", pos);
|
||||
println!("ibuf = {:?}", ibuf);
|
||||
println!(
|
||||
"Failed to read all of packet 0x{:X}, \
|
||||
had {} bytes left",
|
||||
id,
|
||||
ibuf.len() - pos
|
||||
)
|
||||
}
|
||||
}
|
||||
None => println!("missing packet"),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Status {
|
||||
pub version: StatusVersion,
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -18,6 +18,7 @@
|
|||
#![allow(clippy::float_cmp)] // float comparison used to check if changed
|
||||
|
||||
use log::{error, info, warn};
|
||||
use std::fs;
|
||||
use std::time::{Duration, Instant};
|
||||
extern crate steven_shared as shared;
|
||||
|
||||
|
@ -193,6 +194,10 @@ struct Opt {
|
|||
#[structopt(short = "n", long = "network-debug")]
|
||||
network_debug: bool,
|
||||
|
||||
/// Parse a network packet from a file
|
||||
#[structopt(short = "N", long = "network-parse-packet")]
|
||||
network_parse_packet: Option<String>,
|
||||
|
||||
/// Protocol version to use in the autodetection ping
|
||||
#[structopt(short = "p", long = "default-protocol-version")]
|
||||
default_protocol_version: Option<String>,
|
||||
|
@ -328,6 +333,12 @@ fn main2() {
|
|||
protocol::enable_network_debug();
|
||||
}
|
||||
|
||||
if let Some(filename) = opt.network_parse_packet {
|
||||
let data = fs::read(filename).unwrap();
|
||||
protocol::try_parse_packet(data, default_protocol_version);
|
||||
return;
|
||||
}
|
||||
|
||||
if opt.server.is_some() {
|
||||
game.connect_to(&opt.server.unwrap());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue