diff options
Diffstat (limited to 'azalea-protocol/src/packets')
5 files changed, 74 insertions, 20 deletions
diff --git a/azalea-protocol/src/packets/game/clientbound_custom_payload_packet.rs b/azalea-protocol/src/packets/game/clientbound_custom_payload_packet.rs new file mode 100644 index 00000000..63047801 --- /dev/null +++ b/azalea-protocol/src/packets/game/clientbound_custom_payload_packet.rs @@ -0,0 +1,30 @@ +use super::GamePacket; +use crate::mc_buf::{Readable, Writable}; +use azalea_core::{game_type::GameType, resource_location::ResourceLocation}; + +#[derive(Clone, Debug)] +pub struct ClientboundCustomPayloadPacket { + pub identifier: ResourceLocation, + pub data: Vec<u8>, +} + +impl ClientboundCustomPayloadPacket { + pub fn get(self) -> GamePacket { + GamePacket::ClientboundCustomPayloadPacket(self) + } + + pub fn write(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> { + buf.write_resource_location(&self.identifier)?; + buf.write_bytes(&self.data)?; + Ok(()) + } + + pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>( + buf: &mut T, + ) -> Result<GamePacket, String> { + let identifier = buf.read_resource_location().await?; + let data = buf.read_bytes().await?; + + Ok(ClientboundCustomPayloadPacket { identifier, data }.get()) + } +} diff --git a/azalea-protocol/src/packets/game/clientbound_login_packet.rs b/azalea-protocol/src/packets/game/clientbound_login_packet.rs index 9043fa1a..0286fce4 100644 --- a/azalea-protocol/src/packets/game/clientbound_login_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_login_packet.rs @@ -4,23 +4,6 @@ use azalea_core::{game_type::GameType, resource_location::ResourceLocation}; #[derive(Clone, Debug)] pub struct ClientboundLoginPacket { - // private final int playerId; - // private final boolean hardcore; - // private final GameType gameType; - // @Nullable - // private final GameType previousGameType; - // private final Set<ResourceKey<Level>> levels; - // private final RegistryAccess.RegistryHolder registryHolder; - // private final DimensionType dimensionType; - // private final ResourceKey<Level> dimension; - // private final long seed; - // private final int maxPlayers; - // private final int chunkRadius; - // private final int simulationDistance; - // private final boolean reducedDebugInfo; - // private final boolean showDeathScreen; - // private final boolean isDebug; - // private final boolean isFlat; pub player_id: i32, pub hardcore: bool, pub game_type: GameType, diff --git a/azalea-protocol/src/packets/game/clientbound_update_view_distance_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_view_distance_packet.rs new file mode 100644 index 00000000..562f8fc2 --- /dev/null +++ b/azalea-protocol/src/packets/game/clientbound_update_view_distance_packet.rs @@ -0,0 +1,28 @@ +// i don't know the actual name of this packet, i couldn't find it in the source code! + +use super::GamePacket; +use crate::mc_buf::{Readable, Writable}; + +#[derive(Clone, Debug)] +pub struct ClientboundUpdateViewDistancePacket { + pub view_distance: i32, +} + +impl ClientboundUpdateViewDistancePacket { + pub fn get(self) -> GamePacket { + GamePacket::ClientboundUpdateViewDistancePacket(self) + } + + pub fn write(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> { + buf.write_varint(self.view_distance)?; + Ok(()) + } + + pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>( + buf: &mut T, + ) -> Result<GamePacket, String> { + let view_distance = buf.read_varint().await?; + + Ok(ClientboundUpdateViewDistancePacket { view_distance }.get()) + } +} diff --git a/azalea-protocol/src/packets/game/mod.rs b/azalea-protocol/src/packets/game/mod.rs index 00fa1d75..ab5ca7e8 100644 --- a/azalea-protocol/src/packets/game/mod.rs +++ b/azalea-protocol/src/packets/game/mod.rs @@ -1,4 +1,6 @@ +pub mod clientbound_custom_payload_packet; pub mod clientbound_login_packet; +pub mod clientbound_update_view_distance_packet; use super::ProtocolPacket; use crate::connect::PacketFlow; @@ -10,13 +12,21 @@ where Self: Sized, { ClientboundLoginPacket(clientbound_login_packet::ClientboundLoginPacket), + ClientboundUpdateViewDistancePacket( + clientbound_update_view_distance_packet::ClientboundUpdateViewDistancePacket, + ), + ClientboundCustomPayloadPacket( + clientbound_custom_payload_packet::ClientboundCustomPayloadPacket, + ), } #[async_trait] impl ProtocolPacket for GamePacket { fn id(&self) -> u32 { match self { - GamePacket::ClientboundLoginPacket(_packet) => 0x00, + GamePacket::ClientboundCustomPayloadPacket(_packet) => 0x18, + GamePacket::ClientboundLoginPacket(_packet) => 0x26, + GamePacket::ClientboundUpdateViewDistancePacket(_packet) => 0x4a, } } @@ -33,8 +43,11 @@ impl ProtocolPacket for GamePacket { { Ok(match flow { PacketFlow::ServerToClient => match id { + 0x18 => clientbound_custom_payload_packet::ClientboundCustomPayloadPacket::read(buf).await?, 0x26 => clientbound_login_packet::ClientboundLoginPacket::read(buf).await?, - + 0x4a => clientbound_update_view_distance_packet::ClientboundUpdateViewDistancePacket + ::read(buf) + .await?, _ => return Err(format!("Unknown ServerToClient game packet id: {}", id)), }, PacketFlow::ClientToServer => match id { diff --git a/azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs b/azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs index 2bc1fc1e..048fa53f 100644 --- a/azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs +++ b/azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs @@ -26,7 +26,7 @@ impl ClientboundCustomQueryPacket { ) -> Result<LoginPacket, String> { let transaction_id = buf.read_varint().await? as u32; let identifier = ResourceLocation::new(&buf.read_utf().await?)?; - let data = buf.read_bytes(1048576).await?; + let data = buf.read_bytes_with_len(1048576).await?; Ok(ClientboundCustomQueryPacket { transaction_id, identifier, |
