From 8e3ba097b48543a85f2cf487d5db90add3f28bac Mon Sep 17 00:00:00 2001 From: mat Date: Sat, 18 Dec 2021 10:04:10 -0600 Subject: start adding clientbound_login_packet --- .../src/packets/game/ClientboundLoginPacket.rs | 53 -------------------- .../src/packets/game/clientbound_login_packet.rs | 57 ++++++++++++++++++++++ azalea-protocol/src/packets/game/mod.rs | 12 +++-- .../login/clientbound_custom_query_packet.rs | 1 - azalea-protocol/src/packets/login/mod.rs | 7 +-- 5 files changed, 66 insertions(+), 64 deletions(-) delete mode 100644 azalea-protocol/src/packets/game/ClientboundLoginPacket.rs create mode 100644 azalea-protocol/src/packets/game/clientbound_login_packet.rs (limited to 'azalea-protocol/src/packets') diff --git a/azalea-protocol/src/packets/game/ClientboundLoginPacket.rs b/azalea-protocol/src/packets/game/ClientboundLoginPacket.rs deleted file mode 100644 index ec869faa..00000000 --- a/azalea-protocol/src/packets/game/ClientboundLoginPacket.rs +++ /dev/null @@ -1,53 +0,0 @@ -use super::GamePacket; -use crate::mc_buf::{Readable, Writable}; -use azalea_core::resource_location::ResourceLocation; -use std::hash::Hash; -use tokio::io::BufReader; - -#[derive(Hash, 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> levels; - // private final RegistryAccess.RegistryHolder registryHolder; - // private final DimensionType dimensionType; - // private final ResourceKey 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; - -} - -impl ClientboundLoginPacket { - pub fn get(self) -> GamePacket { - GamePacket::ClientboundLoginPacket(self) - } - - pub fn write(&self, buf: &mut Vec) { - buf.write_varint(self.transaction_id as i32).unwrap(); - buf.write_utf(self.identifier.to_string().as_str()).unwrap(); - buf.write_bytes(&self.data).unwrap(); - } - - pub async fn read( - buf: &mut T, - ) -> Result { - let transaction_id = buf.read_varint().await? as u32; - let identifier = ResourceLocation::new(&buf.read_utf().await?)?; - let data = buf.read_bytes(1048576).await?; - Ok(ClientboundLoginPacket { - transaction_id, - 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 new file mode 100644 index 00000000..fc701d9d --- /dev/null +++ b/azalea-protocol/src/packets/game/clientbound_login_packet.rs @@ -0,0 +1,57 @@ +use super::GamePacket; +use crate::mc_buf::{Readable, Writable}; +use azalea_core::{game_type::GameType, resource_location::ResourceLocation}; +use std::hash::Hash; + +#[derive(Hash, 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> levels; + // private final RegistryAccess.RegistryHolder registryHolder; + // private final DimensionType dimensionType; + // private final ResourceKey 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, + pub previous_game_type: Option, + pub levels: Vec, + pub registry_holder: azalea_core::registry::RegistryAccess, +} + +impl ClientboundLoginPacket { + pub fn get(self) -> GamePacket { + GamePacket::ClientboundLoginPacket(self) + } + + pub fn write(&self, buf: &mut Vec) { + buf.write_int(self.player_id); + buf.write_bool(self.hardcore); + // buf.write_byte(self.game_type. + } + + pub async fn read( + buf: &mut T, + ) -> Result { + let transaction_id = buf.read_varint().await? as u32; + let identifier = ResourceLocation::new(&buf.read_utf().await?)?; + let data = buf.read_bytes(1048576).await?; + Ok(ClientboundLoginPacket { + transaction_id, + identifier, + data, + } + .get()) + } +} diff --git a/azalea-protocol/src/packets/game/mod.rs b/azalea-protocol/src/packets/game/mod.rs index 0391a6b1..73f66c33 100644 --- a/azalea-protocol/src/packets/game/mod.rs +++ b/azalea-protocol/src/packets/game/mod.rs @@ -1,9 +1,9 @@ -use async_trait::async_trait; -use tokio::io::BufReader; - -use crate::connect::PacketFlow; +pub mod clientbound_login_packet; use super::ProtocolPacket; +use crate::connect::PacketFlow; +use async_trait::async_trait; +use tokio::io::BufReader; #[derive(Clone, Debug)] pub enum GamePacket @@ -13,7 +13,9 @@ where #[async_trait] impl ProtocolPacket for GamePacket { fn id(&self) -> u32 { - 0x00 + match self { + GamePacket::ClientboundLoginPacket(_packet) => 0x00, + } } fn write(&self, _buf: &mut Vec) {} 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 ed9820ef..2bc1fc1e 100644 --- a/azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs +++ b/azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs @@ -2,7 +2,6 @@ use super::LoginPacket; use crate::mc_buf::{Readable, Writable}; use azalea_core::resource_location::ResourceLocation; use std::hash::Hash; -use tokio::io::BufReader; #[derive(Hash, Clone, Debug)] pub struct ClientboundCustomQueryPacket { diff --git a/azalea-protocol/src/packets/login/mod.rs b/azalea-protocol/src/packets/login/mod.rs index 377a285a..65d94bed 100644 --- a/azalea-protocol/src/packets/login/mod.rs +++ b/azalea-protocol/src/packets/login/mod.rs @@ -4,12 +4,9 @@ pub mod clientbound_hello_packet; pub mod clientbound_login_compression_packet; pub mod serverbound_hello_packet; -use async_trait::async_trait; -use tokio::io::BufReader; - -use crate::connect::PacketFlow; - use super::ProtocolPacket; +use crate::connect::PacketFlow; +use async_trait::async_trait; #[derive(Clone, Debug)] pub enum LoginPacket -- cgit v1.2.3