aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets/handshake/mod.rs
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-04-19 19:17:36 -0500
committermat <github@matdoes.dev>2022-04-19 19:17:36 -0500
commitcbdab27cb555e38b39fe0f600ff945090ec10dcb (patch)
tree57507ec2a3991ed647ef2f4efd8ee357bbf33d11 /azalea-protocol/src/packets/handshake/mod.rs
parent9633874d23f3baa8e5d5c33f3fd51ae6aa880a88 (diff)
downloadazalea-drasl-cbdab27cb555e38b39fe0f600ff945090ec10dcb.tar.xz
add declare_state_packets to the other states
Diffstat (limited to 'azalea-protocol/src/packets/handshake/mod.rs')
-rw-r--r--azalea-protocol/src/packets/handshake/mod.rs51
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,
}
-}
+);