1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 14:26:04 +00:00

fix broken packets

This commit is contained in:
mat 2025-03-16 22:54:42 +00:00
parent acb1c4b147
commit e5cb133c84
12 changed files with 46 additions and 140 deletions

View file

@ -5,7 +5,7 @@ use azalea_protocol::packets::{
ConnectionProtocol, Packet,
config::{ClientboundFinishConfiguration, ClientboundRegistryData},
};
use azalea_registry::DimensionType;
use azalea_registry::{DataRegistry, DimensionType};
use azalea_world::InstanceName;
use bevy_log::tracing_subscriber;
use simdnbt::owned::{NbtCompound, NbtTag};

View file

@ -5,7 +5,7 @@ use azalea_protocol::packets::{
ConnectionProtocol,
config::{ClientboundFinishConfiguration, ClientboundRegistryData},
};
use azalea_registry::{DimensionType, EntityKind};
use azalea_registry::{DataRegistry, DimensionType, EntityKind};
use bevy_ecs::query::With;
use bevy_log::tracing_subscriber;
use simdnbt::owned::{NbtCompound, NbtTag};

View file

@ -2,7 +2,7 @@ use azalea_client::test_simulation::*;
use azalea_core::{position::ChunkPos, resource_location::ResourceLocation};
use azalea_entity::metadata::Cow;
use azalea_protocol::packets::{ConnectionProtocol, game::ClientboundMoveEntityRot};
use azalea_registry::{DimensionType, EntityKind};
use azalea_registry::{DataRegistry, DimensionType, EntityKind};
use azalea_world::MinecraftEntityId;
use bevy_ecs::query::With;
use bevy_log::tracing_subscriber;

View file

@ -6,7 +6,7 @@ use azalea_protocol::packets::{
config::{ClientboundFinishConfiguration, ClientboundRegistryData},
game::ClientboundSetHealth,
};
use azalea_registry::DimensionType;
use azalea_registry::{DataRegistry, DimensionType};
use bevy_log::tracing_subscriber;
use simdnbt::owned::{NbtCompound, NbtTag};

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,7 @@
use azalea_buf::AzBuf;
use azalea_chat::{
translatable_component::{StringOrComponent, TranslatableComponent},
FormattedText,
translatable_component::{StringOrComponent, TranslatableComponent},
};
use azalea_protocol_macros::ClientboundGamePacket;
@ -25,8 +25,6 @@ impl ClientboundDisguisedChat {
let content = self.message.clone();
let target = self.chat_type.target_name.clone();
let translation_key = self.chat_type.chat_type.chat_translation_key();
let mut args = vec![
StringOrComponent::FormattedText(sender),
StringOrComponent::FormattedText(content),
@ -35,6 +33,7 @@ impl ClientboundDisguisedChat {
args.push(StringOrComponent::FormattedText(target));
}
let translation_key = self.chat_type.translation_key();
let component = TranslatableComponent::new(translation_key.to_string(), args);
FormattedText::Translatable(component)

File diff suppressed because one or more lines are too long

View file

@ -2,17 +2,20 @@ use std::io::{Cursor, Write};
use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError};
use azalea_chat::{
translatable_component::{StringOrComponent, TranslatableComponent},
FormattedText,
translatable_component::{StringOrComponent, TranslatableComponent},
};
use azalea_core::bitset::BitSet;
use azalea_crypto::MessageSignature;
use azalea_protocol_macros::ClientboundGamePacket;
use azalea_registry::{ChatType, OptionalRegistry};
use azalea_registry::Holder;
use simdnbt::owned::NbtCompound;
use uuid::Uuid;
#[derive(Clone, Debug, AzBuf, ClientboundGamePacket, PartialEq)]
pub struct ClientboundPlayerChat {
#[var]
pub global_index: u32,
pub sender: Uuid,
#[var]
pub index: u32,
@ -52,34 +55,30 @@ pub enum FilterMask {
PartiallyFiltered(BitSet),
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, AzBuf)]
pub struct ChatTypeBound {
pub chat_type: ChatType,
pub chat_type: Holder<azalea_registry::ChatType, DirectChatType>,
pub name: FormattedText,
pub target_name: Option<FormattedText>,
}
impl AzaleaRead for ChatTypeBound {
fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
let Some(chat_type) = OptionalRegistry::<ChatType>::azalea_read(buf)?.0 else {
return Err(BufReadError::Custom("ChatType cannot be None".to_owned()));
};
let name = FormattedText::azalea_read(buf)?;
let target_name = Option::<FormattedText>::azalea_read(buf)?;
Ok(ChatTypeBound {
chat_type,
name,
target_name,
})
#[derive(Clone, Debug, PartialEq, AzBuf)]
pub struct DirectChatType {
pub chat: ChatTypeDecoration,
pub narration: ChatTypeDecoration,
}
#[derive(Clone, Debug, PartialEq, AzBuf)]
pub struct ChatTypeDecoration {
pub translation_key: String,
pub parameters: Vec<ChatTypeDecorationParameter>,
pub style: NbtCompound,
}
impl AzaleaWrite for ChatTypeBound {
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
OptionalRegistry(Some(self.chat_type)).azalea_write(buf)?;
self.name.azalea_write(buf)?;
self.target_name.azalea_write(buf)?;
Ok(())
}
#[derive(Clone, Copy, Debug, PartialEq, AzBuf)]
pub enum ChatTypeDecorationParameter {
Sender = 0,
Target = 1,
Content = 2,
}
// must be in Client
@ -106,8 +105,6 @@ impl ClientboundPlayerChat {
let content = self.content();
let target = self.chat_type.target_name.clone();
let translation_key = self.chat_type.chat_type.chat_translation_key();
let mut args = vec![
StringOrComponent::FormattedText(sender),
StringOrComponent::FormattedText(content),
@ -116,12 +113,22 @@ impl ClientboundPlayerChat {
args.push(StringOrComponent::FormattedText(target));
}
let translation_key = self.chat_type.translation_key();
let component = TranslatableComponent::new(translation_key.to_string(), args);
FormattedText::Translatable(component)
}
}
impl ChatTypeBound {
pub fn translation_key<'a>(&'a self) -> &'a str {
match &self.chat_type {
Holder::Reference(r) => r.chat_translation_key(),
Holder::Direct(d) => d.chat.translation_key.as_str(),
}
}
}
impl AzaleaRead for PackedMessageSignature {
fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
let id = u32::azalea_read_var(buf)?;

View file

@ -80,22 +80,3 @@ impl EquipmentSlot {
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_hypixel_set_equipment() {
let mut cursor = Cursor::new(
[
230, 25, 0, 1, 224, 6, 2, 0, 3, 0, 22, 79, 0, 0, 0, 3, 0, 0, 0, 0, 0,
]
.as_slice(),
);
let packet = ClientboundSetEquipment::azalea_read(&mut cursor).unwrap();
println!("packet {packet:?}");
assert_eq!(cursor.position(), cursor.get_ref().len() as u64);
}
}

View file

@ -162,6 +162,7 @@ mod tests {
)]
.into_iter()
.collect(),
show_advancements: false,
};
let mut data = Vec::new();

View file

@ -5,6 +5,7 @@ use azalea_protocol_macros::ServerboundGamePacket;
#[derive(Clone, Debug, AzBuf, ServerboundGamePacket)]
pub struct ServerboundChat {
#[limit(256)]
pub message: String,
pub timestamp: u64,
pub salt: u64,
@ -15,6 +16,7 @@ pub struct ServerboundChat {
#[derive(Clone, Debug, AzBuf, Default)]
pub struct LastSeenMessagesUpdate {
#[var]
pub messages: u32,
pub offset: u32,
pub acknowledged: FixedBitSet<{ 20_usize.div_ceil(8) }>,
pub checksum: u8,
}

View file

@ -158,10 +158,9 @@ impl<R: Registry, Direct: AzaleaRead + AzaleaWrite> AzaleaRead for Holder<R, Dir
if id == 0 {
Ok(Self::Direct(Direct::azalea_read(buf)?))
} else {
let Some(value) = R::from_u32(id - 1) else {
return Err(BufReadError::UnexpectedEnumVariant {
id: (id - 1) as i32,
});
let id = id - 1;
let Some(value) = R::from_u32(id) else {
return Err(BufReadError::UnexpectedEnumVariant { id: id as i32 });
};
Ok(Self::Reference(value))
}