aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-protocol/src/packets')
-rw-r--r--azalea-protocol/src/packets/game/ClientboundLoginPacket.rs53
-rw-r--r--azalea-protocol/src/packets/game/mod.rs2
-rw-r--r--azalea-protocol/src/packets/handshake/client_intention_packet.rs2
-rw-r--r--azalea-protocol/src/packets/handshake/mod.rs2
-rw-r--r--azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs2
-rw-r--r--azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs2
-rw-r--r--azalea-protocol/src/packets/login/clientbound_hello_packet.rs2
-rw-r--r--azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs2
-rw-r--r--azalea-protocol/src/packets/login/mod.rs2
-rw-r--r--azalea-protocol/src/packets/login/serverbound_hello_packet.rs2
-rw-r--r--azalea-protocol/src/packets/mod.rs101
-rw-r--r--azalea-protocol/src/packets/status/clientbound_status_response_packet.rs2
-rw-r--r--azalea-protocol/src/packets/status/mod.rs2
-rw-r--r--azalea-protocol/src/packets/status/serverbound_status_request_packet.rs2
14 files changed, 66 insertions, 112 deletions
diff --git a/azalea-protocol/src/packets/game/ClientboundLoginPacket.rs b/azalea-protocol/src/packets/game/ClientboundLoginPacket.rs
new file mode 100644
index 00000000..ec869faa
--- /dev/null
+++ b/azalea-protocol/src/packets/game/ClientboundLoginPacket.rs
@@ -0,0 +1,53 @@
+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<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;
+
+}
+
+impl ClientboundLoginPacket {
+ pub fn get(self) -> GamePacket {
+ GamePacket::ClientboundLoginPacket(self)
+ }
+
+ pub fn write(&self, buf: &mut Vec<u8>) {
+ 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<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
+ buf: &mut T,
+ ) -> Result<GamePacket, 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?;
+ 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 a3ef2541..0391a6b1 100644
--- a/azalea-protocol/src/packets/game/mod.rs
+++ b/azalea-protocol/src/packets/game/mod.rs
@@ -22,7 +22,7 @@ impl ProtocolPacket for GamePacket {
async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
_id: u32,
flow: &PacketFlow,
- _buf: &mut BufReader<T>,
+ _buf: &mut T,
) -> Result<GamePacket, String>
where
Self: Sized,
diff --git a/azalea-protocol/src/packets/handshake/client_intention_packet.rs b/azalea-protocol/src/packets/handshake/client_intention_packet.rs
index 868626b3..5b50c7cc 100644
--- a/azalea-protocol/src/packets/handshake/client_intention_packet.rs
+++ b/azalea-protocol/src/packets/handshake/client_intention_packet.rs
@@ -28,7 +28,7 @@ impl ClientIntentionPacket {
}
pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
- _buf: &mut BufReader<T>,
+ _buf: &mut T,
) -> Result<HandshakePacket, String> {
Err("ClientIntentionPacket::parse not implemented".to_string())
// Ok(ClientIntentionPacket {}.get())
diff --git a/azalea-protocol/src/packets/handshake/mod.rs b/azalea-protocol/src/packets/handshake/mod.rs
index 01010e1e..70e1a90d 100644
--- a/azalea-protocol/src/packets/handshake/mod.rs
+++ b/azalea-protocol/src/packets/handshake/mod.rs
@@ -33,7 +33,7 @@ impl ProtocolPacket for HandshakePacket {
async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
id: u32,
flow: &PacketFlow,
- buf: &mut BufReader<T>,
+ buf: &mut T,
) -> Result<HandshakePacket, String>
where
Self: Sized,
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 2c66bfa3..ed9820ef 100644
--- a/azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs
+++ b/azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs
@@ -23,7 +23,7 @@ impl ClientboundCustomQueryPacket {
}
pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
- buf: &mut BufReader<T>,
+ buf: &mut T,
) -> Result<LoginPacket, String> {
let transaction_id = buf.read_varint().await? as u32;
let identifier = ResourceLocation::new(&buf.read_utf().await?)?;
diff --git a/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs b/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs
index 04ba5369..da51f115 100644
--- a/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs
+++ b/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs
@@ -23,7 +23,7 @@ impl ClientboundGameProfilePacket {
}
pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
- buf: &mut BufReader<T>,
+ buf: &mut T,
) -> Result<LoginPacket, String> {
let uuid = Uuid::from_int_array([
buf.read_int().await? as u32,
diff --git a/azalea-protocol/src/packets/login/clientbound_hello_packet.rs b/azalea-protocol/src/packets/login/clientbound_hello_packet.rs
index 36a48706..46ca1301 100644
--- a/azalea-protocol/src/packets/login/clientbound_hello_packet.rs
+++ b/azalea-protocol/src/packets/login/clientbound_hello_packet.rs
@@ -22,7 +22,7 @@ impl ClientboundHelloPacket {
}
pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
- buf: &mut BufReader<T>,
+ buf: &mut T,
) -> Result<LoginPacket, String> {
let server_id = buf.read_utf_with_len(20).await?;
let public_key = buf.read_byte_array().await?;
diff --git a/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs b/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs
index 53c6c9e1..e5009985 100644
--- a/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs
+++ b/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs
@@ -20,7 +20,7 @@ impl ClientboundLoginCompressionPacket {
}
pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
- buf: &mut BufReader<T>,
+ buf: &mut T,
) -> Result<LoginPacket, String> {
let compression_threshold = buf.read_varint().await?;
diff --git a/azalea-protocol/src/packets/login/mod.rs b/azalea-protocol/src/packets/login/mod.rs
index 7fee684a..377a285a 100644
--- a/azalea-protocol/src/packets/login/mod.rs
+++ b/azalea-protocol/src/packets/login/mod.rs
@@ -51,7 +51,7 @@ impl ProtocolPacket for LoginPacket {
async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
id: u32,
flow: &PacketFlow,
- buf: &mut BufReader<T>,
+ buf: &mut T,
) -> Result<LoginPacket, String>
where
Self: Sized,
diff --git a/azalea-protocol/src/packets/login/serverbound_hello_packet.rs b/azalea-protocol/src/packets/login/serverbound_hello_packet.rs
index 32a6dadc..011cc590 100644
--- a/azalea-protocol/src/packets/login/serverbound_hello_packet.rs
+++ b/azalea-protocol/src/packets/login/serverbound_hello_packet.rs
@@ -20,7 +20,7 @@ impl ServerboundHelloPacket {
}
pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
- _buf: &mut BufReader<T>,
+ _buf: &mut T,
) -> Result<LoginPacket, String> {
Err("ServerboundHelloPacket::read not implemented".to_string())
}
diff --git a/azalea-protocol/src/packets/mod.rs b/azalea-protocol/src/packets/mod.rs
index a074b570..08c94509 100644
--- a/azalea-protocol/src/packets/mod.rs
+++ b/azalea-protocol/src/packets/mod.rs
@@ -38,109 +38,10 @@ where
async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
id: u32,
flow: &PacketFlow,
- buf: &mut BufReader<T>,
+ buf: &mut T,
) -> Result<Self, String>
where
Self: Sized;
fn write(&self, buf: &mut Vec<u8>);
}
-
-// impl Packet {
-// fn get_inner_packet(&self) -> &dyn PacketTrait {
-// match self {
-// Packet::ClientIntentionPacket(packet) => packet,
-// Packet::ServerboundStatusRequestPacket(packet) => packet,
-// Packet::ClientboundStatusResponsePacket(packet) => packet,
-// Packet::ServerboundHelloPacket(packet) => packet,
-// Packet::ClientboundHelloPacket(packet) => packet,
-// }
-// }
-
-// pub fn id(&self) -> u32 {
-// match self {
-// Packet::ClientIntentionPacket(_packet) => 0x00,
-// Packet::ServerboundStatusRequestPacket(_packet) => 0x00,
-// Packet::ClientboundStatusResponsePacket(_packet) => 0x00,
-// Packet::ServerboundHelloPacket(_packet) => 0x00,
-// Packet::ClientboundHelloPacket(_packet) => 0x01,
-// }
-// }
-
-// /// Read a packet by its id, ConnectionProtocol, and flow
-// pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
-// id: u32,
-// protocol: &ConnectionProtocol,
-// flow: &PacketFlow,
-// buf: &mut BufReader<T>,
-// ) -> Result<Packet, String> {
-// match protocol {
-// ConnectionProtocol::Handshake => match flow {
-// PacketFlow::ClientToServer => match id {
-// 0x00 => Ok(
-// handshake::client_intention_packet::ClientIntentionPacket::read(buf).await?,
-// ),
-// _ => Err(format!("Unknown ClientToServer handshake packet id: {}", id)),
-// }
-// PacketFlow::ServerToClient => Err("ServerToClient handshake packets not implemented".to_string()),
-// },
-
-// ConnectionProtocol::Game => Err("Game protocol not implemented yet".to_string()),
-
-// ConnectionProtocol::Status => match flow {
-// PacketFlow::ServerToClient => match id {
-// 0x00 => Ok(
-// status::clientbound_status_response_packet::ClientboundStatusResponsePacket
-// ::read(buf)
-// .await?,
-// ),
-// _ => Err(format!("Unknown ServerToClient status packet id: {}", id)),
-// },
-// PacketFlow::ClientToServer => match id {
-// 0x00 => Ok(
-// status::serverbound_status_request_packet::ServerboundStatusRequestPacket
-// ::read(buf)
-// .await?,
-// ),
-// _ => Err(format!("Unknown ClientToServer status packet id: {}", id)),
-// },
-// },
-
-// ConnectionProtocol::Login => match flow {
-// PacketFlow::ServerToClient => match id {
-// 0x01 => Ok(
-// login::clientbound_hello_packet::ClientboundHelloPacket::read(buf).await?,
-// ),
-// _ => Err(format!("Unknown ServerToClient login packet id: {}", id)),
-// },
-// PacketFlow::ClientToServer => match id {
-// 0x00 => Ok(
-// login::serverbound_hello_packet::ServerboundHelloPacket::read(buf).await?,
-// ),
-// _ => Err(format!("Unknown ClientToServer login packet id: {}", id)),
-// },
-// },
-// }
-// }
-
-// pub fn write(&self, buf: &mut Vec<u8>) {
-// self.get_inner_packet().write(buf);
-// }
-// }
-
-// #[async_trait]
-// pub trait PacketTrait
-// where
-// Self: Sized,
-// {
-// /// Return a version of the packet that you can actually use for stuff
-// fn get(self) -> dyn ProtocolPacket;
-
-// fn write(&self, buf: &mut Vec<u8>);
-
-// async fn read<T: AsyncRead + std::marker::Unpin + std::marker::Send, P: ProtocolPacket>(
-// buf: &mut BufReader<T>,
-// ) -> Result<P, String>
-// where
-// Self: Sized;
-// }
diff --git a/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs b/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs
index 1d8a3aa4..35f913ff 100644
--- a/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs
+++ b/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs
@@ -43,7 +43,7 @@ impl ClientboundStatusResponsePacket {
pub fn write(&self, _buf: &mut Vec<u8>) {}
pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
- buf: &mut BufReader<T>,
+ buf: &mut T,
) -> Result<StatusPacket, String> {
let status_string = buf.read_utf().await?;
let status_json: Value =
diff --git a/azalea-protocol/src/packets/status/mod.rs b/azalea-protocol/src/packets/status/mod.rs
index ac6a34e1..9531111a 100644
--- a/azalea-protocol/src/packets/status/mod.rs
+++ b/azalea-protocol/src/packets/status/mod.rs
@@ -41,7 +41,7 @@ impl ProtocolPacket for StatusPacket {
async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
id: u32,
flow: &PacketFlow,
- buf: &mut BufReader<T>,
+ buf: &mut T,
) -> Result<StatusPacket, String>
where
Self: Sized,
diff --git a/azalea-protocol/src/packets/status/serverbound_status_request_packet.rs b/azalea-protocol/src/packets/status/serverbound_status_request_packet.rs
index 6a58da1f..dce9b93a 100644
--- a/azalea-protocol/src/packets/status/serverbound_status_request_packet.rs
+++ b/azalea-protocol/src/packets/status/serverbound_status_request_packet.rs
@@ -16,7 +16,7 @@ impl ServerboundStatusRequestPacket {
}
pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
- _buf: &mut BufReader<T>,
+ _buf: &mut T,
) -> Result<StatusPacket, String> {
Err("ServerboundStatusRequestPacket::read not implemented".to_string())
}