aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets/game/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-protocol/src/packets/game/mod.rs')
-rwxr-xr-x[-rw-r--r--]azalea-protocol/src/packets/game/mod.rs65
1 files changed, 23 insertions, 42 deletions
diff --git a/azalea-protocol/src/packets/game/mod.rs b/azalea-protocol/src/packets/game/mod.rs
index 00fa1d75..dde3f753 100644..100755
--- a/azalea-protocol/src/packets/game/mod.rs
+++ b/azalea-protocol/src/packets/game/mod.rs
@@ -1,46 +1,27 @@
+pub mod clientbound_change_difficulty_packet;
+pub mod clientbound_custom_payload_packet;
+pub mod clientbound_declare_commands_packet;
+pub mod clientbound_disconnect_packet;
pub mod clientbound_login_packet;
+pub mod clientbound_player_abilities_packet;
+pub mod clientbound_set_carried_item_packet;
+pub mod clientbound_update_tags_packet;
+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),
-}
-
-#[async_trait]
-impl ProtocolPacket for GamePacket {
- fn id(&self) -> u32 {
- match self {
- GamePacket::ClientboundLoginPacket(_packet) => 0x00,
- }
- }
-
- fn write(&self, _buf: &mut Vec<u8>) {}
-
- /// 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 {
- 0x26 => clientbound_login_packet::ClientboundLoginPacket::read(buf).await?,
-
- _ => return Err(format!("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)),
- },
- })
+declare_state_packets!(
+ GamePacket,
+ Serverbound => {},
+ Clientbound => {
+ 0x0e: clientbound_change_difficulty_packet::ClientboundChangeDifficultyPacket,
+ 0x12: clientbound_declare_commands_packet::ClientboundDeclareCommandsPacket,
+ 0x1a: clientbound_disconnect_packet::ClientboundDisconnectPacket,
+ 0x18: clientbound_custom_payload_packet::ClientboundCustomPayloadPacket,
+ 0x26: clientbound_login_packet::ClientboundLoginPacket,
+ 0x32: clientbound_player_abilities_packet::ClientboundPlayerAbilitiesPacket,
+ 0x48: clientbound_set_carried_item_packet::ClientboundSetCarriedItemPacket,
+ 0x4a: clientbound_update_view_distance_packet::ClientboundUpdateViewDistancePacket,
+ 0x67: clientbound_update_tags_packet::ClientboundUpdateTagsPacket
}
-}
+);