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/status/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/status/mod.rs')
| -rw-r--r-- | azalea-protocol/src/packets/status/mod.rs | 71 |
1 files changed, 10 insertions, 61 deletions
diff --git a/azalea-protocol/src/packets/status/mod.rs b/azalea-protocol/src/packets/status/mod.rs index 31fedfb9..56aa577e 100644 --- a/azalea-protocol/src/packets/status/mod.rs +++ b/azalea-protocol/src/packets/status/mod.rs @@ -1,65 +1,14 @@ pub mod clientbound_status_response_packet; pub mod serverbound_status_request_packet; -use async_trait::async_trait; - -use crate::connect::PacketFlow; - -use super::ProtocolPacket; - -#[derive(Clone, Debug)] -pub enum StatusPacket -where - Self: Sized, -{ - ServerboundStatusRequestPacket( - serverbound_status_request_packet::ServerboundStatusRequestPacket, - ), - ClientboundStatusResponsePacket( - Box<clientbound_status_response_packet::ClientboundStatusResponsePacket>, - ), -} - -#[async_trait] -impl ProtocolPacket for StatusPacket { - fn id(&self) -> u32 { - match self { - StatusPacket::ServerboundStatusRequestPacket(_packet) => 0x00, - StatusPacket::ClientboundStatusResponsePacket(_packet) => 0x00, - } - } - - fn write(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> { - match self { - StatusPacket::ServerboundStatusRequestPacket(packet) => packet.write(buf), - StatusPacket::ClientboundStatusResponsePacket(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<StatusPacket, String> - where - Self: Sized, - { - match flow { - PacketFlow::ServerToClient => match id { - 0x00 => Ok( - clientbound_status_response_packet::ClientboundStatusResponsePacket::read(buf) - .await?, - ), - _ => Err(format!("Unknown ServerToClient status packet id: {}", id)), - }, - PacketFlow::ClientToServer => match id { - 0x00 => Ok( - serverbound_status_request_packet::ServerboundStatusRequestPacket::read(buf) - .await?, - ), - _ => Err(format!("Unknown ClientToServer status packet id: {}", id)), - }, - } +use packet_macros::declare_state_packets; + +declare_state_packets!( + StatusPacket, + Serverbound => { + 0x00: serverbound_status_request_packet::ServerboundStatusRequestPacket, + }, + Clientbound => { + 0x00: clientbound_status_response_packet::ClientboundStatusResponsePacket, } -} +); |
