Skip to content

Commit

Permalink
fix packet inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
JackCrumpLeys committed Jun 20, 2024
1 parent 7503956 commit 7514da0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
24 changes: 12 additions & 12 deletions tools/packet_inspector/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ fn write_packets(packets: &Vec<Packet>) -> anyhow::Result<()> {

// if the packet is clientbound, but the name does not ends with S2c, add it
let name = if packet.side == "clientbound" && !name.ends_with("S2c") {
format!("{}S2c", name)
format!("{name}S2c")
} else {
name
};

// same for serverbound
let name = if packet.side == "serverbound" && !name.ends_with("C2s") {
format!("{}C2s", name)
format!("{name}C2s")
} else {
name
};
Expand Down Expand Up @@ -101,24 +101,24 @@ fn write_transformer(packets: &[Packet]) -> anyhow::Result<()> {

let mut grouped_packets = packets.iter().fold(grouped_packets, |mut acc, packet| {
let side = match packet.side.as_str() {
"serverbound" => "Serverbound".to_string(),
"clientbound" => "Clientbound".to_string(),
"serverbound" => "Serverbound".to_owned(),
"clientbound" => "Clientbound".to_owned(),
_ => panic!("Invalid side"),
};

let state = match packet.state.as_str() {
"handshaking" => "Handshaking".to_string(),
"status" => "Status".to_string(),
"login" => "Login".to_string(),
"play" => "Play".to_string(),
"handshaking" => "Handshaking".to_owned(),
"status" => "Status".to_owned(),
"login" => "Login".to_owned(),
"play" => "Play".to_owned(),
_ => panic!("Invalid state"),
};

let name = packet
.name
.strip_suffix("Packet")
.unwrap_or(&packet.name)
.to_string();
.to_owned();

// lowercase the last character of name
let name = {
Expand All @@ -132,14 +132,14 @@ fn write_transformer(packets: &[Packet]) -> anyhow::Result<()> {

// if the packet is clientbound, but the name does not ends with S2c, add it
let name = if side == "Clientbound" && !name.ends_with("S2c") {
format!("{}S2c", name)
format!("{name}S2c")
} else {
name
};

// same for serverbound
let name = if side == "Serverbound" && !name.ends_with("C2s") {
format!("{}C2s", name)
format!("{name}C2s")
} else {
name
};
Expand All @@ -153,7 +153,7 @@ fn write_transformer(packets: &[Packet]) -> anyhow::Result<()> {

let mut generated = TokenStream::new();

for (side, state_map) in grouped_packets.iter_mut() {
for (side, state_map) in &mut grouped_packets {
let mut side_arms = TokenStream::new();
for (state, id_map) in state_map.iter_mut() {
let mut match_arms = TokenStream::new();
Expand Down
6 changes: 1 addition & 5 deletions tools/packet_inspector/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ impl GuiApp {
shared_state: shared_state.clone(),
};

Self {
shared_state,
tree,
tab_viewer,
}
Self { tree, shared_state, tab_viewer }
}
}

Expand Down
2 changes: 1 addition & 1 deletion tools/packet_inspector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl Proxy {
_ = self.main_task => {},

// If the main task doesn't stop after 5 seconds, we force terminate it
_ = tokio::time::sleep(Duration::from_secs(5)) => {
() = tokio::time::sleep(Duration::from_secs(5)) => {
abort_handle.abort();
},
}
Expand Down
8 changes: 4 additions & 4 deletions tools/packet_inspector/src/shared_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl PacketFilter {
pub(crate) fn new() -> Self {
let mut inner = HashMap::new();

for p in packet_inspector::STD_PACKETS.iter() {
for p in &packet_inspector::STD_PACKETS {
inner.insert(p.clone(), true);
}

Expand Down Expand Up @@ -77,8 +77,8 @@ impl Default for SharedState {
let (sender, receiver) = flume::unbounded();

Self {
listener_addr: "127.0.0.1:25566".to_string(),
server_addr: "127.0.0.1:25565".to_string(),
listener_addr: "127.0.0.1:25566".to_owned(),
server_addr: "127.0.0.1:25565".to_owned(),
autostart: false,
is_listening: false,
packet_search: String::new(),
Expand Down Expand Up @@ -110,7 +110,7 @@ impl SharedState {

let mut packet_filter = PacketFilter::new();
// iterate over packet_inspector::STD_PACKETS
for p in packet_inspector::STD_PACKETS.iter() {
for p in &packet_inspector::STD_PACKETS {
// if the packet is in the current packet_filter
if let Some(v) = self.packet_filter.get(p) {
// insert it into packet_filter
Expand Down
2 changes: 1 addition & 1 deletion tools/packet_inspector/src/tri_checkbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl<'a> Widget for TriCheckbox<'a> {
visuals.fg_stroke,
));
}
_ => {}
TriCheckboxState::Disabled => {}
}
if let Some(text) = text {
let text_pos = pos2(
Expand Down

0 comments on commit 7514da0

Please sign in to comment.