aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets/game
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-04-19 00:48:13 -0500
committermat <github@matdoes.dev>2022-04-19 00:48:13 -0500
commitf60426cd5a8a276adcb88988cef38d27f48de912 (patch)
treea7bb1e5b55e8ebc458477d0df759f9b11b3deb75 /azalea-protocol/src/packets/game
parent747bfa568cb1da8afdeb29005bdd2836963ed613 (diff)
downloadazalea-drasl-f60426cd5a8a276adcb88988cef38d27f48de912.tar.xz
start adding declare_state_packets
Diffstat (limited to 'azalea-protocol/src/packets/game')
-rw-r--r--azalea-protocol/src/packets/game/mod.rs139
1 files changed, 76 insertions, 63 deletions
diff --git a/azalea-protocol/src/packets/game/mod.rs b/azalea-protocol/src/packets/game/mod.rs
index 4efe72fb..cb07cf97 100644
--- a/azalea-protocol/src/packets/game/mod.rs
+++ b/azalea-protocol/src/packets/game/mod.rs
@@ -6,70 +6,83 @@ pub mod clientbound_update_view_distance_packet;
use super::ProtocolPacket;
use crate::connect::PacketFlow;
use async_trait::async_trait;
+use packet_macros::declare_state_packets;
-#[derive(Clone, Debug)]
-pub enum GamePacket
-where
- Self: Sized,
-{
- ClientboundLoginPacket(clientbound_login_packet::ClientboundLoginPacket),
- ClientboundUpdateViewDistancePacket(
- clientbound_update_view_distance_packet::ClientboundUpdateViewDistancePacket,
- ),
- ClientboundCustomPayloadPacket(
- clientbound_custom_payload_packet::ClientboundCustomPayloadPacket,
- ),
- ClientboundChangeDifficultyPacket(
- clientbound_change_difficulty_packet::ClientboundChangeDifficultyPacket,
- ),
-}
-
-#[async_trait]
-impl ProtocolPacket for GamePacket {
- fn id(&self) -> u32 {
- match self {
- GamePacket::ClientboundChangeDifficultyPacket(_packet) => 0x0e,
- GamePacket::ClientboundCustomPayloadPacket(_packet) => 0x18,
- GamePacket::ClientboundLoginPacket(_packet) => 0x26,
- GamePacket::ClientboundUpdateViewDistancePacket(_packet) => 0x4a,
- }
+declare_state_packets!(
+ GamePacket,
+ // no serverbound packets implemented yet
+ Serverbound => {},
+ Clientbound => {
+ 0x0e: clientbound_change_difficulty_packet::ClientboundChangeDifficultyPacket,
+ 0x18: clientbound_custom_payload_packet::ClientboundCustomPayloadPacket,
+ 0x26: clientbound_login_packet::ClientboundLoginPacket,
+ 0x4a: clientbound_update_view_distance_packet::ClientboundUpdateViewDistancePacket,
}
+);
- fn write(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
- match self {
- GamePacket::ClientboundChangeDifficultyPacket(packet) => packet.write(buf),
- GamePacket::ClientboundCustomPayloadPacket(packet) => packet.write(buf),
- GamePacket::ClientboundLoginPacket(packet) => packet.write(buf),
- GamePacket::ClientboundUpdateViewDistancePacket(packet) => packet.write(buf),
- }
- }
+// #[derive(Clone, Debug)]
+// pub enum GamePacket
+// where
+// Self: Sized,
+// {
+// ClientboundLoginPacket(clientbound_login_packet::ClientboundLoginPacket),
+// ClientboundUpdateViewDistancePacket(
+// clientbound_update_view_distance_packet::ClientboundUpdateViewDistancePacket,
+// ),
+// ClientboundCustomPayloadPacket(
+// clientbound_custom_payload_packet::ClientboundCustomPayloadPacket,
+// ),
+// ClientboundChangeDifficultyPacket(
+// clientbound_change_difficulty_packet::ClientboundChangeDifficultyPacket,
+// ),
+// }
- /// Read a packet by its id, ConnectionProtocol, and flow
- async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
- id: u32,
- flow: &PacketFlow,
- buf: &mut T,
- ) -> Result<GamePacket, String>
- where
- Self: Sized,
- {
- Ok(match flow {
- PacketFlow::ServerToClient => match id {
- 0x0e => clientbound_change_difficulty_packet::ClientboundChangeDifficultyPacket
- ::read(buf)
- .await?,
- 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)),
- _ => panic!("Unknown ServerToClient game packet id: {}", id),
- },
- PacketFlow::ClientToServer => match id {
- // 0x00 => serverbound_hello_packet::ServerboundHelloPacket::read(buf).await?,
- _ => return Err(format!("Unknown ClientToServer game packet id: {}", id)),
- },
- })
- }
-}
+// #[async_trait]
+// impl ProtocolPacket for GamePacket {
+// fn id(&self) -> u32 {
+// match self {
+// GamePacket::ClientboundChangeDifficultyPacket(_packet) => 0x0e,
+// GamePacket::ClientboundCustomPayloadPacket(_packet) => 0x18,
+// GamePacket::ClientboundLoginPacket(_packet) => 0x26,
+// GamePacket::ClientboundUpdateViewDistancePacket(_packet) => 0x4a,
+// }
+// }
+
+// fn write(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+// match self {
+// GamePacket::ClientboundChangeDifficultyPacket(packet) => packet.write(buf),
+// GamePacket::ClientboundCustomPayloadPacket(packet) => packet.write(buf),
+// GamePacket::ClientboundLoginPacket(packet) => packet.write(buf),
+// GamePacket::ClientboundUpdateViewDistancePacket(packet) => packet.write(buf),
+// }
+// }
+
+// /// Read a packet by its id, ConnectionProtocol, and flow
+// async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
+// id: u32,
+// flow: &PacketFlow,
+// buf: &mut T,
+// ) -> Result<GamePacket, String>
+// where
+// Self: Sized,
+// {
+// Ok(match flow {
+// PacketFlow::ServerToClient => match id {
+// 0x0e => clientbound_change_difficulty_packet::ClientboundChangeDifficultyPacket
+// ::read(buf)
+// .await?,
+// 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)),
+// _ => panic!("Unknown ServerToClient game packet id: {}", id),
+// },
+// PacketFlow::ClientToServer => match id {
+// // 0x00 => serverbound_hello_packet::ServerboundHelloPacket::read(buf).await?,
+// _ => return Err(format!("Unknown ClientToServer game packet id: {}", id)),
+// },
+// })
+// }
+// }