Add server links to pause menu
This commit is contained in:
parent
47a794962c
commit
8105b246b7
4 changed files with 175 additions and 4 deletions
|
@ -1,4 +1,5 @@
|
|||
use super::*;
|
||||
use crate::NbtTag;
|
||||
|
||||
//
|
||||
// MARK: 0x0e ClientBoundKnownPacks
|
||||
|
@ -222,3 +223,89 @@ impl TryFrom<Vec<u8>> for UpdateTags {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// MARK: 0x10 server links
|
||||
//
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ServerLinks {
|
||||
pub links: Vec<(NbtTag, String)>, //TODO: proper type, also handle Text Component AND varint enum
|
||||
}
|
||||
|
||||
impl Packet for ServerLinks {
|
||||
const PACKET_ID: u8 = 0x10;
|
||||
fn get_target() -> PacketTarget { PacketTarget::Client }
|
||||
fn get_state() -> ConnectionState { ConnectionState::Configuration }
|
||||
}
|
||||
|
||||
impl TryFrom<ServerLinks> for Vec<u8> {
|
||||
type Error = Box<dyn Error>;
|
||||
|
||||
fn try_from(value: ServerLinks) -> Result<Self, Box<dyn Error>> {
|
||||
let mut output: Vec<u8> = Vec::new();
|
||||
|
||||
output.append(&mut crate::serialize::varint(value.links.len() as i32));
|
||||
for link in value.links {
|
||||
output.append(&mut crate::serialize::boolean(false));
|
||||
output.append(&mut crate::serialize::nbt_network(link.0));
|
||||
output.append(&mut crate::serialize::string(&link.1));
|
||||
}
|
||||
|
||||
return Ok(output);
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Vec<u8>> for ServerLinks {
|
||||
type Error = Box<dyn Error>;
|
||||
|
||||
fn try_from(mut value: Vec<u8>) -> Result<Self, Box<dyn Error>> {
|
||||
let links_len = crate::deserialize::varint(&mut value)?;
|
||||
let links: Vec<(NbtTag, String)> = (0..links_len).map(|_| {
|
||||
value.remove(0);
|
||||
return (
|
||||
crate::deserialize::nbt_network(&mut value).unwrap(),
|
||||
crate::deserialize::string(&mut value).unwrap(),
|
||||
);
|
||||
}).collect();
|
||||
|
||||
return Ok(Self {
|
||||
links,
|
||||
});
|
||||
}
|
||||
}
|
||||
//
|
||||
// MARK: 0x12 show dialog
|
||||
//
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ShowDialog {
|
||||
pub dialog: NbtTag,
|
||||
}
|
||||
|
||||
impl Packet for ShowDialog {
|
||||
const PACKET_ID: u8 = 0x12;
|
||||
fn get_target() -> PacketTarget { PacketTarget::Client }
|
||||
fn get_state() -> ConnectionState { ConnectionState::Configuration }
|
||||
}
|
||||
|
||||
impl TryFrom<ShowDialog> for Vec<u8> {
|
||||
type Error = Box<dyn Error>;
|
||||
|
||||
fn try_from(value: ShowDialog) -> Result<Self, Box<dyn Error>> {
|
||||
let mut output: Vec<u8> = Vec::new();
|
||||
output.append(&mut crate::serialize::nbt_network(value.dialog));
|
||||
|
||||
return Ok(output);
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Vec<u8>> for ShowDialog {
|
||||
type Error = Box<dyn Error>;
|
||||
|
||||
fn try_from(mut value: Vec<u8>) -> Result<Self, Box<dyn Error>> {
|
||||
return Ok(Self {
|
||||
dialog: crate::deserialize::nbt_network(&mut value)?,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2096,3 +2096,54 @@ impl TryFrom<Vec<u8>> for SystemChatMessage {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// MARK: 0x82 server links
|
||||
//
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ServerLinks {
|
||||
pub links: Vec<(NbtTag, String)>, //TODO: proper type, also handle Text Component instead of varint enum
|
||||
}
|
||||
|
||||
impl Packet for ServerLinks {
|
||||
const PACKET_ID: u8 = 0x82;
|
||||
fn get_target() -> PacketTarget { PacketTarget::Client }
|
||||
fn get_state() -> ConnectionState { ConnectionState::Play }
|
||||
}
|
||||
|
||||
impl TryFrom<ServerLinks> for Vec<u8> {
|
||||
type Error = Box<dyn Error>;
|
||||
|
||||
fn try_from(value: ServerLinks) -> Result<Self, Box<dyn Error>> {
|
||||
let mut output: Vec<u8> = Vec::new();
|
||||
|
||||
output.append(&mut crate::serialize::varint(value.links.len() as i32));
|
||||
for link in value.links {
|
||||
output.append(&mut crate::serialize::boolean(false));
|
||||
output.append(&mut crate::serialize::nbt_network(link.0));
|
||||
output.append(&mut crate::serialize::string(&link.1));
|
||||
}
|
||||
|
||||
return Ok(output);
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Vec<u8>> for ServerLinks {
|
||||
type Error = Box<dyn Error>;
|
||||
|
||||
fn try_from(mut value: Vec<u8>) -> Result<Self, Box<dyn Error>> {
|
||||
let links_len = crate::deserialize::varint(&mut value)?;
|
||||
let links: Vec<(NbtTag, String)> = (0..links_len).map(|_| {
|
||||
value.remove(0);
|
||||
return (
|
||||
crate::deserialize::nbt_network(&mut value).unwrap(),
|
||||
crate::deserialize::string(&mut value).unwrap(),
|
||||
);
|
||||
}).collect();
|
||||
|
||||
return Ok(Self {
|
||||
links,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -209,12 +209,24 @@ fn main() {
|
|||
println!("parsed packet: {parsed_packet:?}");
|
||||
parsed_client_packet = Some(parsed_packet.try_into().unwrap());
|
||||
},
|
||||
lib::packets::clientbound::configuration::ShowDialog::PACKET_ID => {
|
||||
let parsed_packet = lib::packets::clientbound::configuration::ShowDialog::try_from(client_packet.data.clone()).unwrap();
|
||||
println!("parsed packet: {parsed_packet:?}");
|
||||
parsed_client_packet = Some(parsed_packet.try_into().unwrap());
|
||||
},
|
||||
lib::packets::clientbound::configuration::ServerLinks::PACKET_ID => {
|
||||
let parsed_packet = lib::packets::clientbound::configuration::ServerLinks::try_from(client_packet.data.clone()).unwrap();
|
||||
println!("parsed packet: {parsed_packet:?}");
|
||||
parsed_client_packet = Some(parsed_packet.try_into().unwrap());
|
||||
},
|
||||
lib::packets::clientbound::configuration::UpdateTags::PACKET_ID => {
|
||||
let parsed_packet = lib::packets::clientbound::configuration::UpdateTags::try_from(client_packet.data.clone()).unwrap();
|
||||
//println!("parsed packet: {parsed_packet:?}");
|
||||
parsed_client_packet = Some(parsed_packet.try_into().unwrap());
|
||||
}
|
||||
_ => (),
|
||||
_ => {
|
||||
println!("received unkown packet in clientbound::configuration with id 0x{packet_id:02x}");
|
||||
},
|
||||
};
|
||||
},
|
||||
lib::ConnectionState::Play => {
|
||||
|
@ -292,6 +304,11 @@ fn main() {
|
|||
lib::packets::clientbound::play::SetContainerContent::PACKET_ID => {
|
||||
let parsed_packet = lib::packets::clientbound::play::SetContainerContent::try_from(client_packet.data.clone()).unwrap();
|
||||
println!("parsed packet: {parsed_packet:?}");
|
||||
parsed_client_packet = Some(parsed_packet.try_into().unwrap());
|
||||
},
|
||||
lib::packets::clientbound::play::ServerLinks::PACKET_ID => {
|
||||
let parsed_packet = lib::packets::clientbound::play::ServerLinks::try_from(client_packet.data.clone()).unwrap();
|
||||
println!("parsed packet: {parsed_packet:?}");
|
||||
parsed_client_packet = Some(parsed_packet.try_into().unwrap());
|
||||
},
|
||||
lib::packets::clientbound::play::SetEntityMetadata::PACKET_ID => {
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue