mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
Fixes
This commit is contained in:
parent
1e145a82b8
commit
0530c57579
14 changed files with 5108 additions and 196 deletions
|
@ -12,7 +12,8 @@ use azalea_protocol::{
|
||||||
handshake::client_intention_packet::ClientIntentionPacket,
|
handshake::client_intention_packet::ClientIntentionPacket,
|
||||||
login::{
|
login::{
|
||||||
serverbound_hello_packet::ServerboundHelloPacket,
|
serverbound_hello_packet::ServerboundHelloPacket,
|
||||||
serverbound_key_packet::ServerboundKeyPacket, LoginPacket,
|
serverbound_key_packet::{NonceOrSaltSignature, ServerboundKeyPacket},
|
||||||
|
LoginPacket,
|
||||||
},
|
},
|
||||||
ConnectionProtocol, PROTOCOL_VERSION,
|
ConnectionProtocol, PROTOCOL_VERSION,
|
||||||
},
|
},
|
||||||
|
@ -109,8 +110,10 @@ impl Client {
|
||||||
|
|
||||||
conn.write(
|
conn.write(
|
||||||
ServerboundKeyPacket {
|
ServerboundKeyPacket {
|
||||||
nonce: e.encrypted_nonce,
|
nonce_or_salt_signature: NonceOrSaltSignature::Nonce(
|
||||||
shared_secret: e.encrypted_public_key,
|
e.encrypted_nonce,
|
||||||
|
),
|
||||||
|
key_bytes: e.encrypted_public_key,
|
||||||
}
|
}
|
||||||
.get(),
|
.get(),
|
||||||
)
|
)
|
||||||
|
@ -196,27 +199,66 @@ impl Client {
|
||||||
println!("Got login packet {:?}", p);
|
println!("Got login packet {:?}", p);
|
||||||
|
|
||||||
let mut state = state.lock().await;
|
let mut state = state.lock().await;
|
||||||
|
|
||||||
|
// write p into login.txt
|
||||||
|
std::io::Write::write_all(
|
||||||
|
&mut std::fs::File::create("login.txt").unwrap(),
|
||||||
|
format!("{:#?}", p).as_bytes(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
state.player.entity.id = p.player_id;
|
state.player.entity.id = p.player_id;
|
||||||
let dimension_type = p
|
|
||||||
.dimension_type
|
// TODO: have registry_holder be a struct because this sucks rn
|
||||||
|
// best way would be to add serde support to azalea-nbt
|
||||||
|
|
||||||
|
let registry_holder = p
|
||||||
|
.registry_holder
|
||||||
.as_compound()
|
.as_compound()
|
||||||
.expect("Dimension type is not compound")
|
.expect("Registry holder is not a compound")
|
||||||
.get("")
|
.get("")
|
||||||
.expect("No \"\" tag")
|
.expect("No \"\" tag")
|
||||||
.as_compound()
|
.as_compound()
|
||||||
.expect("\"\" tag is not compound");
|
.expect("\"\" tag is not a compound");
|
||||||
|
let dimension_types = registry_holder
|
||||||
|
.get("minecraft:dimension_type")
|
||||||
|
.expect("No dimension_type tag")
|
||||||
|
.as_compound()
|
||||||
|
.expect("dimension_type is not a compound")
|
||||||
|
.get("value")
|
||||||
|
.expect("No dimension_type value")
|
||||||
|
.as_list()
|
||||||
|
.expect("dimension_type value is not a list");
|
||||||
|
let dimension_type = dimension_types
|
||||||
|
.iter()
|
||||||
|
.find(|t| {
|
||||||
|
t.as_compound()
|
||||||
|
.expect("dimension_type value is not a compound")
|
||||||
|
.get("name")
|
||||||
|
.expect("No name tag")
|
||||||
|
.as_string()
|
||||||
|
.expect("name is not a string")
|
||||||
|
== p.dimension_type.to_string()
|
||||||
|
})
|
||||||
|
.expect(&format!("No dimension_type with name {}", p.dimension_type))
|
||||||
|
.as_compound()
|
||||||
|
.unwrap()
|
||||||
|
.get("element")
|
||||||
|
.expect("No element tag")
|
||||||
|
.as_compound()
|
||||||
|
.expect("element is not a compound");
|
||||||
let height = (*dimension_type
|
let height = (*dimension_type
|
||||||
.get("height")
|
.get("height")
|
||||||
.expect("No height tag")
|
.expect("No height tag")
|
||||||
.as_int()
|
.as_int()
|
||||||
.expect("height tag is not int"))
|
.expect("height tag is not an int"))
|
||||||
.try_into()
|
.try_into()
|
||||||
.expect("height is not a u32");
|
.expect("height is not a u32");
|
||||||
let min_y = (*dimension_type
|
let min_y = (*dimension_type
|
||||||
.get("min_y")
|
.get("min_y")
|
||||||
.expect("No min_y tag")
|
.expect("No min_y tag")
|
||||||
.as_int()
|
.as_int()
|
||||||
.expect("min_y tag is not int"))
|
.expect("min_y tag is not an int"))
|
||||||
.try_into()
|
.try_into()
|
||||||
.expect("min_y is not an i32");
|
.expect("min_y is not an i32");
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,9 @@ mod slot;
|
||||||
pub use slot::{Slot, SlotData};
|
pub use slot::{Slot, SlotData};
|
||||||
|
|
||||||
mod position;
|
mod position;
|
||||||
pub use position::{BlockPos, ChunkBlockPos, ChunkPos, ChunkSectionBlockPos, ChunkSectionPos};
|
pub use position::{
|
||||||
|
BlockPos, ChunkBlockPos, ChunkPos, ChunkSectionBlockPos, ChunkSectionPos, GlobalPos,
|
||||||
|
};
|
||||||
|
|
||||||
mod direction;
|
mod direction;
|
||||||
pub use direction::Direction;
|
pub use direction::Direction;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
use std::ops::Rem;
|
use std::ops::Rem;
|
||||||
|
|
||||||
|
use crate::resource_location::ResourceLocation;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default)]
|
#[derive(Clone, Copy, Debug, Default)]
|
||||||
pub struct BlockPos {
|
pub struct BlockPos {
|
||||||
pub x: i32,
|
pub x: i32,
|
||||||
|
@ -137,6 +139,14 @@ impl From<&ChunkBlockPos> for ChunkSectionBlockPos {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A block pos with an attached dimension
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct GlobalPos {
|
||||||
|
pub pos: BlockPos,
|
||||||
|
// this is actually a ResourceKey in Minecraft, but i don't think it matters?
|
||||||
|
pub dimension: ResourceLocation,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
# Azalea NBT
|
# Azalea NBT
|
||||||
|
|
||||||
A fast NBT serializer and deserializer.
|
A fast NBT serializer and deserializer.
|
||||||
|
|
||||||
|
TODO: serde support for fast registry_holder parsing in azalea-client
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
InvalidTagType(u8),
|
InvalidTagType(u8),
|
||||||
InvalidTag,
|
InvalidTag,
|
||||||
WriteError,
|
WriteError(std::io::Error),
|
||||||
|
Utf8Error(std::string::FromUtf8Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for Error {
|
impl std::fmt::Display for Error {
|
||||||
|
@ -10,18 +11,19 @@ impl std::fmt::Display for Error {
|
||||||
match self {
|
match self {
|
||||||
Error::InvalidTagType(id) => write!(f, "Invalid tag type: {}", id),
|
Error::InvalidTagType(id) => write!(f, "Invalid tag type: {}", id),
|
||||||
Error::InvalidTag => write!(f, "Invalid tag"),
|
Error::InvalidTag => write!(f, "Invalid tag"),
|
||||||
Error::WriteError => write!(f, "Write error"),
|
Error::WriteError(e) => write!(f, "Write error: {}", e),
|
||||||
|
Error::Utf8Error(e) => write!(f, "Utf8 error: {}", e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<std::io::Error> for Error {
|
impl From<std::io::Error> for Error {
|
||||||
fn from(_: std::io::Error) -> Self {
|
fn from(e: std::io::Error) -> Self {
|
||||||
Error::WriteError
|
Error::WriteError(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl From<std::string::FromUtf8Error> for Error {
|
impl From<std::string::FromUtf8Error> for Error {
|
||||||
fn from(_: std::string::FromUtf8Error) -> Self {
|
fn from(e: std::string::FromUtf8Error) -> Self {
|
||||||
Error::WriteError
|
Error::Utf8Error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,13 +56,23 @@ fn create_impl_mcbufreadable(ident: &Ident, data: &Data) -> proc_macro2::TokenSt
|
||||||
}
|
}
|
||||||
syn::Data::Enum(syn::DataEnum { variants, .. }) => {
|
syn::Data::Enum(syn::DataEnum { variants, .. }) => {
|
||||||
let mut match_contents = quote!();
|
let mut match_contents = quote!();
|
||||||
|
let mut variant_discrim: usize = 0;
|
||||||
for variant in variants {
|
for variant in variants {
|
||||||
let variant_name = &variant.ident;
|
let variant_name = &variant.ident;
|
||||||
let variant_discrim = &variant
|
match &variant.discriminant.as_ref() {
|
||||||
.discriminant
|
Some(d) => {
|
||||||
.as_ref()
|
variant_discrim = match &d.1 {
|
||||||
.expect("enum variant must have a discriminant")
|
syn::Expr::Lit(e) => match &e.lit {
|
||||||
.1;
|
syn::Lit::Int(i) => i.base10_parse().unwrap(),
|
||||||
|
_ => panic!("Error parsing enum discriminant"),
|
||||||
|
},
|
||||||
|
_ => panic!("Error parsing enum discriminant"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
variant_discrim += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
match_contents.extend(quote! {
|
match_contents.extend(quote! {
|
||||||
#variant_discrim => Ok(Self::#variant_name),
|
#variant_discrim => Ok(Self::#variant_name),
|
||||||
});
|
});
|
||||||
|
@ -344,6 +354,7 @@ pub fn declare_state_packets(input: TokenStream) -> TokenStream {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
for PacketIdPair { id, module, name } in input.clientbound.packets {
|
for PacketIdPair { id, module, name } in input.clientbound.packets {
|
||||||
|
let name_litstr = syn::LitStr::new(&name.to_string(), name.span());
|
||||||
enum_contents.extend(quote! {
|
enum_contents.extend(quote! {
|
||||||
#name(#module::#name),
|
#name(#module::#name),
|
||||||
});
|
});
|
||||||
|
@ -354,7 +365,10 @@ pub fn declare_state_packets(input: TokenStream) -> TokenStream {
|
||||||
#state_name::#name(packet) => packet.write(buf),
|
#state_name::#name(packet) => packet.write(buf),
|
||||||
});
|
});
|
||||||
clientbound_read_match_contents.extend(quote! {
|
clientbound_read_match_contents.extend(quote! {
|
||||||
#id => #module::#name::read(buf)?,
|
#id => {
|
||||||
|
println!("reading packet {}", #name_litstr);
|
||||||
|
#module::#name::read(buf)?
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
//! This lib is responsible for parsing Minecraft packets.
|
//! This lib is responsible for parsing Minecraft packets.
|
||||||
|
|
||||||
#![feature(min_specialization)]
|
#![feature(min_specialization)]
|
||||||
|
#![feature(arbitrary_enum_discriminant)]
|
||||||
|
|
||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
|
@ -2,7 +2,8 @@ use super::{UnsizedByteArray, MAX_STRING_LENGTH};
|
||||||
use azalea_chat::component::Component;
|
use azalea_chat::component::Component;
|
||||||
use azalea_core::{
|
use azalea_core::{
|
||||||
difficulty::Difficulty, game_type::GameType, resource_location::ResourceLocation,
|
difficulty::Difficulty, game_type::GameType, resource_location::ResourceLocation,
|
||||||
serializable_uuid::SerializableUuid, BlockPos, ChunkSectionPos, Direction, Slot, SlotData,
|
serializable_uuid::SerializableUuid, BlockPos, ChunkSectionPos, Direction, GlobalPos, Slot,
|
||||||
|
SlotData,
|
||||||
};
|
};
|
||||||
use azalea_crypto::SaltSignaturePair;
|
use azalea_crypto::SaltSignaturePair;
|
||||||
use byteorder::{ReadBytesExt, BE};
|
use byteorder::{ReadBytesExt, BE};
|
||||||
|
@ -481,6 +482,15 @@ impl McBufReadable for BlockPos {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl McBufReadable for GlobalPos {
|
||||||
|
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||||
|
Ok(GlobalPos {
|
||||||
|
pos: BlockPos::read_into(buf)?,
|
||||||
|
dimension: ResourceLocation::read_into(buf)?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl McBufReadable for Direction {
|
impl McBufReadable for Direction {
|
||||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||||
match buf.read_varint()? {
|
match buf.read_varint()? {
|
||||||
|
|
|
@ -2,7 +2,7 @@ use super::{UnsizedByteArray, MAX_STRING_LENGTH};
|
||||||
use azalea_chat::component::Component;
|
use azalea_chat::component::Component;
|
||||||
use azalea_core::{
|
use azalea_core::{
|
||||||
difficulty::Difficulty, game_type::GameType, resource_location::ResourceLocation,
|
difficulty::Difficulty, game_type::GameType, resource_location::ResourceLocation,
|
||||||
serializable_uuid::SerializableUuid, BlockPos, ChunkSectionPos, Direction, Slot,
|
serializable_uuid::SerializableUuid, BlockPos, ChunkSectionPos, Direction, GlobalPos, Slot,
|
||||||
};
|
};
|
||||||
use azalea_crypto::SaltSignaturePair;
|
use azalea_crypto::SaltSignaturePair;
|
||||||
use byteorder::{BigEndian, WriteBytesExt};
|
use byteorder::{BigEndian, WriteBytesExt};
|
||||||
|
@ -193,28 +193,24 @@ impl McBufWritable for Vec<u8> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// string
|
|
||||||
impl McBufWritable for String {
|
impl McBufWritable for String {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_utf(self)
|
buf.write_utf(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResourceLocation
|
|
||||||
impl McBufWritable for ResourceLocation {
|
impl McBufWritable for ResourceLocation {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_resource_location(self)
|
buf.write_resource_location(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// u32
|
|
||||||
impl McBufWritable for u32 {
|
impl McBufWritable for u32 {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
i16::write_into(&(*self as i16), buf)
|
i16::write_into(&(*self as i16), buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// u32 varint
|
|
||||||
impl McBufVarWritable for u32 {
|
impl McBufVarWritable for u32 {
|
||||||
fn var_write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn var_write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
i32::var_write_into(&(*self as i32), buf)
|
i32::var_write_into(&(*self as i32), buf)
|
||||||
|
@ -244,21 +240,18 @@ impl McBufVarWritable for u64 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// u16
|
|
||||||
impl McBufWritable for u16 {
|
impl McBufWritable for u16 {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
i16::write_into(&(*self as i16), buf)
|
i16::write_into(&(*self as i16), buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// u16 varint
|
|
||||||
impl McBufVarWritable for u16 {
|
impl McBufVarWritable for u16 {
|
||||||
fn var_write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn var_write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
i32::var_write_into(&(*self as i32), buf)
|
i32::var_write_into(&(*self as i32), buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vec<T> varint
|
|
||||||
impl<T: McBufVarWritable> McBufVarWritable for Vec<T> {
|
impl<T: McBufVarWritable> McBufVarWritable for Vec<T> {
|
||||||
fn var_write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn var_write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
u32::var_write_into(&(self.len() as u32), buf)?;
|
u32::var_write_into(&(self.len() as u32), buf)?;
|
||||||
|
@ -269,77 +262,66 @@ impl<T: McBufVarWritable> McBufVarWritable for Vec<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// u8
|
|
||||||
impl McBufWritable for u8 {
|
impl McBufWritable for u8 {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_byte(*self)
|
buf.write_byte(*self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// i16
|
|
||||||
impl McBufWritable for i16 {
|
impl McBufWritable for i16 {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
Writable::write_short(buf, *self)
|
Writable::write_short(buf, *self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// i64
|
|
||||||
impl McBufWritable for i64 {
|
impl McBufWritable for i64 {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
Writable::write_long(buf, *self)
|
Writable::write_long(buf, *self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// u64
|
|
||||||
impl McBufWritable for u64 {
|
impl McBufWritable for u64 {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
i64::write_into(&(*self as i64), buf)
|
i64::write_into(&(*self as i64), buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// bool
|
|
||||||
impl McBufWritable for bool {
|
impl McBufWritable for bool {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_boolean(*self)
|
buf.write_boolean(*self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// i8
|
|
||||||
impl McBufWritable for i8 {
|
impl McBufWritable for i8 {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_byte(*self as u8)
|
buf.write_byte(*self as u8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// f32
|
|
||||||
impl McBufWritable for f32 {
|
impl McBufWritable for f32 {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_float(*self)
|
buf.write_float(*self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// f64
|
|
||||||
impl McBufWritable for f64 {
|
impl McBufWritable for f64 {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_double(*self)
|
buf.write_double(*self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GameType
|
|
||||||
impl McBufWritable for GameType {
|
impl McBufWritable for GameType {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
u8::write_into(&self.to_id(), buf)
|
u8::write_into(&self.to_id(), buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Option<GameType>
|
|
||||||
impl McBufWritable for Option<GameType> {
|
impl McBufWritable for Option<GameType> {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_byte(GameType::to_optional_id(self) as u8)
|
buf.write_byte(GameType::to_optional_id(self) as u8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Option<String>
|
|
||||||
impl<T: McBufWritable> McBufWritable for Option<T> {
|
impl<T: McBufWritable> McBufWritable for Option<T> {
|
||||||
default fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
default fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
if let Some(s) = self {
|
if let Some(s) = self {
|
||||||
|
@ -352,21 +334,18 @@ impl<T: McBufWritable> McBufWritable for Option<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// azalea_nbt::Tag
|
|
||||||
impl McBufWritable for azalea_nbt::Tag {
|
impl McBufWritable for azalea_nbt::Tag {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_nbt(self)
|
buf.write_nbt(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Difficulty
|
|
||||||
impl McBufWritable for Difficulty {
|
impl McBufWritable for Difficulty {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
u8::write_into(&self.id(), buf)
|
u8::write_into(&self.id(), buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Component
|
|
||||||
impl McBufWritable for Component {
|
impl McBufWritable for Component {
|
||||||
// async fn read_into(buf: &mut impl Read) -> Result<Self, String>
|
// async fn read_into(buf: &mut impl Read) -> Result<Self, String>
|
||||||
// where
|
// where
|
||||||
|
@ -384,7 +363,6 @@ impl McBufWritable for Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Slot
|
|
||||||
impl McBufWritable for Slot {
|
impl McBufWritable for Slot {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
match self {
|
match self {
|
||||||
|
@ -400,7 +378,6 @@ impl McBufWritable for Slot {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Slot
|
|
||||||
impl McBufWritable for Uuid {
|
impl McBufWritable for Uuid {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_uuid(self)?;
|
buf.write_uuid(self)?;
|
||||||
|
@ -409,7 +386,6 @@ impl McBufWritable for Uuid {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlockPos
|
|
||||||
impl McBufWritable for BlockPos {
|
impl McBufWritable for BlockPos {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_long(
|
buf.write_long(
|
||||||
|
@ -420,14 +396,21 @@ impl McBufWritable for BlockPos {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Direction
|
impl McBufWritable for GlobalPos {
|
||||||
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
|
BlockPos::write_into(&self.pos, buf)?;
|
||||||
|
ResourceLocation::write_into(&self.dimension, buf)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl McBufWritable for Direction {
|
impl McBufWritable for Direction {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_varint(*self as i32)
|
buf.write_varint(*self as i32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChunkSectionPos
|
|
||||||
impl McBufWritable for ChunkSectionPos {
|
impl McBufWritable for ChunkSectionPos {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
let long = (((self.x & 0x3FFFFF) as i64) << 42)
|
let long = (((self.x & 0x3FFFFF) as i64) << 42)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use super::GamePacket;
|
use super::GamePacket;
|
||||||
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
||||||
use azalea_core::resource_location::ResourceLocation;
|
use azalea_core::resource_location::ResourceLocation;
|
||||||
|
use packet_macros::McBuf;
|
||||||
use std::{
|
use std::{
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
io::{Read, Write},
|
io::{Read, Write},
|
||||||
|
@ -110,6 +111,58 @@ impl McBufWritable for BrigadierString {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, McBuf)]
|
||||||
|
pub enum BrigadierParserType {
|
||||||
|
Bool = 0,
|
||||||
|
Double,
|
||||||
|
Float,
|
||||||
|
Integer,
|
||||||
|
Long,
|
||||||
|
String,
|
||||||
|
Entity,
|
||||||
|
GameProfile,
|
||||||
|
BlockPos,
|
||||||
|
ColumnPos,
|
||||||
|
Vec3,
|
||||||
|
Vec2,
|
||||||
|
BlockState,
|
||||||
|
BlockPredicate,
|
||||||
|
ItemStack,
|
||||||
|
ItemPredicate,
|
||||||
|
Color,
|
||||||
|
Component,
|
||||||
|
Message,
|
||||||
|
Nbt,
|
||||||
|
NbtPath,
|
||||||
|
Objective,
|
||||||
|
ObjectiveCriteira,
|
||||||
|
Operation,
|
||||||
|
Particle,
|
||||||
|
Rotation,
|
||||||
|
Angle,
|
||||||
|
ScoreboardSlot,
|
||||||
|
ScoreHolder,
|
||||||
|
Swizzle,
|
||||||
|
Team,
|
||||||
|
ItemSlot,
|
||||||
|
ResourceLocation,
|
||||||
|
MobEffect,
|
||||||
|
Function,
|
||||||
|
EntityAnchor,
|
||||||
|
Range,
|
||||||
|
IntRange,
|
||||||
|
FloatRange,
|
||||||
|
ItemEnchantment,
|
||||||
|
EntitySummon,
|
||||||
|
Dimension,
|
||||||
|
Uuid,
|
||||||
|
NbtTag,
|
||||||
|
NbtCompoundTag,
|
||||||
|
Time,
|
||||||
|
ResourceOrTag,
|
||||||
|
Resource,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum BrigadierParser {
|
pub enum BrigadierParser {
|
||||||
Bool,
|
Bool,
|
||||||
|
@ -164,119 +217,84 @@ pub enum BrigadierParser {
|
||||||
|
|
||||||
impl McBufReadable for BrigadierParser {
|
impl McBufReadable for BrigadierParser {
|
||||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||||
let parser = buf.read_resource_location()?;
|
let parser_type = BrigadierParserType::read_into(buf)?;
|
||||||
|
|
||||||
if parser == ResourceLocation::new("brigadier:bool")? {
|
match parser_type {
|
||||||
Ok(BrigadierParser::Bool)
|
BrigadierParserType::Bool => Ok(BrigadierParser::Bool),
|
||||||
} else if parser == ResourceLocation::new("brigadier:double")? {
|
BrigadierParserType::Double => {
|
||||||
Ok(BrigadierParser::Double(BrigadierNumber::read_into(buf)?))
|
Ok(BrigadierParser::Double(BrigadierNumber::read_into(buf)?))
|
||||||
} else if parser == ResourceLocation::new("brigadier:float")? {
|
}
|
||||||
Ok(BrigadierParser::Float(BrigadierNumber::read_into(buf)?))
|
BrigadierParserType::Float => {
|
||||||
} else if parser == ResourceLocation::new("brigadier:integer")? {
|
Ok(BrigadierParser::Float(BrigadierNumber::read_into(buf)?))
|
||||||
Ok(BrigadierParser::Integer(BrigadierNumber::read_into(buf)?))
|
}
|
||||||
} else if parser == ResourceLocation::new("brigadier:long")? {
|
BrigadierParserType::Integer => {
|
||||||
Ok(BrigadierParser::Long(BrigadierNumber::read_into(buf)?))
|
Ok(BrigadierParser::Integer(BrigadierNumber::read_into(buf)?))
|
||||||
} else if parser == ResourceLocation::new("brigadier:string")? {
|
}
|
||||||
Ok(BrigadierParser::String(BrigadierString::read_into(buf)?))
|
BrigadierParserType::Long => {
|
||||||
} else if parser == ResourceLocation::new("minecraft:entity")? {
|
Ok(BrigadierParser::Long(BrigadierNumber::read_into(buf)?))
|
||||||
let flags = buf.read_byte()?;
|
}
|
||||||
Ok(BrigadierParser::Entity {
|
BrigadierParserType::String => {
|
||||||
single: flags & 0x01 != 0,
|
Ok(BrigadierParser::String(BrigadierString::read_into(buf)?))
|
||||||
players_only: flags & 0x02 != 0,
|
}
|
||||||
})
|
BrigadierParserType::Entity {
|
||||||
} else if parser == ResourceLocation::new("minecraft:game_profile")? {
|
single,
|
||||||
Ok(BrigadierParser::GameProfile)
|
players_only,
|
||||||
} else if parser == ResourceLocation::new("minecraft:block_pos")? {
|
} => Ok(BrigadierParser::Entity {
|
||||||
Ok(BrigadierParser::BlockPos)
|
single,
|
||||||
} else if parser == ResourceLocation::new("minecraft:column_pos")? {
|
players_only,
|
||||||
Ok(BrigadierParser::ColumnPos)
|
}),
|
||||||
} else if parser == ResourceLocation::new("minecraft:vec3")? {
|
BrigadierParserType::GameProfile => Ok(BrigadierParser::GameProfile),
|
||||||
Ok(BrigadierParser::Vec3)
|
BrigadierParserType::BlockPos => Ok(BrigadierParser::BlockPos),
|
||||||
} else if parser == ResourceLocation::new("minecraft:vec2")? {
|
BrigadierParserType::ColumnPos => Ok(BrigadierParser::ColumnPos),
|
||||||
Ok(BrigadierParser::Vec2)
|
BrigadierParserType::Vec3 => Ok(BrigadierParser::Vec3),
|
||||||
} else if parser == ResourceLocation::new("minecraft:block_state")? {
|
BrigadierParserType::Vec2 => Ok(BrigadierParser::Vec2),
|
||||||
Ok(BrigadierParser::BlockState)
|
BrigadierParserType::BlockState => Ok(BrigadierParser::BlockState),
|
||||||
} else if parser == ResourceLocation::new("minecraft:block_predicate")? {
|
BrigadierParserType::BlockPredicate => Ok(BrigadierParser::BlockPredicate),
|
||||||
Ok(BrigadierParser::BlockPredicate)
|
BrigadierParserType::ItemStack => Ok(BrigadierParser::ItemStack),
|
||||||
} else if parser == ResourceLocation::new("minecraft:item_stack")? {
|
BrigadierParserType::ItemPredicate => Ok(BrigadierParser::ItemPredicate),
|
||||||
Ok(BrigadierParser::ItemStack)
|
BrigadierParserType::Color => Ok(BrigadierParser::Color),
|
||||||
} else if parser == ResourceLocation::new("minecraft:item_predicate")? {
|
BrigadierParserType::Component => Ok(BrigadierParser::Component),
|
||||||
Ok(BrigadierParser::ItemPredicate)
|
BrigadierParserType::Message => Ok(BrigadierParser::Message),
|
||||||
} else if parser == ResourceLocation::new("minecraft:color")? {
|
BrigadierParserType::Nbt => Ok(BrigadierParser::Nbt),
|
||||||
Ok(BrigadierParser::Color)
|
BrigadierParserType::NbtPath => Ok(BrigadierParser::NbtPath),
|
||||||
} else if parser == ResourceLocation::new("minecraft:component")? {
|
BrigadierParserType::Objective => Ok(BrigadierParser::Objective),
|
||||||
Ok(BrigadierParser::Component)
|
BrigadierParserType::ObjectiveCriteira => Ok(BrigadierParser::ObjectiveCriteira),
|
||||||
} else if parser == ResourceLocation::new("minecraft:message")? {
|
BrigadierParserType::Operation => Ok(BrigadierParser::Operation),
|
||||||
Ok(BrigadierParser::Message)
|
BrigadierParserType::Particle => Ok(BrigadierParser::Particle),
|
||||||
} else if parser == ResourceLocation::new("minecraft:nbt")? {
|
BrigadierParserType::Rotation => Ok(BrigadierParser::Rotation),
|
||||||
Ok(BrigadierParser::Nbt)
|
BrigadierParserType::Angle => Ok(BrigadierParser::Angle),
|
||||||
} else if parser == ResourceLocation::new("minecraft:nbt_path")? {
|
BrigadierParserType::ScoreboardSlot => Ok(BrigadierParser::ScoreboardSlot),
|
||||||
Ok(BrigadierParser::NbtPath)
|
BrigadierParserType::ScoreHolder => {
|
||||||
} else if parser == ResourceLocation::new("minecraft:objective")? {
|
let flags = buf.read_byte()?;
|
||||||
Ok(BrigadierParser::Objective)
|
Ok(BrigadierParser::ScoreHolder {
|
||||||
} else if parser == ResourceLocation::new("minecraft:objective_criteria")? {
|
allows_multiple: flags & 0x01 != 0,
|
||||||
Ok(BrigadierParser::ObjectiveCriteira)
|
})
|
||||||
} else if parser == ResourceLocation::new("minecraft:operation")? {
|
}
|
||||||
Ok(BrigadierParser::Operation)
|
BrigadierParserType::Swizzle => Ok(BrigadierParser::Swizzle),
|
||||||
} else if parser == ResourceLocation::new("minecraft:particle")? {
|
BrigadierParserType::Team => Ok(BrigadierParser::Team),
|
||||||
Ok(BrigadierParser::Particle)
|
BrigadierParserType::ItemSlot => Ok(BrigadierParser::ItemSlot),
|
||||||
} else if parser == ResourceLocation::new("minecraft:rotation")? {
|
BrigadierParserType::ResourceLocation => Ok(BrigadierParser::ResourceLocation),
|
||||||
Ok(BrigadierParser::Rotation)
|
BrigadierParserType::MobEffect => Ok(BrigadierParser::MobEffect),
|
||||||
} else if parser == ResourceLocation::new("minecraft:angle")? {
|
BrigadierParserType::Function => Ok(BrigadierParser::Function),
|
||||||
Ok(BrigadierParser::Angle)
|
BrigadierParserType::EntityAnchor => Ok(BrigadierParser::EntityAnchor),
|
||||||
} else if parser == ResourceLocation::new("minecraft:scoreboard_slot")? {
|
BrigadierParserType::Range => Ok(BrigadierParser::Range {
|
||||||
Ok(BrigadierParser::ScoreboardSlot)
|
|
||||||
} else if parser == ResourceLocation::new("minecraft:score_holder")? {
|
|
||||||
let flags = buf.read_byte()?;
|
|
||||||
Ok(BrigadierParser::ScoreHolder {
|
|
||||||
allows_multiple: flags & 0x01 != 0,
|
|
||||||
})
|
|
||||||
} else if parser == ResourceLocation::new("minecraft:swizzle")? {
|
|
||||||
Ok(BrigadierParser::Swizzle)
|
|
||||||
} else if parser == ResourceLocation::new("minecraft:team")? {
|
|
||||||
Ok(BrigadierParser::Team)
|
|
||||||
} else if parser == ResourceLocation::new("minecraft:item_slot")? {
|
|
||||||
Ok(BrigadierParser::ItemSlot)
|
|
||||||
} else if parser == ResourceLocation::new("minecraft:resource_location")? {
|
|
||||||
Ok(BrigadierParser::ResourceLocation)
|
|
||||||
} else if parser == ResourceLocation::new("minecraft:mob_effect")? {
|
|
||||||
Ok(BrigadierParser::MobEffect)
|
|
||||||
} else if parser == ResourceLocation::new("minecraft:function")? {
|
|
||||||
Ok(BrigadierParser::Function)
|
|
||||||
} else if parser == ResourceLocation::new("minecraft:entity_anchor")? {
|
|
||||||
Ok(BrigadierParser::EntityAnchor)
|
|
||||||
} else if parser == ResourceLocation::new("minecraft:range")? {
|
|
||||||
Ok(BrigadierParser::Range {
|
|
||||||
decimals_allowed: buf.read_boolean()?,
|
decimals_allowed: buf.read_boolean()?,
|
||||||
})
|
}),
|
||||||
} else if parser == ResourceLocation::new("minecraft:int_range")? {
|
BrigadierParserType::IntRange => Ok(BrigadierParser::IntRange),
|
||||||
Ok(BrigadierParser::IntRange)
|
BrigadierParserType::FloatRange => Ok(BrigadierParser::FloatRange),
|
||||||
} else if parser == ResourceLocation::new("minecraft:float_range")? {
|
BrigadierParserType::ItemEnchantment => Ok(BrigadierParser::ItemEnchantment),
|
||||||
Ok(BrigadierParser::FloatRange)
|
BrigadierParserType::EntitySummon => Ok(BrigadierParser::EntitySummon),
|
||||||
} else if parser == ResourceLocation::new("minecraft:item_enchantment")? {
|
BrigadierParserType::Dimension => Ok(BrigadierParser::Dimension),
|
||||||
Ok(BrigadierParser::ItemEnchantment)
|
BrigadierParserType::Uuid => Ok(BrigadierParser::Uuid),
|
||||||
} else if parser == ResourceLocation::new("minecraft:entity_summon")? {
|
BrigadierParserType::NbtTag => Ok(BrigadierParser::NbtTag),
|
||||||
Ok(BrigadierParser::EntitySummon)
|
BrigadierParserType::NbtCompoundTag => Ok(BrigadierParser::NbtCompoundTag),
|
||||||
} else if parser == ResourceLocation::new("minecraft:dimension")? {
|
BrigadierParserType::Time => Ok(BrigadierParser::Time),
|
||||||
Ok(BrigadierParser::Dimension)
|
BrigadierParserType::ResourceOrTag => Ok(BrigadierParser::ResourceOrTag {
|
||||||
} else if parser == ResourceLocation::new("minecraft:uuid")? {
|
|
||||||
Ok(BrigadierParser::Uuid)
|
|
||||||
} else if parser == ResourceLocation::new("minecraft:nbt_tag")? {
|
|
||||||
Ok(BrigadierParser::NbtTag)
|
|
||||||
} else if parser == ResourceLocation::new("minecraft:nbt_compound_tag")? {
|
|
||||||
Ok(BrigadierParser::NbtCompoundTag)
|
|
||||||
} else if parser == ResourceLocation::new("minecraft:time")? {
|
|
||||||
Ok(BrigadierParser::Time)
|
|
||||||
} else if parser == ResourceLocation::new("minecraft:resource_or_tag")? {
|
|
||||||
Ok(BrigadierParser::ResourceOrTag {
|
|
||||||
registry_key: buf.read_resource_location()?,
|
registry_key: buf.read_resource_location()?,
|
||||||
})
|
}),
|
||||||
} else if parser == ResourceLocation::new("minecraft:resource")? {
|
BrigadierParserType::Resource => Ok(BrigadierParser::Resource {
|
||||||
Ok(BrigadierParser::Resource {
|
|
||||||
registry_key: buf.read_resource_location()?,
|
registry_key: buf.read_resource_location()?,
|
||||||
})
|
}),
|
||||||
} else {
|
|
||||||
panic!("Unknown Brigadier parser: {}", parser)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use azalea_core::{game_type::GameType, resource_location::ResourceLocation};
|
use azalea_core::{game_type::GameType, resource_location::ResourceLocation, GlobalPos};
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use packet_macros::{GamePacket, McBuf};
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
|
@ -9,7 +9,7 @@ pub struct ClientboundLoginPacket {
|
||||||
pub previous_game_type: Option<GameType>,
|
pub previous_game_type: Option<GameType>,
|
||||||
pub levels: Vec<ResourceLocation>,
|
pub levels: Vec<ResourceLocation>,
|
||||||
pub registry_holder: azalea_nbt::Tag,
|
pub registry_holder: azalea_nbt::Tag,
|
||||||
pub dimension_type: azalea_nbt::Tag,
|
pub dimension_type: ResourceLocation,
|
||||||
pub dimension: ResourceLocation,
|
pub dimension: ResourceLocation,
|
||||||
pub seed: i64,
|
pub seed: i64,
|
||||||
#[var]
|
#[var]
|
||||||
|
@ -22,4 +22,5 @@ pub struct ClientboundLoginPacket {
|
||||||
pub show_death_screen: bool,
|
pub show_death_screen: bool,
|
||||||
pub is_debug: bool,
|
pub is_debug: bool,
|
||||||
pub is_flat: bool,
|
pub is_flat: bool,
|
||||||
|
pub last_death_location: Option<GlobalPos>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,37 +1,11 @@
|
||||||
use std::{
|
use packet_macros::LoginPacket;
|
||||||
hash::Hash,
|
use packet_macros::McBuf;
|
||||||
io::{Read, Write},
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::LoginPacket;
|
#[derive(Clone, Debug, McBuf, LoginPacket)]
|
||||||
use crate::mc_buf::Readable;
|
|
||||||
|
|
||||||
#[derive(Hash, Clone, Debug)]
|
|
||||||
pub struct ClientboundHelloPacket {
|
pub struct ClientboundHelloPacket {
|
||||||
|
// TODO: make this len thing work
|
||||||
|
// #[len(20)]
|
||||||
pub server_id: String,
|
pub server_id: String,
|
||||||
pub public_key: Vec<u8>,
|
pub public_key: Vec<u8>,
|
||||||
pub nonce: Vec<u8>,
|
pub nonce: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ClientboundHelloPacket {
|
|
||||||
pub fn get(self) -> LoginPacket {
|
|
||||||
LoginPacket::ClientboundHelloPacket(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn write(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> {
|
|
||||||
panic!("ClientboundHelloPacket::write not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn read(buf: &mut impl Read) -> Result<LoginPacket, String> {
|
|
||||||
let server_id = buf.read_utf_with_len(20)?;
|
|
||||||
let public_key = buf.read_byte_array()?;
|
|
||||||
let nonce = buf.read_byte_array()?;
|
|
||||||
|
|
||||||
Ok(ClientboundHelloPacket {
|
|
||||||
server_id,
|
|
||||||
public_key,
|
|
||||||
nonce,
|
|
||||||
}
|
|
||||||
.get())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,8 +1,49 @@
|
||||||
|
use azalea_crypto::SaltSignaturePair;
|
||||||
use packet_macros::{LoginPacket, McBuf};
|
use packet_macros::{LoginPacket, McBuf};
|
||||||
use std::hash::Hash;
|
use std::{
|
||||||
|
hash::Hash,
|
||||||
|
io::{Read, Write},
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Hash, Clone, Debug, McBuf, LoginPacket)]
|
use crate::mc_buf::{McBufReadable, McBufWritable};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, McBuf, LoginPacket)]
|
||||||
pub struct ServerboundKeyPacket {
|
pub struct ServerboundKeyPacket {
|
||||||
pub shared_secret: Vec<u8>,
|
pub key_bytes: Vec<u8>,
|
||||||
pub nonce: Vec<u8>,
|
pub nonce_or_salt_signature: NonceOrSaltSignature,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum NonceOrSaltSignature {
|
||||||
|
Nonce(Vec<u8>),
|
||||||
|
SaltSignature(SaltSignaturePair),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl McBufReadable for NonceOrSaltSignature {
|
||||||
|
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||||
|
let is_nonce = bool::read_into(buf)?;
|
||||||
|
if is_nonce {
|
||||||
|
Ok(NonceOrSaltSignature::Nonce(Vec::<u8>::read_into(buf)?))
|
||||||
|
} else {
|
||||||
|
Ok(NonceOrSaltSignature::SaltSignature(
|
||||||
|
SaltSignaturePair::read_into(buf)?,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl McBufWritable for NonceOrSaltSignature {
|
||||||
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
|
match self {
|
||||||
|
NonceOrSaltSignature::Nonce(nonce) => {
|
||||||
|
bool::write_into(&true, buf)?;
|
||||||
|
nonce.write_into(buf)?;
|
||||||
|
}
|
||||||
|
NonceOrSaltSignature::SaltSignature(salt_signature) => {
|
||||||
|
bool::write_into(&false, buf)?;
|
||||||
|
salt_signature.write_into(buf)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue