aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets/status
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/status
parent9633874d23f3baa8e5d5c33f3fd51ae6aa880a88 (diff)
downloadazalea-drasl-cbdab27cb555e38b39fe0f600ff945090ec10dcb.tar.xz
add declare_state_packets to the other states
Diffstat (limited to 'azalea-protocol/src/packets/status')
-rw-r--r--azalea-protocol/src/packets/status/clientbound_status_response_packet.rs2
-rw-r--r--azalea-protocol/src/packets/status/mod.rs71
2 files changed, 11 insertions, 62 deletions
diff --git a/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs b/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs
index 58f5b701..884cf408 100644
--- a/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs
+++ b/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs
@@ -36,7 +36,7 @@ pub struct ClientboundStatusResponsePacket {
impl ClientboundStatusResponsePacket {
pub fn get(self) -> StatusPacket {
- StatusPacket::ClientboundStatusResponsePacket(Box::new(self))
+ StatusPacket::ClientboundStatusResponsePacket(self)
}
pub fn write(&self, _buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
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,
}
-}
+);