use basalt_derive::packet;
use basalt_types::Decode as _;
use crate::error::{Error, Result};
#[derive(Debug, Clone, Default, PartialEq)]
#[packet(id = 0x01)]
pub struct ServerboundStatusPing {
pub time: i64,
}
#[derive(Debug, Clone, Default, PartialEq)]
#[packet(id = 0x00)]
pub struct ServerboundStatusPingStart;
#[derive(Debug, Clone, Default, PartialEq)]
#[packet(id = 0x01)]
pub struct ClientboundStatusPing {
pub time: i64,
}
#[derive(Debug, Clone, Default, PartialEq)]
#[packet(id = 0x00)]
pub struct ClientboundStatusServerInfo {
pub response: String,
}
#[derive(Debug, Clone, PartialEq)]
pub enum ServerboundStatusPacket {
Ping(ServerboundStatusPing),
PingStart(ServerboundStatusPingStart),
}
impl ServerboundStatusPacket {
pub fn decode_by_id(id: i32, buf: &mut &[u8]) -> Result<Self> {
match id {
ServerboundStatusPing::PACKET_ID => Ok(Self::Ping(ServerboundStatusPing::decode(buf)?)),
ServerboundStatusPingStart::PACKET_ID => {
Ok(Self::PingStart(ServerboundStatusPingStart::decode(buf)?))
}
_ => Err(Error::UnknownPacket {
id,
state: "status",
}),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum ClientboundStatusPacket {
Ping(ClientboundStatusPing),
ServerInfo(ClientboundStatusServerInfo),
}
impl ClientboundStatusPacket {
pub fn decode_by_id(id: i32, buf: &mut &[u8]) -> Result<Self> {
match id {
ClientboundStatusPing::PACKET_ID => Ok(Self::Ping(ClientboundStatusPing::decode(buf)?)),
ClientboundStatusServerInfo::PACKET_ID => {
Ok(Self::ServerInfo(ClientboundStatusServerInfo::decode(buf)?))
}
_ => Err(Error::UnknownPacket {
id,
state: "status",
}),
}
}
}