diff options
| author | mat <github@matdoes.dev> | 2022-04-19 20:35:21 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-04-19 20:35:21 -0500 |
| commit | 58e58dfa8f6e2cb1a6435016be08ff3de3d8d94a (patch) | |
| tree | f594d20500fe35b2f8f1da1153a823c62d291ba4 /azalea-protocol/src/packets/handshake/mod.rs | |
| parent | 751098b636c9aee54b9ca7a465fdaa769f10be4d (diff) | |
| parent | 5fd87615cf1514c7f9a0358988964768ded3f06e (diff) | |
| download | azalea-drasl-58e58dfa8f6e2cb1a6435016be08ff3de3d8d94a.tar.xz | |
Merge branch 'main' into declare-commands-packet
Diffstat (limited to 'azalea-protocol/src/packets/handshake/mod.rs')
| -rw-r--r-- | azalea-protocol/src/packets/handshake/mod.rs | 51 |
1 files changed, 7 insertions, 44 deletions
diff --git a/azalea-protocol/src/packets/handshake/mod.rs b/azalea-protocol/src/packets/handshake/mod.rs index 17465fca..88d9939b 100644 --- a/azalea-protocol/src/packets/handshake/mod.rs +++ b/azalea-protocol/src/packets/handshake/mod.rs @@ -1,48 +1,11 @@ pub mod client_intention_packet; -use async_trait::async_trait; +use packet_macros::declare_state_packets; -use crate::connect::PacketFlow; - -use super::ProtocolPacket; - -#[derive(Clone, Debug)] -pub enum HandshakePacket -where - Self: Sized, -{ - ClientIntentionPacket(client_intention_packet::ClientIntentionPacket), -} - -#[async_trait] -impl ProtocolPacket for HandshakePacket { - fn id(&self) -> u32 { - match self { - HandshakePacket::ClientIntentionPacket(_packet) => 0x00, - } - } - - fn write(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> { - match self { - HandshakePacket::ClientIntentionPacket(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<HandshakePacket, String> - where - Self: Sized, - { - match flow { - PacketFlow::ServerToClient => Err("HandshakePacket::read not implemented".to_string()), - PacketFlow::ClientToServer => match id { - 0x00 => Ok(client_intention_packet::ClientIntentionPacket::read(buf).await?), - _ => Err(format!("Unknown ClientToServer status packet id: {}", id)), - }, - } +declare_state_packets!( + HandshakePacket, + Serverbound => {}, + Clientbound => { + 0x00: client_intention_packet::ClientIntentionPacket, } -} +); |
