diff options
Diffstat (limited to 'azalea-protocol/src/packets/game')
20 files changed, 700 insertions, 825 deletions
diff --git a/azalea-protocol/src/packets/game/clientbound_commands_packet.rs b/azalea-protocol/src/packets/game/clientbound_commands_packet.rs index dcaf8d66..ce578176 100755 --- a/azalea-protocol/src/packets/game/clientbound_commands_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_commands_packet.rs @@ -79,15 +79,15 @@ pub enum BrigadierString { GreedyPhrase = 2, } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, McBuf)] pub enum BrigadierParser { Bool, - Double(BrigadierNumber<f64>), Float(BrigadierNumber<f32>), + Double(BrigadierNumber<f64>), Integer(BrigadierNumber<i32>), Long(BrigadierNumber<i64>), String(BrigadierString), - Entity { single: bool, players_only: bool }, + Entity(EntityParser), GameProfile, BlockPos, ColumnPos, @@ -100,283 +100,61 @@ pub enum BrigadierParser { Color, Component, Message, - Nbt, + NbtCompoundTag, + NbtTag, NbtPath, Objective, - ObjectiveCriteira, + ObjectiveCriteria, Operation, Particle, - Rotation, Angle, + Rotation, ScoreboardSlot, ScoreHolder { allows_multiple: bool }, Swizzle, Team, ItemSlot, ResourceLocation, - MobEffect, Function, EntityAnchor, IntRange, FloatRange, - ItemEnchantment, - EntitySummon, Dimension, - Uuid, - NbtTag, + GameMode, Time, ResourceOrTag { registry_key: ResourceLocation }, + ResourceOrTagKey { registry_key: ResourceLocation }, Resource { registry_key: ResourceLocation }, + ResourceKey { registry_key: ResourceLocation }, TemplateMirror, TemplateRotation, + Uuid, } -impl McBufReadable for BrigadierParser { +#[derive(Debug, Clone)] +pub struct EntityParser { + pub single: bool, + pub players_only: bool, +} +impl McBufReadable for EntityParser { fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { - let parser_type = u32::var_read_from(buf)?; - - match parser_type { - 0 => Ok(BrigadierParser::Bool), - 1 => Ok(BrigadierParser::Float(BrigadierNumber::read_from(buf)?)), - 2 => Ok(BrigadierParser::Double(BrigadierNumber::read_from(buf)?)), - 3 => Ok(BrigadierParser::Integer(BrigadierNumber::read_from(buf)?)), - 4 => Ok(BrigadierParser::Long(BrigadierNumber::read_from(buf)?)), - 5 => Ok(BrigadierParser::String(BrigadierString::read_from(buf)?)), - 6 => { - let flags = u8::read_from(buf)?; - Ok(BrigadierParser::Entity { - single: flags & 0x01 != 0, - players_only: flags & 0x02 != 0, - }) - } - 7 => Ok(BrigadierParser::GameProfile), - 8 => Ok(BrigadierParser::BlockPos), - 9 => Ok(BrigadierParser::ColumnPos), - 10 => Ok(BrigadierParser::Vec3), - 11 => Ok(BrigadierParser::Vec2), - 12 => Ok(BrigadierParser::BlockState), - 13 => Ok(BrigadierParser::BlockPredicate), - 14 => Ok(BrigadierParser::ItemStack), - 15 => Ok(BrigadierParser::ItemPredicate), - 16 => Ok(BrigadierParser::Color), - 17 => Ok(BrigadierParser::Component), - 18 => Ok(BrigadierParser::Message), - 19 => Ok(BrigadierParser::Nbt), - 20 => Ok(BrigadierParser::NbtTag), - 21 => Ok(BrigadierParser::NbtPath), - 22 => Ok(BrigadierParser::Objective), - 23 => Ok(BrigadierParser::ObjectiveCriteira), - 24 => Ok(BrigadierParser::Operation), - 25 => Ok(BrigadierParser::Particle), - 26 => Ok(BrigadierParser::Angle), - 27 => Ok(BrigadierParser::Rotation), - 28 => Ok(BrigadierParser::ScoreboardSlot), - 29 => { - let flags = u8::read_from(buf)?; - Ok(BrigadierParser::ScoreHolder { - allows_multiple: flags & 0x01 != 0, - }) - } - 30 => Ok(BrigadierParser::Swizzle), - 31 => Ok(BrigadierParser::Team), - 32 => Ok(BrigadierParser::ItemSlot), - 33 => Ok(BrigadierParser::ResourceLocation), - 34 => Ok(BrigadierParser::MobEffect), - 35 => Ok(BrigadierParser::Function), - 36 => Ok(BrigadierParser::EntityAnchor), - 37 => Ok(BrigadierParser::IntRange), - 38 => Ok(BrigadierParser::FloatRange), - 39 => Ok(BrigadierParser::ItemEnchantment), - 40 => Ok(BrigadierParser::EntitySummon), - 41 => Ok(BrigadierParser::Dimension), - 42 => Ok(BrigadierParser::Time), - 43 => Ok(BrigadierParser::ResourceOrTag { - registry_key: ResourceLocation::read_from(buf)?, - }), - 44 => Ok(BrigadierParser::Resource { - registry_key: ResourceLocation::read_from(buf)?, - }), - 45 => Ok(BrigadierParser::TemplateMirror), - 46 => Ok(BrigadierParser::TemplateRotation), - 47 => Ok(BrigadierParser::Uuid), - _ => Err(BufReadError::UnexpectedEnumVariant { - id: parser_type as i32, - }), - } + let flags = u8::read_from(buf)?; + Ok(EntityParser { + single: flags & 0x01 != 0, + players_only: flags & 0x02 != 0, + }) } } - -impl McBufWritable for BrigadierParser { +impl McBufWritable for EntityParser { fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { - match &self { - BrigadierParser::Bool => { - u32::var_write_into(&0, buf)?; - } - BrigadierParser::Float(f) => { - u32::var_write_into(&1, buf)?; - f.write_into(buf)?; - } - BrigadierParser::Double(d) => { - u32::var_write_into(&2, buf)?; - d.write_into(buf)?; - } - BrigadierParser::Integer(i) => { - u32::var_write_into(&3, buf)?; - i.write_into(buf)?; - } - BrigadierParser::Long(l) => { - u32::var_write_into(&4, buf)?; - l.write_into(buf)?; - } - BrigadierParser::String(s) => { - u32::var_write_into(&5, buf)?; - s.write_into(buf)?; - } - BrigadierParser::Entity { - single, - players_only, - } => { - u32::var_write_into(&6, buf)?; - let mut bitmask: u8 = 0x00; - if *single { - bitmask |= 0x01; - } - if *players_only { - bitmask |= 0x02; - } - bitmask.write_into(buf)?; - } - BrigadierParser::GameProfile => { - u32::var_write_into(&7, buf)?; - } - BrigadierParser::BlockPos => { - u32::var_write_into(&8, buf)?; - } - BrigadierParser::ColumnPos => { - u32::var_write_into(&9, buf)?; - } - BrigadierParser::Vec3 => { - u32::var_write_into(&10, buf)?; - } - BrigadierParser::Vec2 => { - u32::var_write_into(&11, buf)?; - } - BrigadierParser::BlockState => { - u32::var_write_into(&12, buf)?; - } - BrigadierParser::BlockPredicate => { - u32::var_write_into(&13, buf)?; - } - BrigadierParser::ItemStack => { - u32::var_write_into(&14, buf)?; - } - BrigadierParser::ItemPredicate => { - u32::var_write_into(&15, buf)?; - } - BrigadierParser::Color => { - u32::var_write_into(&16, buf)?; - } - BrigadierParser::Component => { - u32::var_write_into(&17, buf)?; - } - BrigadierParser::Message => { - u32::var_write_into(&18, buf)?; - } - BrigadierParser::Nbt => { - u32::var_write_into(&19, buf)?; - } - BrigadierParser::NbtTag => { - u32::var_write_into(&20, buf)?; - } - BrigadierParser::NbtPath => { - u32::var_write_into(&21, buf)?; - } - BrigadierParser::Objective => { - u32::var_write_into(&22, buf)?; - } - BrigadierParser::ObjectiveCriteira => { - u32::var_write_into(&23, buf)?; - } - BrigadierParser::Operation => { - u32::var_write_into(&24, buf)?; - } - BrigadierParser::Particle => { - u32::var_write_into(&25, buf)?; - } - BrigadierParser::Angle => { - u32::var_write_into(&26, buf)?; - } - BrigadierParser::Rotation => { - u32::var_write_into(&27, buf)?; - } - BrigadierParser::ScoreboardSlot => { - u32::var_write_into(&28, buf)?; - } - BrigadierParser::ScoreHolder { allows_multiple } => { - u32::var_write_into(&29, buf)?; - if *allows_multiple { - buf.write_all(&[0x01])?; - } else { - buf.write_all(&[0x00])?; - } - } - BrigadierParser::Swizzle => { - u32::var_write_into(&30, buf)?; - } - BrigadierParser::Team => { - u32::var_write_into(&31, buf)?; - } - BrigadierParser::ItemSlot => { - u32::var_write_into(&32, buf)?; - } - BrigadierParser::ResourceLocation => { - u32::var_write_into(&33, buf)?; - } - BrigadierParser::MobEffect => { - u32::var_write_into(&34, buf)?; - } - BrigadierParser::Function => { - u32::var_write_into(&35, buf)?; - } - BrigadierParser::EntityAnchor => { - u32::var_write_into(&36, buf)?; - } - BrigadierParser::IntRange => { - u32::var_write_into(&37, buf)?; - } - BrigadierParser::FloatRange => { - u32::var_write_into(&38, buf)?; - } - BrigadierParser::ItemEnchantment => { - u32::var_write_into(&39, buf)?; - } - BrigadierParser::EntitySummon => { - u32::var_write_into(&40, buf)?; - } - BrigadierParser::Dimension => { - u32::var_write_into(&41, buf)?; - } - BrigadierParser::Time => { - u32::var_write_into(&42, buf)?; - } - BrigadierParser::ResourceOrTag { registry_key } => { - u32::var_write_into(&43, buf)?; - registry_key.write_into(buf)?; - } - BrigadierParser::Resource { registry_key } => { - u32::var_write_into(&44, buf)?; - registry_key.write_into(buf)?; - } - BrigadierParser::TemplateMirror => { - u32::var_write_into(&45, buf)?; - } - BrigadierParser::TemplateRotation => { - u32::var_write_into(&46, buf)?; - } - BrigadierParser::Uuid => { - u32::var_write_into(&47, buf)?; - } + let mut flags: u8 = 0; + if self.single { + flags |= 0x01; + } + if self.players_only { + flags |= 0x02; } + flags.write_into(buf)?; Ok(()) } } @@ -412,7 +190,7 @@ impl McBufReadable for BrigadierNodeStub { } else { None }; - return Ok(BrigadierNodeStub { + let node = BrigadierNodeStub { is_executable, children, redirect_node, @@ -421,10 +199,11 @@ impl McBufReadable for BrigadierNodeStub { parser, suggestions_type, }, - }); + }; + return Ok(node); } // literal node - if node_type == 1 { + else if node_type == 1 { let name = String::read_from(buf)?; return Ok(BrigadierNodeStub { is_executable, diff --git a/azalea-protocol/src/packets/game/clientbound_custom_sound_packet.rs b/azalea-protocol/src/packets/game/clientbound_custom_sound_packet.rs deleted file mode 100755 index 2f7aa28e..00000000 --- a/azalea-protocol/src/packets/game/clientbound_custom_sound_packet.rs +++ /dev/null @@ -1,20 +0,0 @@ -use azalea_buf::McBuf; -use azalea_core::ResourceLocation; -use azalea_protocol_macros::ClientboundGamePacket; - -use super::clientbound_sound_packet::SoundSource; - -#[derive(Clone, Debug, McBuf, ClientboundGamePacket)] -pub struct ClientboundCustomSoundPacket { - pub name: ResourceLocation, - pub source: SoundSource, - /// x position multiplied by 8 - pub x: i32, - /// y position multiplied by 8 - pub y: i32, - /// z position multiplied by 8 - pub z: i32, - pub volume: f32, - pub pitch: f32, - pub seed: u64, -} diff --git a/azalea-protocol/src/packets/game/clientbound_delete_chat_packet.rs b/azalea-protocol/src/packets/game/clientbound_delete_chat_packet.rs index 6f1a3665..b8377afe 100755 --- a/azalea-protocol/src/packets/game/clientbound_delete_chat_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_delete_chat_packet.rs @@ -1,8 +1,8 @@ +use super::clientbound_player_chat_packet::PackedMessageSignature; use azalea_buf::McBuf; -use azalea_crypto::MessageSignature; use azalea_protocol_macros::ClientboundGamePacket; #[derive(Clone, Debug, McBuf, ClientboundGamePacket)] pub struct ClientboundDeleteChatPacket { - pub message_signature: MessageSignature, + pub signature: PackedMessageSignature, } diff --git a/azalea-protocol/src/packets/game/clientbound_disguised_chat_packet.rs b/azalea-protocol/src/packets/game/clientbound_disguised_chat_packet.rs new file mode 100644 index 00000000..701284a0 --- /dev/null +++ b/azalea-protocol/src/packets/game/clientbound_disguised_chat_packet.rs @@ -0,0 +1,10 @@ +use super::clientbound_player_chat_packet::ChatTypeBound; +use azalea_buf::McBuf; +use azalea_chat::Component; +use azalea_protocol_macros::ClientboundGamePacket; + +#[derive(Clone, Debug, McBuf, ClientboundGamePacket)] +pub struct ClientboundDisguisedChatPacket { + pub message: Component, + pub chat_type: ChatTypeBound, +} diff --git a/azalea-protocol/src/packets/game/clientbound_explode_packet.rs b/azalea-protocol/src/packets/game/clientbound_explode_packet.rs index 10a9e9a9..58070769 100755 --- a/azalea-protocol/src/packets/game/clientbound_explode_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_explode_packet.rs @@ -1,13 +1,14 @@ +use std::io::{Cursor, Write}; + use azalea_buf::{BufReadError, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable}; use azalea_core::BlockPos; use azalea_protocol_macros::ClientboundGamePacket; -use std::io::{Cursor, Write}; #[derive(Clone, Debug, PartialEq, ClientboundGamePacket)] pub struct ClientboundExplodePacket { - pub x: f32, - pub y: f32, - pub z: f32, + pub x: f64, + pub y: f64, + pub z: f64, pub power: f32, pub to_blow: Vec<BlockPos>, pub knockback_x: f32, @@ -17,9 +18,9 @@ pub struct ClientboundExplodePacket { impl McBufReadable for ClientboundExplodePacket { fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { - let x = f32::read_from(buf)?; - let y = f32::read_from(buf)?; - let z = f32::read_from(buf)?; + let x = f64::read_from(buf)?; + let y = f64::read_from(buf)?; + let z = f64::read_from(buf)?; let power = f32::read_from(buf)?; let x_floor = x.floor() as i32; diff --git a/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs index 0e271e3d..f22fb608 100755..100644 --- a/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs @@ -1,19 +1,57 @@ -use azalea_buf::McBuf; +use azalea_buf::{ + BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable, +}; use azalea_chat::{ translatable_component::{StringOrComponent, TranslatableComponent}, Component, }; use azalea_core::BitSet; -use azalea_crypto::{MessageSignature, SignedMessageHeader}; +use azalea_crypto::MessageSignature; use azalea_protocol_macros::ClientboundGamePacket; +use std::io::{Cursor, Write}; use uuid::Uuid; #[derive(Clone, Debug, McBuf, ClientboundGamePacket, PartialEq)] pub struct ClientboundPlayerChatPacket { - pub message: PlayerChatMessage, + pub sender: Uuid, + #[var] + pub index: u32, + pub signature: Option<MessageSignature>, + pub body: PackedSignedMessageBody, + pub unsigned_content: Option<Component>, + pub filter_mask: FilterMask, pub chat_type: ChatTypeBound, } +#[derive(Clone, Debug, PartialEq, McBuf)] +pub struct PackedSignedMessageBody { + // the error is here, for some reason it skipped a byte earlier and here + // it's reading `0` when it should be `11` + pub content: String, + pub timestamp: u64, + pub salt: u64, + pub last_seen: PackedLastSeenMessages, +} + +#[derive(Clone, Debug, PartialEq, McBuf)] +pub struct PackedLastSeenMessages { + pub entries: Vec<PackedMessageSignature>, +} + +/// Messages can be deleted by either their signature or message id. +#[derive(Clone, Debug, PartialEq)] +pub enum PackedMessageSignature { + Signature(Box<MessageSignature>), + Id(u32), +} + +#[derive(Clone, Debug, PartialEq, McBuf)] +pub enum FilterMask { + PassThrough, + FullyFiltered, + PartiallyFiltered(BitSet), +} + #[derive(Copy, Clone, Debug, McBuf, PartialEq, Eq)] pub enum ChatType { Chat = 0, @@ -32,47 +70,36 @@ pub struct ChatTypeBound { pub target_name: Option<Component>, } -#[derive(Clone, Debug, McBuf, PartialEq)] -pub struct PlayerChatMessage { - pub signed_header: SignedMessageHeader, - pub header_signature: MessageSignature, - pub signed_body: SignedMessageBody, - pub unsigned_content: Option<Component>, - pub filter_mask: FilterMask, +// must be in Client +#[derive(Clone, Debug, PartialEq)] +pub struct MessageSignatureCache { + pub entries: Vec<Option<MessageSignature>>, } -#[derive(Clone, Debug, PartialEq, McBuf)] -pub struct SignedMessageBody { - pub content: ChatMessageContent, - pub timestamp: u64, - pub salt: u64, - pub last_seen: Vec<LastSeenMessagesEntry>, -} +// impl MessageSignatureCache { +// pub fn unpacker(&self) -> impl Fn(u32) -> Option<SignedMessageBody> { + +// } +// } -impl PlayerChatMessage { +// impl PackedSignedMessageBody { +// pub fn unpack(&self, unpacker: impl Fn(u32) -> Option<SignedMessageBody>) {} +// } + +impl ClientboundPlayerChatPacket { /// Returns the content of the message. If you want to get the Component /// for the whole message including the sender part, use /// [`ClientboundPlayerChatPacket::message`]. - pub fn content(&self, only_secure_chat: bool) -> Component { - if only_secure_chat { - return self - .signed_body - .content - .decorated - .clone() - .unwrap_or_else(|| Component::from(self.signed_body.content.plain.clone())); - } + pub fn content(&self) -> Component { self.unsigned_content .clone() - .unwrap_or_else(|| self.content(true)) + .unwrap_or_else(|| Component::from(self.body.content.clone())) } -} -impl ClientboundPlayerChatPacket { /// Get the full message, including the sender part. - pub fn message(&self, only_secure_chat: bool) -> Component { + pub fn message(&self) -> Component { let sender = self.chat_type.name.clone(); - let content = self.message.content(only_secure_chat); + let content = self.content(); let target = self.chat_type.target_name.clone(); let translation_key = self.chat_type.chat_type.chat_translation_key(); @@ -117,45 +144,66 @@ impl ChatType { } } -#[derive(Clone, Debug, McBuf, PartialEq)] -pub struct LastSeenMessagesEntry { - pub profile_id: Uuid, - pub last_signature: MessageSignature, -} - -#[derive(Clone, Debug, McBuf, Default)] -pub struct LastSeenMessagesUpdate { - pub last_seen: Vec<LastSeenMessagesEntry>, - pub last_received: Option<LastSeenMessagesEntry>, -} +impl McBufReadable for PackedMessageSignature { + fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { + let id = u32::var_read_from(buf)?; + if id == 0 { + let full_signature = MessageSignature::read_from(buf)?; -#[derive(Clone, Debug, McBuf, PartialEq)] -pub struct ChatMessageContent { - pub plain: String, - /// Only sent if the decorated message is different than the plain. - pub decorated: Option<Component>, + Ok(PackedMessageSignature::Signature(Box::new(full_signature))) + } else { + Ok(PackedMessageSignature::Id(id - 1)) + } + } } - -#[derive(Clone, Debug, McBuf, PartialEq)] -pub enum FilterMask { - PassThrough, - FullyFiltered, - PartiallyFiltered(BitSet), +impl McBufWritable for PackedMessageSignature { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { + match self { + PackedMessageSignature::Signature(full_signature) => { + 0u32.var_write_into(buf)?; + full_signature.write_into(buf)?; + } + PackedMessageSignature::Id(id) => { + (id + 1).var_write_into(buf)?; + } + } + Ok(()) + } } #[cfg(test)] mod tests { use super::*; - use azalea_buf::McBufReadable; - use std::io::Cursor; + use std::backtrace::Backtrace; + // you can remove or update this test if it breaks because mojang changed the structure of the packet again #[test] - fn test_chat_type() { - let chat_type_enum = ChatType::read_from(&mut Cursor::new(&[0x06])).unwrap(); - assert_eq!(chat_type_enum, ChatType::EmoteCommand); - assert_eq!( - ChatType::read_from(&mut Cursor::new(&[0x07])).unwrap(), - ChatType::Chat - ); + fn test_player_chat_packet() { + let data: [u8; 295] = [ + 47, 247, 69, 164, 160, 108, 63, 217, 178, 34, 4, 161, 47, 115, 192, 126, 0, 0, 11, 72, + 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 0, 0, 1, 132, 209, 9, 72, 139, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 242, 1, 123, 34, 105, 110, 115, 101, 114, 116, 105, 111, + 110, 34, 58, 34, 98, 111, 116, 48, 34, 44, 34, 99, 108, 105, 99, 107, 69, 118, 101, + 110, 116, 34, 58, 123, 34, 97, 99, 116, 105, 111, 110, 34, 58, 34, 115, 117, 103, 103, + 101, 115, 116, 95, 99, 111, 109, 109, 97, 110, 100, 34, 44, 34, 118, 97, 108, 117, 101, + 34, 58, 34, 47, 116, 101, 108, 108, 32, 98, 111, 116, 48, 32, 34, 125, 44, 34, 104, + 111, 118, 101, 114, 69, 118, 101, 110, 116, 34, 58, 123, 34, 97, 99, 116, 105, 111, + 110, 34, 58, 34, 115, 104, 111, 119, 95, 101, 110, 116, 105, 116, 121, 34, 44, 34, 99, + 111, 110, 116, 101, 110, 116, 115, 34, 58, 123, 34, 116, 121, 112, 101, 34, 58, 34, + 109, 105, 110, 101, 99, 114, 97, 102, 116, 58, 112, 108, 97, 121, 101, 114, 34, 44, 34, + 105, 100, 34, 58, 34, 50, 102, 102, 55, 52, 53, 97, 52, 45, 97, 48, 54, 99, 45, 51, + 102, 100, 57, 45, 98, 50, 50, 50, 45, 48, 52, 97, 49, 50, 102, 55, 51, 99, 48, 55, 101, + 34, 44, 34, 110, 97, 109, 101, 34, 58, 123, 34, 116, 101, 120, 116, 34, 58, 34, 98, + 111, 116, 48, 34, 125, 125, 125, 44, 34, 116, 101, 120, 116, 34, 58, 34, 98, 111, 116, + 48, 34, 125, 0, + ]; + // just make sure it doesn't panic + if let Err(e) = ClientboundPlayerChatPacket::read_from(&mut Cursor::new(&data)) { + let default_backtrace = Backtrace::capture(); + let backtrace = std::any::request_ref::<Backtrace>(&e).unwrap_or(&default_backtrace); + eprintln!("{e}\n{backtrace}"); + + panic!("failed to read player chat packet"); + } } } diff --git a/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs deleted file mode 100755 index dea3b784..00000000 --- a/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs +++ /dev/null @@ -1,93 +0,0 @@ -use crate::packets::login::serverbound_hello_packet::ProfilePublicKeyData; -use azalea_auth::game_profile::ProfilePropertyValue; -use azalea_buf::{BufReadError, McBuf}; -use azalea_buf::{McBufReadable, McBufWritable}; -use azalea_chat::Component; -use azalea_core::GameType; -use azalea_protocol_macros::ClientboundGamePacket; -use std::collections::HashMap; -use std::io::{Cursor, Write}; -use uuid::Uuid; - -#[derive(Clone, Debug, McBuf, ClientboundGamePacket)] -pub struct ClientboundPlayerInfoPacket { - pub action: Action, -} - -#[derive(Clone, Debug)] -pub enum Action { - AddPlayer(Vec<AddPlayer>), - UpdateGameMode(Vec<UpdateGameMode>), - UpdateLatency(Vec<UpdateLatency>), - UpdateDisplayName(Vec<UpdateDisplayName>), - RemovePlayer(Vec<RemovePlayer>), -} - -#[derive(Clone, Debug, McBuf)] -pub struct AddPlayer { - pub uuid: Uuid, - pub name: String, - pub properties: HashMap<String, ProfilePropertyValue>, - pub gamemode: GameType, - #[var] - pub latency: i32, - pub display_name: Option<Component>, - pub profile_public_key: Option<ProfilePublicKeyData>, -} - -#[derive(Clone, Debug, McBuf)] -pub struct UpdateGameMode { - pub uuid: Uuid, - pub gamemode: GameType, -} - -#[derive(Clone, Debug, McBuf)] -pub struct UpdateLatency { - pub uuid: Uuid, - #[var] - pub latency: i32, -} - -#[derive(Clone, Debug, McBuf)] -pub struct UpdateDisplayName { - pub uuid: Uuid, - pub display_name: Option<Component>, -} -#[derive(Clone, Debug, McBuf)] -pub struct RemovePlayer { - pub uuid: Uuid, -} - -impl McBufReadable for Action { - fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { - let id = u8::read_from(buf)?; - Ok(match id { - 0 => Action::AddPlayer(Vec::<AddPlayer>::read_from(buf)?), - 1 => Action::UpdateGameMode(Vec::<UpdateGameMode>::read_from(buf)?), - 2 => Action::UpdateLatency(Vec::<UpdateLatency>::read_from(buf)?), - 3 => Action::UpdateDisplayName(Vec::<UpdateDisplayName>::read_from(buf)?), - 4 => Action::RemovePlayer(Vec::<RemovePlayer>::read_from(buf)?), - _ => return Err(BufReadError::UnexpectedEnumVariant { id: id.into() }), - }) - } -} -impl McBufWritable for Action { - fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { - let id: u8 = match self { - Action::AddPlayer(_) => 0, - Action::UpdateGameMode(_) => 1, - Action::UpdateLatency(_) => 2, - Action::UpdateDisplayName(_) => 3, - Action::RemovePlayer(_) => 4, - }; - id.write_into(buf)?; - match self { - Action::AddPlayer(players) => players.write_into(buf)?, - Action::UpdateGameMode(players) => players.write_into(buf)?, - Action::UpdateLatency(players) => players.write_into(buf)?, - Action::UpdateDisplayName(players) => players.write_into(buf)?, - Action::RemovePlayer(players) => players.write_into(buf)?, - } - Ok(()) - } -} diff --git a/azalea-protocol/src/packets/game/clientbound_player_info_remove_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_info_remove_packet.rs new file mode 100644 index 00000000..bb620272 --- /dev/null +++ b/azalea-protocol/src/packets/game/clientbound_player_info_remove_packet.rs @@ -0,0 +1,8 @@ +use azalea_buf::McBuf; +use azalea_protocol_macros::ClientboundGamePacket; +use uuid::Uuid; + +#[derive(Clone, Debug, McBuf, ClientboundGamePacket)] +pub struct ClientboundPlayerInfoRemovePacket { + pub profile_ids: Vec<Uuid>, +} diff --git a/azalea-protocol/src/packets/game/clientbound_player_info_update_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_info_update_packet.rs new file mode 100644 index 00000000..a3a3b45d --- /dev/null +++ b/azalea-protocol/src/packets/game/clientbound_player_info_update_packet.rs @@ -0,0 +1,201 @@ +use azalea_auth::game_profile::{GameProfile, ProfilePropertyValue}; +use azalea_buf::{ + BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable, +}; +use azalea_chat::Component; +use azalea_core::{BitSet, GameType}; +use azalea_protocol_macros::ClientboundGamePacket; +use std::{ + collections::HashMap, + io::{Cursor, Write}, +}; +use uuid::Uuid; + +use super::serverbound_chat_session_update_packet::RemoteChatSessionData; + +#[derive(Clone, Debug, ClientboundGamePacket)] +pub struct ClientboundPlayerInfoUpdatePacket { + pub actions: ActionEnumSet, + pub entries: Vec<PlayerInfoEntry>, +} + +#[derive(Clone, Debug, Default)] +pub struct PlayerInfoEntry { + pub profile: GameProfile, + pub listed: bool, + pub latency: i32, + pub game_mode: GameType, + pub display_name: Option<Component>, + pub chat_session: Option<RemoteChatSessionData>, +} + +#[derive(Clone, Debug, McBuf)] +pub struct AddPlayerAction { + pub name: String, + pub properties: HashMap<String, ProfilePropertyValue>, +} +#[derive(Clone, Debug, McBuf)] +pub struct InitializeChatAction { + pub chat_session: Option<RemoteChatSessionData>, +} +#[derive(Clone, Debug, McBuf)] +pub struct UpdateGameModeAction { + pub game_mode: GameType, +} +#[derive(Clone, Debug, McBuf)] +pub struct UpdateListedAction { + pub listed: bool, +} +#[derive(Clone, Debug, McBuf)] +pub struct UpdateLatencyAction { + #[var] + pub latency: i32, +} +#[derive(Clone, Debug, McBuf)] +pub struct UpdateDisplayNameAction { + pub display_name: Option<Component>, +} + +impl McBufReadable for ClientboundPlayerInfoUpdatePacket { + fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { + let actions = ActionEnumSet::read_from(buf)?; + let mut entries = vec![]; + + let entry_count = u32::var_read_from(buf)?; + for _ in 0..entry_count { + let profile_id = Uuid::read_from(buf)?; + let mut entry = PlayerInfoEntry::default(); + entry.profile.uuid = profile_id; + + if actions.add_player { + let action = AddPlayerAction::read_from(buf)?; + entry.profile.name = action.name; + entry.profile.properties = action.properties; + } + if actions.initialize_chat { + let action = InitializeChatAction::read_from(buf)?; + entry.chat_session = action.chat_session; + } + if actions.update_game_mode { + let action = UpdateGameModeAction::read_from(buf)?; + entry.game_mode = action.game_mode; + } + if actions.update_listed { + let action = UpdateListedAction::read_from(buf)?; + entry.listed = action.listed; + } + if actions.update_latency { + let action = UpdateLatencyAction::read_from(buf)?; + entry.latency = action.latency; + } + if actions.update_display_name { + let action = UpdateDisplayNameAction::read_from(buf)?; + entry.display_name = action.display_name; + } + + entries.push(entry); + } + + Ok(ClientboundPlayerInfoUpdatePacket { actions, entries }) + } +} + +impl McBufWritable for ClientboundPlayerInfoUpdatePacket { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { + self.actions.write_into(buf)?; + + (self.entries.len() as u32).var_write_into(buf)?; + for entry in &self.entries { + entry.profile.uuid.write_into(buf)?; + + if self.actions.add_player { + AddPlayerAction { + name: entry.profile.name.clone(), + properties: entry.profile.properties.clone(), + } + .write_into(buf)?; + } + if self.actions.initialize_chat { + InitializeChatAction { + chat_session: entry.chat_session.clone(), + } + .write_into(buf)?; + } + if self.actions.update_game_mode { + UpdateGameModeAction { + game_mode: entry.game_mode, + } + .write_into(buf)?; + } + if self.actions.update_listed { + UpdateListedAction { + listed: entry.listed, + } + .write_into(buf)?; + } + if self.actions.update_latency { + UpdateLatencyAction { + latency: entry.latency, + } + .write_into(buf)?; + } + if self.actions.update_display_name { + UpdateDisplayNameAction { + display_name: entry.display_name.clone(), + } + .write_into(buf)?; + } + } + + Ok(()) + } +} + +#[derive(Clone, Debug)] +pub struct ActionEnumSet { + pub add_player: bool, + pub initialize_chat: bool, + pub update_game_mode: bool, + pub update_listed: bool, + pub update_latency: bool, + pub update_display_name: bool, +} + +impl McBufReadable for ActionEnumSet { + fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { + let set = BitSet::read_fixed(buf, 6)?; + Ok(ActionEnumSet { + add_player: set.index(0), + initialize_chat: set.index(1), + update_game_mode: set.index(2), + update_listed: set.index(3), + update_latency: set.index(4), + update_display_name: set.index(5), + }) + } +} + +impl McBufWritable for ActionEnumSet { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { + let mut set = BitSet::new(6); + if self.add_player { + set.set(0); + } + if self.initialize_chat { + set.set(1); + } + if self.update_game_mode { + set.set(2); + } + if self.update_listed { + set.set(3); + } + if self.update_latency { + set.set(4); + } + if self.update_display_name { + set.set(5); + } + set.write_into(buf) + } +} diff --git a/azalea-protocol/src/packets/game/clientbound_respawn_packet.rs b/azalea-protocol/src/packets/game/clientbound_respawn_packet.rs index 0ad1e706..58488124 100755 --- a/azalea-protocol/src/packets/game/clientbound_respawn_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_respawn_packet.rs @@ -11,6 +11,6 @@ pub struct ClientboundRespawnPacket { pub previous_player_game_type: OptionalGameType, pub is_debug: bool, pub is_flat: bool, - pub keep_all_player_data: bool, + pub data_to_keep: u8, pub last_death_location: Option<GlobalPos>, } diff --git a/azalea-protocol/src/packets/game/clientbound_server_data_packet.rs b/azalea-protocol/src/packets/game/clientbound_server_data_packet.rs index 2305cf32..16841e3a 100755 --- a/azalea-protocol/src/packets/game/clientbound_server_data_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_server_data_packet.rs @@ -6,6 +6,5 @@ use azalea_protocol_macros::ClientboundGamePacket; pub struct ClientboundServerDataPacket { pub motd: Option<Component>, pub icon_base64: Option<String>, - pub previews_chat: bool, pub enforces_secure_chat: bool, } diff --git a/azalea-protocol/src/packets/game/clientbound_sound_entity_packet.rs b/azalea-protocol/src/packets/game/clientbound_sound_entity_packet.rs index ad382fe0..c7448800 100755 --- a/azalea-protocol/src/packets/game/clientbound_sound_entity_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_sound_entity_packet.rs @@ -1,10 +1,11 @@ use super::clientbound_sound_packet::SoundSource; use azalea_buf::McBuf; use azalea_protocol_macros::ClientboundGamePacket; +use azalea_registry::OptionalRegistry; #[derive(Clone, Debug, McBuf, ClientboundGamePacket)] pub struct ClientboundSoundEntityPacket { - pub sound: azalea_registry::SoundEvent, + pub sound: OptionalRegistry<azalea_registry::SoundEvent>, pub source: SoundSource, #[var] pub id: u32, diff --git a/azalea-protocol/src/packets/game/clientbound_sound_packet.rs b/azalea-protocol/src/packets/game/clientbound_sound_packet.rs index 54f35492..39dd39c8 100755 --- a/azalea-protocol/src/packets/game/clientbound_sound_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_sound_packet.rs @@ -1,9 +1,10 @@ use azalea_buf::McBuf; use azalea_protocol_macros::ClientboundGamePacket; +use azalea_registry::OptionalRegistry; #[derive(Clone, Debug, McBuf, ClientboundGamePacket)] pub struct ClientboundSoundPacket { - pub sound: azalea_registry::SoundEvent, + pub sound: OptionalRegistry<azalea_registry::SoundEvent>, pub source: SoundSource, pub x: i32, pub y: i32, diff --git a/azalea-protocol/src/packets/game/clientbound_update_enabled_features_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_enabled_features_packet.rs new file mode 100644 index 00000000..4f05b413 --- /dev/null +++ b/azalea-protocol/src/packets/game/clientbound_update_enabled_features_packet.rs @@ -0,0 +1,8 @@ +use azalea_buf::McBuf; +use azalea_core::ResourceLocation; +use azalea_protocol_macros::ClientboundGamePacket; + +#[derive(Clone, Debug, McBuf, ClientboundGamePacket)] +pub struct ClientboundUpdateEnabledFeaturesPacket { + pub features: Vec<ResourceLocation>, +} diff --git a/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs index 9c325d29..e95e9316 100755 --- a/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs @@ -20,17 +20,27 @@ pub struct Recipe { pub struct ShapelessRecipe { /// Used to group similar recipes together in the recipe book. /// Tag is present in recipe JSON - group: String, - ingredients: Vec<Ingredient>, - result: Slot, + pub group: String, + pub category: CraftingBookCategory, + pub ingredients: Vec<Ingredient>, + pub result: Slot, } #[derive(Clone, Debug)] pub struct ShapedRecipe { - width: usize, - height: usize, - group: String, - ingredients: Vec<Ingredient>, - result: Slot, + pub width: usize, + pub height: usize, + pub group: String, + pub category: CraftingBookCategory, + pub ingredients: Vec<Ingredient>, + pub result: Slot, +} + +#[derive(Clone, Debug, Copy, McBuf)] +pub enum CraftingBookCategory { + Building = 0, + Redstone, + Equipment, + Misc, } impl McBufWritable for ShapedRecipe { @@ -38,6 +48,7 @@ impl McBufWritable for ShapedRecipe { (self.width as u32).var_write_into(buf)?; (self.height as u32).var_write_into(buf)?; self.group.write_into(buf)?; + self.category.write_into(buf)?; for ingredient in &self.ingredients { ingredient.write_into(buf)?; } @@ -51,6 +62,7 @@ impl McBufReadable for ShapedRecipe { let width = u32::var_read_from(buf)?.try_into().unwrap(); let height = u32::var_read_from(buf)?.try_into().unwrap(); let group = String::read_from(buf)?; + let category = CraftingBookCategory::read_from(buf)?; let mut ingredients = Vec::with_capacity(width * height); for _ in 0..width * height { ingredients.push(Ingredient::read_from(buf)?); @@ -61,6 +73,7 @@ impl McBufReadable for ShapedRecipe { width, height, group, + category, ingredients, result, }) @@ -69,49 +82,55 @@ impl McBufReadable for ShapedRecipe { #[derive(Clone, Debug, McBuf)] pub struct CookingRecipe { - group: String, - ingredient: Ingredient, - result: Slot, - experience: f32, + pub group: String, + pub category: CraftingBookCategory, + pub ingredient: Ingredient, + pub result: Slot, + pub experience: f32, #[var] - cooking_time: u32, + pub cooking_time: u32, } #[derive(Clone, Debug, McBuf)] -pub struct StoneCuttingRecipe { - group: String, - ingredient: Ingredient, - result: Slot, +pub struct StoneCutterRecipe { + pub group: String, + pub ingredient: Ingredient, + pub result: Slot, } #[derive(Clone, Debug, McBuf)] pub struct SmithingRecipe { - base: Ingredient, - addition: Ingredient, - result: Slot, + pub base: Ingredient, + pub addition: Ingredient, + pub result: Slot, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, McBuf)] +pub struct SimpleRecipe { + pub category: CraftingBookCategory, +} + +#[derive(Clone, Debug, McBuf)] pub enum RecipeData { CraftingShapeless(ShapelessRecipe), CraftingShaped(ShapedRecipe), - CraftingSpecialArmorDye, - CraftingSpecialBookCloning, - CraftingSpecialMapCloning, - CraftingSpecialMapExtending, - CraftingSpecialFireworkRocket, - CraftingSpecialFireworkStar, - CraftingSpecialFireworkStarFade, - CraftingSpecialRepairItem, - CraftingSpecialTippedArrow, - CraftingSpecialBannerDuplicate, - CraftingSpecialBannerAddPattern, - CraftingSpecialShieldDecoration, - CraftingSpecialShulkerBoxColoring, - CraftingSpecialSuspiciousStew, + CraftingSpecialArmorDye(SimpleRecipe), + CraftingSpecialBookCloning(SimpleRecipe), + CraftingSpecialMapCloning(SimpleRecipe), + CraftingSpecialMapExtending(SimpleRecipe), + CraftingSpecialFireworkRocket(SimpleRecipe), + CraftingSpecialFireworkStar(SimpleRecipe), + CraftingSpecialFireworkStarFade(SimpleRecipe), + CraftingSpecialRepairItem(SimpleRecipe), + CraftingSpecialTippedArrow(SimpleRecipe), + CraftingSpecialBannerDuplicate(SimpleRecipe), + CraftingSpecialBannerAddPattern(SimpleRecipe), + CraftingSpecialShieldDecoration(SimpleRecipe), + CraftingSpecialShulkerBoxColoring(SimpleRecipe), + CraftingSpecialSuspiciousStew(SimpleRecipe), Smelting(CookingRecipe), Blasting(CookingRecipe), Smoking(CookingRecipe), CampfireCooking(CookingRecipe), - Stonecutting(StoneCuttingRecipe), + Stonecutting(StoneCutterRecipe), Smithing(SmithingRecipe), } @@ -122,236 +141,127 @@ pub struct Ingredient { impl McBufWritable for Recipe { fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { - match &self.data { - RecipeData::CraftingShapeless(recipe) => { - ResourceLocation::new("minecraft:crafting_shapeless") - .unwrap() - .write_into(buf)?; - self.identifier.write_into(buf)?; - recipe.write_into(buf)?; + let resource_location = match &self.data { + RecipeData::CraftingShapeless(_) => "minecraft:crafting_shapeless", + RecipeData::CraftingShaped(_) => "minecraft:crafting_shaped", + RecipeData::CraftingSpecialArmorDye(_) => "minecraft:crafting_special_armordye", + RecipeData::CraftingSpecialBookCloning(_) => "minecraft:crafting_special_bookcloning", + RecipeData::CraftingSpecialMapCloning(_) => "minecraft:crafting_special_mapcloning", + RecipeData::CraftingSpecialMapExtending(_) => "minecraft:crafting_special_mapextending", + RecipeData::CraftingSpecialFireworkRocket(_) => { + "minecraft:crafting_special_firework_rocket" } - RecipeData::CraftingShaped(recipe) => { - ResourceLocation::new("minecraft:crafting_shaped") - .unwrap() - .write_into(buf)?; - self.identifier.write_into(buf)?; - recipe.write_into(buf)?; + RecipeData::CraftingSpecialFireworkStar(_) => { + "minecraft:crafting_special_firework_star" } - RecipeData::CraftingSpecialArmorDye => { - ResourceLocation::new("minecraft:crafting_special_armordye") - .unwrap() - .write_into(buf)?; - self.identifier.write_into(buf)?; + + RecipeData::CraftingSpecialFireworkStarFade(_) => { + "minecraft:crafting_special_firework_star_fade" } - RecipeData::CraftingSpecialBookCloning => { - ResourceLocation::new("minecraft:crafting_special_bookcloning") - .unwrap() - .write_into(buf)?; - self.identifier.write_into(buf)?; + RecipeData::CraftingSpecialRepairItem(_) => "minecraft:crafting_special_repairitem", + RecipeData::CraftingSpecialTippedArrow(_) => "minecraft:crafting_special_tippedarrow", + RecipeData::CraftingSpecialBannerDuplicate(_) => { + "minecraft:crafting_special_bannerduplicate" } - RecipeData::CraftingSpecialMapCloning => { - ResourceLocation::new("minecraft:crafting_special_mapcloning") - .unwrap() - .write_into(buf)?; - self.identifier.write_into(buf)?; + RecipeData::CraftingSpecialBannerAddPattern(_) => { + "minecraft:crafting_special_banneraddpattern" } - RecipeData::CraftingSpecialMapExtending => { - ResourceLocation::new("minecraft:crafting_special_mapextending") - .unwrap() - .write_into(buf)?; - self.identifier.write_into(buf)?; + RecipeData::CraftingSpecialShieldDecoration(_) => { + "minecraft:crafting_special_shielddecoration" } - RecipeData::CraftingSpecialFireworkRocket => { - ResourceLocation::new("minecraft:crafting_special_firework_rocket") - .unwrap() - .write_into(buf)?; - self.identifier.write_into(buf)?; + RecipeData::CraftingSpecialShulkerBoxColoring(_) => { + "minecraft:crafting_special_shulkerboxcoloring" } - RecipeData::CraftingSpecialFireworkStar => { - ResourceLocation::new("minecraft:crafting_special_firework_star") - .unwrap() - .write_into(buf)?; - self.identifier.write_into(buf)?; + RecipeData::CraftingSpecialSuspiciousStew(_) => { + "minecraft:crafting_special_suspiciousstew" } - RecipeData::CraftingSpecialFireworkStarFade => { - ResourceLocation::new("minecraft:crafting_special_firework_star_fade") - .unwrap() - .write_into(buf)?; - self.identifier.write_into(buf)?; + RecipeData::Smelting(_) => "minecraft:smelting", + RecipeData::Blasting(_) => "minecraft:blasting", + RecipeData::Smoking(_) => "minecraft:smoking", + RecipeData::CampfireCooking(_) => "minecraft:campfire_cooking", + RecipeData::Stonecutting(_) => "minecraft:stonecutting", + RecipeData::Smithing(_) => "minecraft:smithing", + }; + ResourceLocation::new(resource_location) + .unwrap() + .write_into(buf)?; + self.identifier.write_into(buf)?; + self.data.write_without_id(buf)?; + Ok(()) + } +} + +impl McBufReadable for Recipe { + fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { + let recipe_type = ResourceLocation::read_from(buf)?; + let identifier = ResourceLocation::read_from(buf)?; + + // rust doesn't let us match ResourceLocation so we have to do a big + // if-else chain :( + let data = match recipe_type.to_string().as_str() { + "minecraft:crafting_shapeless" => { + RecipeData::CraftingShapeless(ShapelessRecipe::read_from(buf)?) } - RecipeData::CraftingSpecialRepairItem => { - ResourceLocation::new("minecraft:crafting_special_repairitem") - .unwrap() - .write_into(buf)?; - self.identifier.write_into(buf)?; + "minecraft:crafting_shaped" => { + RecipeData::CraftingShaped(ShapedRecipe::read_from(buf)?) } - RecipeData::CraftingSpecialTippedArrow => { - ResourceLocation::new("minecraft:crafting_special_tippedarrow") - .unwrap() - .write_into(buf)?; - self.identifier.write_into(buf)?; + "minecraft:crafting_special_armordye" => { + RecipeData::CraftingSpecialArmorDye(SimpleRecipe::read_from(buf)?) } - RecipeData::CraftingSpecialBannerDuplicate => { - ResourceLocation::new("minecraft:crafting_special_bannerduplicate") - .unwrap() - .write_into(buf)?; - self.identifier.write_into(buf)?; + "minecraft:crafting_special_bookcloning" => { + RecipeData::CraftingSpecialBookCloning(SimpleRecipe::read_from(buf)?) } - RecipeData::CraftingSpecialBannerAddPattern => { - ResourceLocation::new("minecraft:crafting_special_banneraddpattern") - .unwrap() - .write_into(buf)?; - self.identifier.write_into(buf)?; + "minecraft:crafting_special_mapcloning" => { + RecipeData::CraftingSpecialMapCloning(SimpleRecipe::read_from(buf)?) } - RecipeData::CraftingSpecialShieldDecoration => { - ResourceLocation::new("minecraft:crafting_special_shielddecoration") - .unwrap() - .write_into(buf)?; - self.identifier.write_into(buf)?; + "minecraft:crafting_special_mapextending" => { + RecipeData::CraftingSpecialMapExtending(SimpleRecipe::read_from(buf)?) } - RecipeData::CraftingSpecialShulkerBoxColoring => { - ResourceLocation::new("minecraft:crafting_special_shulkerboxcoloring") - .unwrap() - .write_into(buf)?; - self.identifier.write_into(buf)?; + "minecraft:crafting_special_firework_rocket" => { + RecipeData::CraftingSpecialFireworkRocket(SimpleRecipe::read_from(buf)?) } - RecipeData::CraftingSpecialSuspiciousStew => { - ResourceLocation::new("minecraft:crafting_special_suspiciousstew") - .unwrap() - .write_into(buf)?; - self.identifier.write_into(buf)?; + "minecraft:crafting_special_firework_star" => { + RecipeData::CraftingSpecialFireworkStar(SimpleRecipe::read_from(buf)?) } - RecipeData::Smelting(recipe) => { - ResourceLocation::new("minecraft:smelting") - .unwrap() - .write_into(buf)?; - self.identifier.write_into(buf)?; - recipe.write_into(buf)?; + "minecraft:crafting_special_firework_star_fade" => { + RecipeData::CraftingSpecialFireworkStarFade(SimpleRecipe::read_from(buf)?) } - RecipeData::Blasting(recipe) => { - ResourceLocation::new("minecraft:blasting") - .unwrap() - .write_into(buf)?; - self.identifier.write_into(buf)?; - recipe.write_into(buf)?; + "minecraft:crafting_special_repairitem" => { + RecipeData::CraftingSpecialRepairItem(SimpleRecipe::read_from(buf)?) } - RecipeData::Smoking(recipe) => { - ResourceLocation::new("minecraft:smoking") - .unwrap() - .write_into(buf)?; - self.identifier.write_into(buf)?; - recipe.write_into(buf)?; + "minecraft:crafting_special_tippedarrow" => { + RecipeData::CraftingSpecialTippedArrow(SimpleRecipe::read_from(buf)?) } - RecipeData::CampfireCooking(recipe) => { - ResourceLocation::new("minecraft:campfire_cooking") - .unwrap() - .write_into(buf)?; - self.identifier.write_into(buf)?; - recipe.write_into(buf)?; + "minecraft:crafting_special_bannerduplicate" => { + RecipeData::CraftingSpecialBannerDuplicate(SimpleRecipe::read_from(buf)?) } - RecipeData::Stonecutting(recipe) => { - ResourceLocation::new("minecraft:stonecutting") - .unwrap() - .write_into(buf)?; - self.identifier.write_into(buf)?; - recipe.write_into(buf)?; + "minecraft:crafting_special_banneraddpattern" => { + RecipeData::CraftingSpecialBannerAddPattern(SimpleRecipe::read_from(buf)?) } - RecipeData::Smithing(recipe) => { - ResourceLocation::new("minecraft:smithing") - .unwrap() - .write_into(buf)?; - self.identifier.write_into(buf)?; - recipe.write_into(buf)?; + "minecraft:crafting_special_shielddecoration" => { + RecipeData::CraftingSpecialShieldDecoration(SimpleRecipe::read_from(buf)?) + } + "minecraft:crafting_special_shulkerboxcoloring" => { + RecipeData::CraftingSpecialShulkerBoxColoring(SimpleRecipe::read_from(buf)?) + } + "minecraft:crafting_special_suspiciousstew" => { + RecipeData::CraftingSpecialSuspiciousStew(SimpleRecipe::read_from(buf)?) + } + "minecraft:smelting" => RecipeData::Smelting(CookingRecipe::read_from(buf)?), + "minecraft:blasting" => RecipeData::Blasting(CookingRecipe::read_from(buf)?), + "minecraft:smoking" => RecipeData::Smoking(CookingRecipe::read_from(buf)?), + "minecraft:campfire_cooking" => { + RecipeData::CampfireCooking(CookingRecipe::read_from(buf)?) + } + "minecraft:stonecutting" => { + RecipeData::Stonecutting(StoneCutterRecipe::read_from(buf)?) + } + "minecraft:smithing" => RecipeData::Smithing(SmithingRecipe::read_from(buf)?), + _ => { + return Err(BufReadError::UnexpectedStringEnumVariant { + id: recipe_type.to_string(), + }); } - }; - Ok(()) - } -} - -impl McBufReadable for Recipe { - fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { - let recipe_type = ResourceLocation::read_from(buf)?; - let identifier = ResourceLocation::read_from(buf)?; - - // rust doesn't let us match ResourceLocation so we have to do a big - // if-else chain :( - let data = if recipe_type == ResourceLocation::new("minecraft:crafting_shapeless").unwrap() - { - RecipeData::CraftingShapeless(ShapelessRecipe::read_from(buf)?) - } else if recipe_type == ResourceLocation::new("minecraft:crafting_shaped").unwrap() { - RecipeData::CraftingShaped(ShapedRecipe::read_from(buf)?) - } else if recipe_type - == ResourceLocation::new("minecraft:crafting_special_armordye").unwrap() - { - RecipeData::CraftingSpecialArmorDye - } else if recipe_type - == ResourceLocation::new("minecraft:crafting_special_bookcloning").unwrap() - { - RecipeData::CraftingSpecialBookCloning - } else if recipe_type - == ResourceLocation::new("minecraft:crafting_special_mapcloning").unwrap() - { - RecipeData::CraftingSpecialMapCloning - } else if recipe_type - == ResourceLocation::new("minecraft:crafting_special_mapextending").unwrap() - { - RecipeData::CraftingSpecialMapExtending - } else if recipe_type - == ResourceLocation::new("minecraft:crafting_special_firework_rocket").unwrap() - { - RecipeData::CraftingSpecialFireworkRocket - } else if recipe_type - == ResourceLocation::new("minecraft:crafting_special_firework_star").unwrap() - { - RecipeData::CraftingSpecialFireworkStar - } else if recipe_type - == ResourceLocation::new("minecraft:crafting_special_firework_star_fade").unwrap() - { - RecipeData::CraftingSpecialFireworkStarFade - } else if recipe_type - == ResourceLocation::new("minecraft:crafting_special_repairitem").unwrap() - { - RecipeData::CraftingSpecialRepairItem - } else if recipe_type - == ResourceLocation::new("minecraft:crafting_special_tippedarrow").unwrap() - { - RecipeData::CraftingSpecialTippedArrow - } else if recipe_type - == ResourceLocation::new("minecraft:crafting_special_bannerduplicate").unwrap() - { - RecipeData::CraftingSpecialBannerDuplicate - } else if recipe_type - == ResourceLocation::new("minecraft:crafting_special_banneraddpattern").unwrap() - { - RecipeData::CraftingSpecialBannerAddPattern - } else if recipe_type - == ResourceLocation::new("minecraft:crafting_special_shielddecoration").unwrap() - { - RecipeData::CraftingSpecialShieldDecoration - } else if recipe_type - == ResourceLocation::new("minecraft:crafting_special_shulkerboxcoloring").unwrap() - { - RecipeData::CraftingSpecialShulkerBoxColoring - } else if recipe_type - == ResourceLocation::new("minecraft:crafting_special_suspiciousstew").unwrap() - { - RecipeData::CraftingSpecialSuspiciousStew - } else if recipe_type == ResourceLocation::new("minecraft:smelting").unwrap() { - RecipeData::Smelting(CookingRecipe::read_from(buf)?) - } else if recipe_type == ResourceLocation::new("minecraft:blasting").unwrap() { - RecipeData::Blasting(CookingRecipe::read_from(buf)?) - } else if recipe_type == ResourceLocation::new("minecraft:smoking").unwrap() { - RecipeData::Smoking(CookingRecipe::read_from(buf)?) - } else if recipe_type == ResourceLocation::new("minecraft:campfire_cooking").unwrap() { - RecipeData::CampfireCooking(CookingRecipe::read_from(buf)?) - } else if recipe_type == ResourceLocation::new("minecraft:stonecutting").unwrap() { - RecipeData::Stonecutting(StoneCuttingRecipe::read_from(buf)?) - } else if recipe_type == ResourceLocation::new("minecraft:smithing").unwrap() { - RecipeData::Smithing(SmithingRecipe::read_from(buf)?) - } else { - return Err(BufReadError::UnexpectedStringEnumVariant { - id: recipe_type.to_string(), - }); }; let recipe = Recipe { identifier, data }; diff --git a/azalea-protocol/src/packets/game/mod.rs b/azalea-protocol/src/packets/game/mod.rs index 54247202..8c9207b5 100755 --- a/azalea-protocol/src/packets/game/mod.rs +++ b/azalea-protocol/src/packets/game/mod.rs @@ -10,7 +10,6 @@ pub mod clientbound_block_event_packet; pub mod clientbound_block_update_packet; pub mod clientbound_boss_event_packet; pub mod clientbound_change_difficulty_packet; -pub mod clientbound_chat_preview_packet; pub mod clientbound_command_suggestions_packet; pub mod clientbound_commands_packet; pub mod clientbound_container_close_packet; @@ -20,9 +19,9 @@ pub mod clientbound_container_set_slot_packet; pub mod clientbound_cooldown_packet; pub mod clientbound_custom_chat_completions_packet; pub mod clientbound_custom_payload_packet; -pub mod clientbound_custom_sound_packet; pub mod clientbound_delete_chat_packet; pub mod clientbound_disconnect_packet; +pub mod clientbound_disguised_chat_packet; pub mod clientbound_entity_event_packet; pub mod clientbound_explode_packet; pub mod clientbound_forget_level_chunk_packet; @@ -47,12 +46,12 @@ pub mod clientbound_open_sign_editor_packet; pub mod clientbound_ping_packet; pub mod clientbound_place_ghost_recipe_packet; pub mod clientbound_player_abilities_packet; -pub mod clientbound_player_chat_header_packet; pub mod clientbound_player_chat_packet; pub mod clientbound_player_combat_end_packet; pub mod clientbound_player_combat_enter_packet; pub mod clientbound_player_combat_kill_packet; -pub mod clientbound_player_info_packet; +pub mod clientbound_player_info_remove_packet; +pub mod clientbound_player_info_update_packet; pub mod clientbound_player_look_at_packet; pub mod clientbound_player_position_packet; pub mod clientbound_recipe_packet; @@ -75,7 +74,6 @@ pub mod clientbound_set_carried_item_packet; pub mod clientbound_set_chunk_cache_center_packet; pub mod clientbound_set_chunk_cache_radius_packet; pub mod clientbound_set_default_spawn_position_packet; -pub mod clientbound_set_display_chat_preview_packet; pub mod clientbound_set_display_objective_packet; pub mod clientbound_set_entity_data_packet; pub mod clientbound_set_entity_link_packet; @@ -102,6 +100,7 @@ pub mod clientbound_take_item_entity_packet; pub mod clientbound_teleport_entity_packet; pub mod clientbound_update_advancements_packet; pub mod clientbound_update_attributes_packet; +pub mod clientbound_update_enabled_features_packet; pub mod clientbound_update_mob_effect_packet; pub mod clientbound_update_recipes_packet; pub mod clientbound_update_tags_packet; @@ -111,7 +110,7 @@ pub mod serverbound_change_difficulty_packet; pub mod serverbound_chat_ack_packet; pub mod serverbound_chat_command_packet; pub mod serverbound_chat_packet; -pub mod serverbound_chat_preview_packet; +pub mod serverbound_chat_session_update_packet; pub mod serverbound_client_command_packet; pub mod serverbound_client_information_packet; pub mod serverbound_command_suggestion_packet; @@ -168,33 +167,33 @@ declare_state_packets!( 0x03: serverbound_chat_ack_packet::ServerboundChatAckPacket, 0x04: serverbound_chat_command_packet::ServerboundChatCommandPacket, 0x05: serverbound_chat_packet::ServerboundChatPacket, - 0x06: serverbound_chat_preview_packet::ServerboundChatPreviewPacket, - 0x07: serverbound_client_command_packet::ServerboundClientCommandPacket, - 0x08: serverbound_client_information_packet::ServerboundClientInformationPacket, - 0x09: serverbound_command_suggestion_packet::ServerboundCommandSuggestionPacket, - 0x0a: serverbound_container_button_click_packet::ServerboundContainerButtonClickPacket, - 0x0b: serverbound_container_click_packet::ServerboundContainerClickPacket, - 0x0c: serverbound_container_close_packet::ServerboundContainerClosePacket, - 0x0d: serverbound_custom_payload_packet::ServerboundCustomPayloadPacket, - 0x0e: serverbound_edit_book_packet::ServerboundEditBookPacket, - 0x0f: serverbound_entity_tag_query::ServerboundEntityTagQuery, - 0x10: serverbound_interact_packet::ServerboundInteractPacket, - 0x11: serverbound_jigsaw_generate_packet::ServerboundJigsawGeneratePacket, - 0x12: serverbound_keep_alive_packet::ServerboundKeepAlivePacket, - 0x13: serverbound_lock_difficulty_packet::ServerboundLockDifficultyPacket, - 0x14: serverbound_move_player_pos_packet::ServerboundMovePlayerPosPacket, - 0x15: serverbound_move_player_pos_rot_packet::ServerboundMovePlayerPosRotPacket, - 0x16: serverbound_move_player_rot_packet::ServerboundMovePlayerRotPacket, - 0x17: serverbound_move_player_status_only_packet::ServerboundMovePlayerStatusOnlyPacket, - 0x18: serverbound_move_vehicle_packet::ServerboundMoveVehiclePacket, - 0x19: serverbound_paddle_boat_packet::ServerboundPaddleBoatPacket, - 0x1a: serverbound_pick_item_packet::ServerboundPickItemPacket, - 0x1b: serverbound_place_recipe_packet::ServerboundPlaceRecipePacket, - 0x1c: serverbound_player_abilities_packet::ServerboundPlayerAbilitiesPacket, - 0x1d: serverbound_player_action_packet::ServerboundPlayerActionPacket, - 0x1e: serverbound_player_command_packet::ServerboundPlayerCommandPacket, - 0x1f: serverbound_player_input_packet::ServerboundPlayerInputPacket, - 0x20: serverbound_pong_packet::ServerboundPongPacket, + 0x06: serverbound_client_command_packet::ServerboundClientCommandPacket, + 0x07: serverbound_client_information_packet::ServerboundClientInformationPacket, + 0x08: serverbound_command_suggestion_packet::ServerboundCommandSuggestionPacket, + 0x09: serverbound_container_button_click_packet::ServerboundContainerButtonClickPacket, + 0x0a: serverbound_container_click_packet::ServerboundContainerClickPacket, + 0x0b: serverbound_container_close_packet::ServerboundContainerClosePacket, + 0x0c: serverbound_custom_payload_packet::ServerboundCustomPayloadPacket, + 0x0d: serverbound_edit_book_packet::ServerboundEditBookPacket, + 0x0e: serverbound_entity_tag_query::ServerboundEntityTagQuery, + 0x0f: serverbound_interact_packet::ServerboundInteractPacket, + 0x10: serverbound_jigsaw_generate_packet::ServerboundJigsawGeneratePacket, + 0x11: serverbound_keep_alive_packet::ServerboundKeepAlivePacket, + 0x12: serverbound_lock_difficulty_packet::ServerboundLockDifficultyPacket, + 0x13: serverbound_move_player_pos_packet::ServerboundMovePlayerPosPacket, + 0x14: serverbound_move_player_pos_rot_packet::ServerboundMovePlayerPosRotPacket, + 0x15: serverbound_move_player_rot_packet::ServerboundMovePlayerRotPacket, + 0x16: serverbound_move_player_status_only_packet::ServerboundMovePlayerStatusOnlyPacket, + 0x17: serverbound_move_vehicle_packet::ServerboundMoveVehiclePacket, + 0x18: serverbound_paddle_boat_packet::ServerboundPaddleBoatPacket, + 0x19: serverbound_pick_item_packet::ServerboundPickItemPacket, + 0x1a: serverbound_place_recipe_packet::ServerboundPlaceRecipePacket, + 0x1b: serverbound_player_abilities_packet::ServerboundPlayerAbilitiesPacket, + 0x1c: serverbound_player_action_packet::ServerboundPlayerActionPacket, + 0x1d: serverbound_player_command_packet::ServerboundPlayerCommandPacket, + 0x1e: serverbound_player_input_packet::ServerboundPlayerInputPacket, + 0x1f: serverbound_pong_packet::ServerboundPongPacket, + 0x20: serverbound_chat_session_update_packet::ServerboundChatSessionUpdatePacket, 0x21: serverbound_recipe_book_change_settings_packet::ServerboundRecipeBookChangeSettingsPacket, 0x22: serverbound_recipe_book_seen_recipe_packet::ServerboundRecipeBookSeenRecipePacket, 0x23: serverbound_rename_item_packet::ServerboundRenameItemPacket, @@ -227,100 +226,99 @@ declare_state_packets!( 0x09: clientbound_block_update_packet::ClientboundBlockUpdatePacket, 0x0a: clientbound_boss_event_packet::ClientboundBossEventPacket, 0x0b: clientbound_change_difficulty_packet::ClientboundChangeDifficultyPacket, - 0x0c: clientbound_chat_preview_packet::ClientboundChatPreviewPacket, - 0x0e: clientbound_command_suggestions_packet::ClientboundCommandSuggestionsPacket, - 0x0f: clientbound_commands_packet::ClientboundCommandsPacket, - 0x10: clientbound_container_close_packet::ClientboundContainerClosePacket, - 0x11: clientbound_container_set_content_packet::ClientboundContainerSetContentPacket, - 0x12: clientbound_container_set_data_packet::ClientboundContainerSetDataPacket, - 0x13: clientbound_container_set_slot_packet::ClientboundContainerSetSlotPacket, - 0x14: clientbound_cooldown_packet::ClientboundCooldownPacket, - 0x15: clientbound_custom_chat_completions_packet::ClientboundCustomChatCompletionsPacket, - 0x16: clientbound_custom_payload_packet::ClientboundCustomPayloadPacket, - 0x17: clientbound_custom_sound_packet::ClientboundCustomSoundPacket, - 0x18: clientbound_delete_chat_packet::ClientboundDeleteChatPacket, - 0x19: clientbound_disconnect_packet::ClientboundDisconnectPacket, - 0x1a: clientbound_entity_event_packet::ClientboundEntityEventPacket, - 0x1b: clientbound_explode_packet::ClientboundExplodePacket, - 0x1c: clientbound_forget_level_chunk_packet::ClientboundForgetLevelChunkPacket, - 0x1d: clientbound_game_event_packet::ClientboundGameEventPacket, - 0x1e: clientbound_horse_screen_open_packet::ClientboundHorseScreenOpenPacket, - 0x1f: clientbound_initialize_border_packet::ClientboundInitializeBorderPacket, - 0x20: clientbound_keep_alive_packet::ClientboundKeepAlivePacket, - 0x21: clientbound_level_chunk_with_light_packet::ClientboundLevelChunkWithLightPacket, - 0x22: clientbound_level_event_packet::ClientboundLevelEventPacket, - 0x23: clientbound_level_particles_packet::ClientboundLevelParticlesPacket, - 0x24: clientbound_light_update_packet::ClientboundLightUpdatePacket, - 0x25: clientbound_login_packet::ClientboundLoginPacket, - 0x26: clientbound_map_item_data_packet::ClientboundMapItemDataPacket, - 0x27: clientbound_merchant_offers_packet::ClientboundMerchantOffersPacket, - 0x28: clientbound_move_entity_pos_packet::ClientboundMoveEntityPosPacket, - 0x29: clientbound_move_entity_pos_rot_packet::ClientboundMoveEntityPosRotPacket, - 0x2a: clientbound_move_entity_rot_packet::ClientboundMoveEntityRotPacket, - 0x2b: clientbound_move_vehicle_packet::ClientboundMoveVehiclePacket, - 0x2c: clientbound_open_book_packet::ClientboundOpenBookPacket, - 0x2d: clientbound_open_screen_packet::ClientboundOpenScreenPacket, - 0x2e: clientbound_open_sign_editor_packet::ClientboundOpenSignEditorPacket, - 0x2f: clientbound_ping_packet::ClientboundPingPacket, - 0x30: clientbound_place_ghost_recipe_packet::ClientboundPlaceGhostRecipePacket, - 0x31: clientbound_player_abilities_packet::ClientboundPlayerAbilitiesPacket, - 0x32: clientbound_player_chat_header_packet::ClientboundPlayerChatHeaderPacket, - 0x33: clientbound_player_chat_packet::ClientboundPlayerChatPacket, - 0x34: clientbound_player_combat_end_packet::ClientboundPlayerCombatEndPacket, - 0x35: clientbound_player_combat_enter_packet::ClientboundPlayerCombatEnterPacket, - 0x36: clientbound_player_combat_kill_packet::ClientboundPlayerCombatKillPacket, - 0x37: clientbound_player_info_packet::ClientboundPlayerInfoPacket, - 0x38: clientbound_player_look_at_packet::ClientboundPlayerLookAtPacket, - 0x39: clientbound_player_position_packet::ClientboundPlayerPositionPacket, - 0x3a: clientbound_recipe_packet::ClientboundRecipePacket, - 0x3b: clientbound_remove_entities_packet::ClientboundRemoveEntitiesPacket, - 0x3c: clientbound_remove_mob_effect_packet::ClientboundRemoveMobEffectPacket, - 0x3d: clientbound_resource_pack_packet::ClientboundResourcePackPacket, - 0x3e: clientbound_respawn_packet::ClientboundRespawnPacket, - 0x3f: clientbound_rotate_head_packet::ClientboundRotateHeadPacket, - 0x40: clientbound_section_blocks_update_packet::ClientboundSectionBlocksUpdatePacket, - 0x41: clientbound_select_advancements_tab_packet::ClientboundSelectAdvancementsTabPacket, - 0x42: clientbound_server_data_packet::ClientboundServerDataPacket, - 0x43: clientbound_set_action_bar_text_packet::ClientboundSetActionBarTextPacket, - 0x44: clientbound_set_border_center_packet::ClientboundSetBorderCenterPacket, - 0x45: clientbound_set_border_lerp_size_packet::ClientboundSetBorderLerpSizePacket, - 0x46: clientbound_set_border_size_packet::ClientboundSetBorderSizePacket, - 0x47: clientbound_set_border_warning_delay_packet::ClientboundSetBorderWarningDelayPacket, - 0x48: clientbound_set_border_warning_distance_packet::ClientboundSetBorderWarningDistancePacket, - 0x49: clientbound_set_camera_packet::ClientboundSetCameraPacket, - 0x4a: clientbound_set_carried_item_packet::ClientboundSetCarriedItemPacket, - 0x4b: clientbound_set_chunk_cache_center_packet::ClientboundSetChunkCacheCenterPacket, - 0x4c: clientbound_set_chunk_cache_radius_packet::ClientboundSetChunkCacheRadiusPacket, - 0x4d: clientbound_set_default_spawn_position_packet::ClientboundSetDefaultSpawnPositionPacket, - 0x4e: clientbound_set_display_chat_preview_packet::ClientboundSetDisplayChatPreviewPacket, - 0x4f: clientbound_set_display_objective_packet::ClientboundSetDisplayObjectivePacket, - 0x50: clientbound_set_entity_data_packet::ClientboundSetEntityDataPacket, - 0x51: clientbound_set_entity_link_packet::ClientboundSetEntityLinkPacket, - 0x52: clientbound_set_entity_motion_packet::ClientboundSetEntityMotionPacket, - 0x53: clientbound_set_equipment_packet::ClientboundSetEquipmentPacket, - 0x54: clientbound_set_experience_packet::ClientboundSetExperiencePacket, - 0x55: clientbound_set_health_packet::ClientboundSetHealthPacket, - 0x56: clientbound_set_objective_packet::ClientboundSetObjectivePacket, - 0x57: clientbound_set_passengers_packet::ClientboundSetPassengersPacket, - 0x58: clientbound_set_player_team_packet::ClientboundSetPlayerTeamPacket, - 0x59: clientbound_set_score_packet::ClientboundSetScorePacket, - 0x5a: clientbound_set_simulation_distance_packet::ClientboundSetSimulationDistancePacket, - 0x5b: clientbound_set_subtitle_text_packet::ClientboundSetSubtitleTextPacket, - 0x5c: clientbound_set_time_packet::ClientboundSetTimePacket, - 0x5d: clientbound_set_title_text_packet::ClientboundSetTitleTextPacket, - 0x5e: clientbound_set_titles_animation_packet::ClientboundSetTitlesAnimationPacket, - 0x5f: clientbound_sound_entity_packet::ClientboundSoundEntityPacket, - 0x60: clientbound_sound_packet::ClientboundSoundPacket, - 0x61: clientbound_stop_sound_packet::ClientboundStopSoundPacket, - 0x62: clientbound_system_chat_packet::ClientboundSystemChatPacket, - 0x63: clientbound_tab_list_packet::ClientboundTabListPacket, - 0x64: clientbound_tag_query_packet::ClientboundTagQueryPacket, - 0x65: clientbound_take_item_entity_packet::ClientboundTakeItemEntityPacket, - 0x66: clientbound_teleport_entity_packet::ClientboundTeleportEntityPacket, - 0x67: clientbound_update_advancements_packet::ClientboundUpdateAdvancementsPacket, - 0x68: clientbound_update_attributes_packet::ClientboundUpdateAttributesPacket, - 0x69: clientbound_update_mob_effect_packet::ClientboundUpdateMobEffectPacket, - 0x6a: clientbound_update_recipes_packet::ClientboundUpdateRecipesPacket, - 0x6b: clientbound_update_tags_packet::ClientboundUpdateTagsPacket, + 0x0d: clientbound_command_suggestions_packet::ClientboundCommandSuggestionsPacket, + 0x0e: clientbound_commands_packet::ClientboundCommandsPacket, + 0x0f: clientbound_container_close_packet::ClientboundContainerClosePacket, + 0x10: clientbound_container_set_content_packet::ClientboundContainerSetContentPacket, + 0x11: clientbound_container_set_data_packet::ClientboundContainerSetDataPacket, + 0x12: clientbound_container_set_slot_packet::ClientboundContainerSetSlotPacket, + 0x13: clientbound_cooldown_packet::ClientboundCooldownPacket, + 0x14: clientbound_custom_chat_completions_packet::ClientboundCustomChatCompletionsPacket, + 0x15: clientbound_custom_payload_packet::ClientboundCustomPayloadPacket, + 0x16: clientbound_delete_chat_packet::ClientboundDeleteChatPacket, + 0x17: clientbound_disconnect_packet::ClientboundDisconnectPacket, + 0x18: clientbound_disguised_chat_packet::ClientboundDisguisedChatPacket, + 0x19: clientbound_entity_event_packet::ClientboundEntityEventPacket, + 0x1a: clientbound_explode_packet::ClientboundExplodePacket, + 0x1b: clientbound_forget_level_chunk_packet::ClientboundForgetLevelChunkPacket, + 0x1c: clientbound_game_event_packet::ClientboundGameEventPacket, + 0x1d: clientbound_horse_screen_open_packet::ClientboundHorseScreenOpenPacket, + 0x1e: clientbound_initialize_border_packet::ClientboundInitializeBorderPacket, + 0x1f: clientbound_keep_alive_packet::ClientboundKeepAlivePacket, + 0x20: clientbound_level_chunk_with_light_packet::ClientboundLevelChunkWithLightPacket, + 0x21: clientbound_level_event_packet::ClientboundLevelEventPacket, + 0x22: clientbound_level_particles_packet::ClientboundLevelParticlesPacket, + 0x23: clientbound_light_update_packet::ClientboundLightUpdatePacket, + 0x24: clientbound_login_packet::ClientboundLoginPacket, + 0x25: clientbound_map_item_data_packet::ClientboundMapItemDataPacket, + 0x26: clientbound_merchant_offers_packet::ClientboundMerchantOffersPacket, + 0x27: clientbound_move_entity_pos_packet::ClientboundMoveEntityPosPacket, + 0x28: clientbound_move_entity_pos_rot_packet::ClientboundMoveEntityPosRotPacket, + 0x29: clientbound_move_entity_rot_packet::ClientboundMoveEntityRotPacket, + 0x2a: clientbound_move_vehicle_packet::ClientboundMoveVehiclePacket, + 0x2b: clientbound_open_book_packet::ClientboundOpenBookPacket, + 0x2c: clientbound_open_screen_packet::ClientboundOpenScreenPacket, + 0x2d: clientbound_open_sign_editor_packet::ClientboundOpenSignEditorPacket, + 0x2e: clientbound_ping_packet::ClientboundPingPacket, + 0x2f: clientbound_place_ghost_recipe_packet::ClientboundPlaceGhostRecipePacket, + 0x30: clientbound_player_abilities_packet::ClientboundPlayerAbilitiesPacket, + 0x31: clientbound_player_chat_packet::ClientboundPlayerChatPacket, + 0x32: clientbound_player_combat_end_packet::ClientboundPlayerCombatEndPacket, + 0x33: clientbound_player_combat_enter_packet::ClientboundPlayerCombatEnterPacket, + 0x34: clientbound_player_combat_kill_packet::ClientboundPlayerCombatKillPacket, + 0x35: clientbound_player_info_remove_packet::ClientboundPlayerInfoRemovePacket, + 0x36: clientbound_player_info_update_packet::ClientboundPlayerInfoUpdatePacket, + 0x37: clientbound_player_look_at_packet::ClientboundPlayerLookAtPacket, + 0x38: clientbound_player_position_packet::ClientboundPlayerPositionPacket, + 0x39: clientbound_recipe_packet::ClientboundRecipePacket, + 0x3a: clientbound_remove_entities_packet::ClientboundRemoveEntitiesPacket, + 0x3b: clientbound_remove_mob_effect_packet::ClientboundRemoveMobEffectPacket, + 0x3c: clientbound_resource_pack_packet::ClientboundResourcePackPacket, + 0x3d: clientbound_respawn_packet::ClientboundRespawnPacket, + 0x3e: clientbound_rotate_head_packet::ClientboundRotateHeadPacket, + 0x3f: clientbound_section_blocks_update_packet::ClientboundSectionBlocksUpdatePacket, + 0x40: clientbound_select_advancements_tab_packet::ClientboundSelectAdvancementsTabPacket, + 0x41: clientbound_server_data_packet::ClientboundServerDataPacket, + 0x42: clientbound_set_action_bar_text_packet::ClientboundSetActionBarTextPacket, + 0x43: clientbound_set_border_center_packet::ClientboundSetBorderCenterPacket, + 0x44: clientbound_set_border_lerp_size_packet::ClientboundSetBorderLerpSizePacket, + 0x45: clientbound_set_border_size_packet::ClientboundSetBorderSizePacket, + 0x46: clientbound_set_border_warning_delay_packet::ClientboundSetBorderWarningDelayPacket, + 0x47: clientbound_set_border_warning_distance_packet::ClientboundSetBorderWarningDistancePacket, + 0x48: clientbound_set_camera_packet::ClientboundSetCameraPacket, + 0x49: clientbound_set_carried_item_packet::ClientboundSetCarriedItemPacket, + 0x4a: clientbound_set_chunk_cache_center_packet::ClientboundSetChunkCacheCenterPacket, + 0x4b: clientbound_set_chunk_cache_radius_packet::ClientboundSetChunkCacheRadiusPacket, + 0x4c: clientbound_set_default_spawn_position_packet::ClientboundSetDefaultSpawnPositionPacket, + 0x4d: clientbound_set_display_objective_packet::ClientboundSetDisplayObjectivePacket, + 0x4e: clientbound_set_entity_data_packet::ClientboundSetEntityDataPacket, + 0x4f: clientbound_set_entity_link_packet::ClientboundSetEntityLinkPacket, + 0x50: clientbound_set_entity_motion_packet::ClientboundSetEntityMotionPacket, + 0x51: clientbound_set_equipment_packet::ClientboundSetEquipmentPacket, + 0x52: clientbound_set_experience_packet::ClientboundSetExperiencePacket, + 0x53: clientbound_set_health_packet::ClientboundSetHealthPacket, + 0x54: clientbound_set_objective_packet::ClientboundSetObjectivePacket, + 0x55: clientbound_set_passengers_packet::ClientboundSetPassengersPacket, + 0x56: clientbound_set_player_team_packet::ClientboundSetPlayerTeamPacket, + 0x57: clientbound_set_score_packet::ClientboundSetScorePacket, + 0x58: clientbound_set_simulation_distance_packet::ClientboundSetSimulationDistancePacket, + 0x59: clientbound_set_subtitle_text_packet::ClientboundSetSubtitleTextPacket, + 0x5a: clientbound_set_time_packet::ClientboundSetTimePacket, + 0x5b: clientbound_set_title_text_packet::ClientboundSetTitleTextPacket, + 0x5c: clientbound_set_titles_animation_packet::ClientboundSetTitlesAnimationPacket, + 0x5d: clientbound_sound_entity_packet::ClientboundSoundEntityPacket, + 0x5e: clientbound_sound_packet::ClientboundSoundPacket, + 0x5f: clientbound_stop_sound_packet::ClientboundStopSoundPacket, + 0x60: clientbound_system_chat_packet::ClientboundSystemChatPacket, + 0x61: clientbound_tab_list_packet::ClientboundTabListPacket, + 0x62: clientbound_tag_query_packet::ClientboundTagQueryPacket, + 0x63: clientbound_take_item_entity_packet::ClientboundTakeItemEntityPacket, + 0x64: clientbound_teleport_entity_packet::ClientboundTeleportEntityPacket, + 0x65: clientbound_update_advancements_packet::ClientboundUpdateAdvancementsPacket, + 0x66: clientbound_update_attributes_packet::ClientboundUpdateAttributesPacket, + 0x67: clientbound_update_enabled_features_packet::ClientboundUpdateEnabledFeaturesPacket, + 0x68: clientbound_update_mob_effect_packet::ClientboundUpdateMobEffectPacket, + 0x69: clientbound_update_recipes_packet::ClientboundUpdateRecipesPacket, + 0x6a: clientbound_update_tags_packet::ClientboundUpdateTagsPacket, } ); diff --git a/azalea-protocol/src/packets/game/serverbound_chat_ack_packet.rs b/azalea-protocol/src/packets/game/serverbound_chat_ack_packet.rs index 19c51de8..998e96d2 100755 --- a/azalea-protocol/src/packets/game/serverbound_chat_ack_packet.rs +++ b/azalea-protocol/src/packets/game/serverbound_chat_ack_packet.rs @@ -1,8 +1,8 @@ -use crate::packets::game::clientbound_player_chat_packet::LastSeenMessagesUpdate; use azalea_buf::McBuf; use azalea_protocol_macros::ServerboundGamePacket; #[derive(Clone, Debug, McBuf, ServerboundGamePacket)] pub struct ServerboundChatAckPacket { - pub last_seen_messages: LastSeenMessagesUpdate, + #[var] + pub offset: u32, } diff --git a/azalea-protocol/src/packets/game/serverbound_chat_command_packet.rs b/azalea-protocol/src/packets/game/serverbound_chat_command_packet.rs index a840e44f..3c36c505 100755 --- a/azalea-protocol/src/packets/game/serverbound_chat_command_packet.rs +++ b/azalea-protocol/src/packets/game/serverbound_chat_command_packet.rs @@ -1,17 +1,14 @@ +use super::serverbound_chat_packet::LastSeenMessagesUpdate; use azalea_buf::McBuf; use azalea_crypto::MessageSignature; use azalea_protocol_macros::ServerboundGamePacket; -use super::clientbound_player_chat_packet::LastSeenMessagesUpdate; - #[derive(Clone, Debug, McBuf, ServerboundGamePacket)] pub struct ServerboundChatCommandPacket { pub command: String, - // TODO: Choose a real timestamp type pub timestamp: u64, pub salt: u64, pub argument_signatures: Vec<ArgumentSignature>, - pub signed_preview: bool, pub last_seen_messages: LastSeenMessagesUpdate, } diff --git a/azalea-protocol/src/packets/game/serverbound_chat_packet.rs b/azalea-protocol/src/packets/game/serverbound_chat_packet.rs index 434474a2..1912d6a0 100755 --- a/azalea-protocol/src/packets/game/serverbound_chat_packet.rs +++ b/azalea-protocol/src/packets/game/serverbound_chat_packet.rs @@ -1,5 +1,5 @@ -use crate::packets::game::clientbound_player_chat_packet::LastSeenMessagesUpdate; use azalea_buf::McBuf; +use azalea_core::FixedBitSet; use azalea_crypto::MessageSignature; use azalea_protocol_macros::ServerboundGamePacket; @@ -8,7 +8,13 @@ pub struct ServerboundChatPacket { pub message: String, pub timestamp: u64, pub salt: u64, - pub signature: MessageSignature, - pub signed_preview: bool, + pub signature: Option<MessageSignature>, pub last_seen_messages: LastSeenMessagesUpdate, } + +#[derive(Clone, Debug, McBuf, Default)] +pub struct LastSeenMessagesUpdate { + #[var] + pub offset: u32, + pub acknowledged: FixedBitSet<20>, +} diff --git a/azalea-protocol/src/packets/game/serverbound_chat_session_update_packet.rs b/azalea-protocol/src/packets/game/serverbound_chat_session_update_packet.rs new file mode 100644 index 00000000..e56d2bc6 --- /dev/null +++ b/azalea-protocol/src/packets/game/serverbound_chat_session_update_packet.rs @@ -0,0 +1,21 @@ +use azalea_buf::McBuf; +use azalea_protocol_macros::ServerboundGamePacket; +use uuid::Uuid; + +#[derive(Clone, Debug, McBuf, ServerboundGamePacket)] +pub struct ServerboundChatSessionUpdatePacket { + pub chat_session: RemoteChatSessionData, +} + +#[derive(Clone, Debug, PartialEq, Eq, McBuf)] +pub struct RemoteChatSessionData { + pub session_id: Uuid, + pub profile_public_key: ProfilePublicKeyData, +} + +#[derive(Clone, Debug, McBuf, PartialEq, Eq)] +pub struct ProfilePublicKeyData { + pub expires_at: u64, + pub key: Vec<u8>, + pub key_signature: Vec<u8>, +} |
