aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets/status
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-protocol/src/packets/status')
-rwxr-xr-x[-rw-r--r--]azalea-protocol/src/packets/status/clientbound_status_response_packet.rs6
-rwxr-xr-x[-rw-r--r--]azalea-protocol/src/packets/status/mod.rs71
-rwxr-xr-x[-rw-r--r--]azalea-protocol/src/packets/status/serverbound_status_request_packet.rs21
3 files changed, 16 insertions, 82 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 38270ad1..884cf408 100644..100755
--- a/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs
+++ b/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs
@@ -36,10 +36,12 @@ 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>) {}
+ pub fn write(&self, _buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ Ok(())
+ }
pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
buf: &mut T,
diff --git a/azalea-protocol/src/packets/status/mod.rs b/azalea-protocol/src/packets/status/mod.rs
index 6383bae8..56aa577e 100644..100755
--- 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>) {
- 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,
}
-}
+);
diff --git a/azalea-protocol/src/packets/status/serverbound_status_request_packet.rs b/azalea-protocol/src/packets/status/serverbound_status_request_packet.rs
index 3a25ac42..e77687ec 100644..100755
--- a/azalea-protocol/src/packets/status/serverbound_status_request_packet.rs
+++ b/azalea-protocol/src/packets/status/serverbound_status_request_packet.rs
@@ -1,22 +1,5 @@
+use packet_macros::StatusPacket;
use std::hash::Hash;
-use super::StatusPacket;
-
-#[derive(Hash, Clone, Debug)]
+#[derive(Clone, Debug, StatusPacket)]
pub struct ServerboundStatusRequestPacket {}
-
-impl ServerboundStatusRequestPacket {
- pub fn get(self) -> StatusPacket {
- StatusPacket::ServerboundStatusRequestPacket(self)
- }
-
- pub fn write(&self, _buf: &mut Vec<u8>) {
- panic!("ServerboundStatusRequestPacket::write not implemented")
- }
-
- pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
- _buf: &mut T,
- ) -> Result<StatusPacket, String> {
- Err("ServerboundStatusRequestPacket::read not implemented".to_string())
- }
-}