From c96ae8fce4e53ea9fad111ac7f479f2fa33ef859 Mon Sep 17 00:00:00 2001 From: mat Date: Mon, 13 Dec 2021 00:07:21 -0600 Subject: start implementing joining servers --- minecraft-protocol/src/connect.rs | 100 ++++++++++++ minecraft-protocol/src/connection.rs | 100 ------------ minecraft-protocol/src/lib.rs | 9 +- minecraft-protocol/src/mc_buf.rs | 23 +++ minecraft-protocol/src/packets/game/mod.rs | 3 +- minecraft-protocol/src/packets/handshake/mod.rs | 5 + .../src/packets/login/clientbound_hello_packet.rs | 40 +++++ minecraft-protocol/src/packets/login/mod.rs | 7 + .../src/packets/login/serverbound_hello_packet.rs | 29 ++++ minecraft-protocol/src/packets/mod.rs | 177 ++++++++++++--------- .../status/clientbound_status_response_packet.rs | 12 +- minecraft-protocol/src/packets/status/mod.rs | 78 +++++++++ .../status/serverbound_status_request_packet.rs | 14 +- 13 files changed, 412 insertions(+), 185 deletions(-) create mode 100644 minecraft-protocol/src/connect.rs delete mode 100644 minecraft-protocol/src/connection.rs create mode 100644 minecraft-protocol/src/packets/login/clientbound_hello_packet.rs create mode 100644 minecraft-protocol/src/packets/login/serverbound_hello_packet.rs (limited to 'minecraft-protocol') diff --git a/minecraft-protocol/src/connect.rs b/minecraft-protocol/src/connect.rs new file mode 100644 index 00000000..5b750802 --- /dev/null +++ b/minecraft-protocol/src/connect.rs @@ -0,0 +1,100 @@ +//! parse sending and receiving packets with a server. + +use crate::packets::ConnectionProtocol; +use crate::{mc_buf, packets::Packet, ServerIpAddress}; +use tokio::io::AsyncWriteExt; +use tokio::{ + io::{AsyncReadExt, BufReader}, + net::TcpStream, +}; + +pub enum PacketFlow { + ClientToServer, + ServerToClient, +} + +pub struct Connection { + pub state: ConnectionProtocol, + pub flow: PacketFlow, + /// The buffered writer + pub stream: TcpStream, +} + +impl Connection { + pub async fn new(address: &ServerIpAddress) -> Result { + let ip = address.ip; + let port = address.port; + + let stream = TcpStream::connect(format!("{}:{}", ip, port)) + .await + .map_err(|_| "Failed to connect to server")?; + + // enable tcp_nodelay + stream + .set_nodelay(true) + .expect("Error enabling tcp_nodelay"); + + Ok(Connection { + state: ConnectionProtocol::Handshake, + flow: PacketFlow::ServerToClient, + stream, + }) + } + + pub fn switch_state(&mut self, state: ConnectionProtocol) { + self.state = state; + } + + pub async fn read_packet(&mut self) -> Result { + // what this does: + // 1. reads the first 5 bytes, probably only some of this will be used to get the packet length + // 2. how much we should read = packet length - 5 + // 3. read the rest of the packet and add it to the cursor + // 4. figure out what packet this is and parse it + + // the first thing minecraft sends us is the length as a varint, which can be up to 5 bytes long + let mut buf = BufReader::with_capacity(4 * 1024 * 1024, &mut self.stream); + + let (_packet_size, _packet_size_varint_size) = mc_buf::read_varint(&mut buf).await?; + + // then, minecraft tells us the packet id as a varint + let (packet_id, _packet_id_size) = mc_buf::read_varint(&mut buf).await?; + + // if we recognize the packet id, parse it + + let packet = Packet::read( + packet_id.try_into().unwrap(), + &self.state, + &self.flow, + &mut buf, + ) + .await?; + + Ok(packet) + } + + /// Write a packet to the server + pub async fn send_packet(&mut self, packet: Packet) { + // TODO: implement compression + + // packet structure: + // length (varint) + id (varint) + data + + // write the packet id + let mut id_and_data_buf = vec![]; + mc_buf::write_varint(&mut id_and_data_buf, packet.id() as i32); + packet.write(&mut id_and_data_buf); + + // write the packet data + + // make a new buffer that has the length at the beginning + // and id+data at the end + let mut complete_buf: Vec = Vec::new(); + mc_buf::write_varint(&mut complete_buf, id_and_data_buf.len() as i32); + complete_buf.append(&mut id_and_data_buf); + + // finally, write and flush to the stream + self.stream.write_all(&complete_buf).await.unwrap(); + self.stream.flush().await.unwrap(); + } +} diff --git a/minecraft-protocol/src/connection.rs b/minecraft-protocol/src/connection.rs deleted file mode 100644 index 5b750802..00000000 --- a/minecraft-protocol/src/connection.rs +++ /dev/null @@ -1,100 +0,0 @@ -//! parse sending and receiving packets with a server. - -use crate::packets::ConnectionProtocol; -use crate::{mc_buf, packets::Packet, ServerIpAddress}; -use tokio::io::AsyncWriteExt; -use tokio::{ - io::{AsyncReadExt, BufReader}, - net::TcpStream, -}; - -pub enum PacketFlow { - ClientToServer, - ServerToClient, -} - -pub struct Connection { - pub state: ConnectionProtocol, - pub flow: PacketFlow, - /// The buffered writer - pub stream: TcpStream, -} - -impl Connection { - pub async fn new(address: &ServerIpAddress) -> Result { - let ip = address.ip; - let port = address.port; - - let stream = TcpStream::connect(format!("{}:{}", ip, port)) - .await - .map_err(|_| "Failed to connect to server")?; - - // enable tcp_nodelay - stream - .set_nodelay(true) - .expect("Error enabling tcp_nodelay"); - - Ok(Connection { - state: ConnectionProtocol::Handshake, - flow: PacketFlow::ServerToClient, - stream, - }) - } - - pub fn switch_state(&mut self, state: ConnectionProtocol) { - self.state = state; - } - - pub async fn read_packet(&mut self) -> Result { - // what this does: - // 1. reads the first 5 bytes, probably only some of this will be used to get the packet length - // 2. how much we should read = packet length - 5 - // 3. read the rest of the packet and add it to the cursor - // 4. figure out what packet this is and parse it - - // the first thing minecraft sends us is the length as a varint, which can be up to 5 bytes long - let mut buf = BufReader::with_capacity(4 * 1024 * 1024, &mut self.stream); - - let (_packet_size, _packet_size_varint_size) = mc_buf::read_varint(&mut buf).await?; - - // then, minecraft tells us the packet id as a varint - let (packet_id, _packet_id_size) = mc_buf::read_varint(&mut buf).await?; - - // if we recognize the packet id, parse it - - let packet = Packet::read( - packet_id.try_into().unwrap(), - &self.state, - &self.flow, - &mut buf, - ) - .await?; - - Ok(packet) - } - - /// Write a packet to the server - pub async fn send_packet(&mut self, packet: Packet) { - // TODO: implement compression - - // packet structure: - // length (varint) + id (varint) + data - - // write the packet id - let mut id_and_data_buf = vec![]; - mc_buf::write_varint(&mut id_and_data_buf, packet.id() as i32); - packet.write(&mut id_and_data_buf); - - // write the packet data - - // make a new buffer that has the length at the beginning - // and id+data at the end - let mut complete_buf: Vec = Vec::new(); - mc_buf::write_varint(&mut complete_buf, id_and_data_buf.len() as i32); - complete_buf.append(&mut id_and_data_buf); - - // finally, write and flush to the stream - self.stream.write_all(&complete_buf).await.unwrap(); - self.stream.flush().await.unwrap(); - } -} diff --git a/minecraft-protocol/src/lib.rs b/minecraft-protocol/src/lib.rs index 5d6c8330..31b50164 100644 --- a/minecraft-protocol/src/lib.rs +++ b/minecraft-protocol/src/lib.rs @@ -3,7 +3,7 @@ use std::net::IpAddr; use std::str::FromStr; -pub mod connection; +pub mod connect; pub mod mc_buf; pub mod packets; pub mod resolver; @@ -20,9 +20,12 @@ pub struct ServerIpAddress { pub port: u16, } -impl ServerAddress { +// impl try_from for ServerAddress +impl<'a> TryFrom<&'a str> for ServerAddress { + type Error = String; + /// Convert a Minecraft server address (host:port, the port is optional) to a ServerAddress - pub fn parse(string: &str) -> Result { + fn try_from(string: &str) -> Result { if string.is_empty() { return Err("Empty string".to_string()); } diff --git a/minecraft-protocol/src/mc_buf.rs b/minecraft-protocol/src/mc_buf.rs index 6c812058..3490a66f 100644 --- a/minecraft-protocol/src/mc_buf.rs +++ b/minecraft-protocol/src/mc_buf.rs @@ -23,6 +23,17 @@ pub fn write_byte(buf: &mut Vec, n: u8) { WriteBytesExt::write_u8(buf, n).unwrap(); } +pub async fn read_bytes( + buf: &mut BufReader, + n: usize, +) -> Result, String> { + let mut bytes = vec![0; n]; + match AsyncReadExt::read_exact(buf, &mut bytes).await { + Ok(_) => Ok(bytes), + Err(_) => Err("Error reading bytes".to_string()), + } +} + pub fn write_bytes(buf: &mut Vec, bytes: &[u8]) { buf.extend_from_slice(bytes); } @@ -159,3 +170,15 @@ pub fn write_utf(buf: &mut Vec, string: &str) { pub fn write_short(buf: &mut Vec, n: u16) { WriteBytesExt::write_u16::(buf, n).unwrap(); } + +pub async fn read_byte_array( + buf: &mut BufReader, +) -> Result, String> { + let length = read_varint(buf).await?.0 as usize; + Ok(read_bytes(buf, length).await?) +} + +pub fn write_byte_array(buf: &mut Vec, bytes: &[u8]) { + write_varint(buf, bytes.len() as i32); + write_bytes(buf, bytes); +} diff --git a/minecraft-protocol/src/packets/game/mod.rs b/minecraft-protocol/src/packets/game/mod.rs index 8b137891..08444697 100644 --- a/minecraft-protocol/src/packets/game/mod.rs +++ b/minecraft-protocol/src/packets/game/mod.rs @@ -1 +1,2 @@ - +#[derive(Clone, Debug)] +pub enum GamePacket {} diff --git a/minecraft-protocol/src/packets/handshake/mod.rs b/minecraft-protocol/src/packets/handshake/mod.rs index 667b00f2..d2716299 100644 --- a/minecraft-protocol/src/packets/handshake/mod.rs +++ b/minecraft-protocol/src/packets/handshake/mod.rs @@ -1 +1,6 @@ pub mod client_intention_packet; + +#[derive(Clone, Debug)] +pub enum HandshakePacket { + ClientIntentionPacket(client_intention_packet::ClientIntentionPacket), +} diff --git a/minecraft-protocol/src/packets/login/clientbound_hello_packet.rs b/minecraft-protocol/src/packets/login/clientbound_hello_packet.rs new file mode 100644 index 00000000..878ca456 --- /dev/null +++ b/minecraft-protocol/src/packets/login/clientbound_hello_packet.rs @@ -0,0 +1,40 @@ +use async_trait::async_trait; +use std::hash::Hash; +use tokio::io::BufReader; + +use crate::{ + mc_buf, + packets::{Packet, PacketTrait}, +}; + +#[derive(Hash, Clone, Debug)] +pub struct ClientboundHelloPacket { + pub server_id: String, + pub public_key: Vec, + pub nonce: Vec, +} + +#[async_trait] +impl PacketTrait for ClientboundHelloPacket { + fn get(self) -> Packet { + Packet::ClientboundHelloPacket(self) + } + fn write(&self, _buf: &mut Vec) { + panic!("ClientboundHelloPacket::write not implemented") + } + + async fn read( + buf: &mut BufReader, + ) -> Result { + let server_id = mc_buf::read_utf_with_len(buf, 20).await?; + let public_key = mc_buf::read_byte_array(buf).await?; + let nonce = mc_buf::read_byte_array(buf).await?; + + Ok(ClientboundHelloPacket { + server_id, + public_key, + nonce, + } + .get()) + } +} diff --git a/minecraft-protocol/src/packets/login/mod.rs b/minecraft-protocol/src/packets/login/mod.rs index 8b137891..47193f92 100644 --- a/minecraft-protocol/src/packets/login/mod.rs +++ b/minecraft-protocol/src/packets/login/mod.rs @@ -1 +1,8 @@ +pub mod clientbound_hello_packet; +pub mod serverbound_hello_packet; +#[derive(Clone, Debug)] +pub enum LoginPacket { + ServerboundHelloPacket(serverbound_hello_packet::ServerboundHelloPacket), + ClientboundHelloPacket(clientbound_hello_packet::ClientboundHelloPacket), +} diff --git a/minecraft-protocol/src/packets/login/serverbound_hello_packet.rs b/minecraft-protocol/src/packets/login/serverbound_hello_packet.rs new file mode 100644 index 00000000..cadf9f7b --- /dev/null +++ b/minecraft-protocol/src/packets/login/serverbound_hello_packet.rs @@ -0,0 +1,29 @@ +use async_trait::async_trait; +use std::hash::Hash; +use tokio::io::BufReader; + +use crate::{ + mc_buf, + packets::{Packet, PacketTrait}, +}; + +#[derive(Hash, Clone, Debug)] +pub struct ServerboundHelloPacket { + pub username: String, +} + +#[async_trait] +impl PacketTrait for ServerboundHelloPacket { + fn get(self) -> Packet { + Packet::ServerboundHelloPacket(self) + } + fn write(&self, buf: &mut Vec) { + mc_buf::write_utf(buf, &self.username); + } + + async fn read( + _buf: &mut BufReader, + ) -> Result { + Err("ServerboundHelloPacket::read not implemented".to_string()) + } +} diff --git a/minecraft-protocol/src/packets/mod.rs b/minecraft-protocol/src/packets/mod.rs index bacd0c27..46caf02b 100644 --- a/minecraft-protocol/src/packets/mod.rs +++ b/minecraft-protocol/src/packets/mod.rs @@ -6,7 +6,9 @@ pub mod status; use async_trait::async_trait; use tokio::io::{AsyncRead, BufReader}; -use crate::connection::PacketFlow; +use crate::connect::PacketFlow; + +pub const PROTOCOL_VERSION: u32 = 757; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum ConnectionProtocol { @@ -18,90 +20,123 @@ pub enum ConnectionProtocol { #[derive(Clone, Debug)] pub enum Packet { - // game - - // handshake - ClientIntentionPacket(handshake::client_intention_packet::ClientIntentionPacket), - - // login - - // status - ServerboundStatusRequestPacket( - status::serverbound_status_request_packet::ServerboundStatusRequestPacket, - ), - ClientboundStatusResponsePacket( - status::clientbound_status_response_packet::ClientboundStatusResponsePacket, - ), + Game(game::GamePacket), + Handshake(handshake::HandshakePacket), + Login(login::LoginPacket), + Status(status::StatusPacket), } -// TODO: do all this with macros so it's less repetitive -impl Packet { - fn get_inner_packet(&self) -> &dyn PacketTrait { - match self { - Packet::ClientIntentionPacket(packet) => packet, - Packet::ServerboundStatusRequestPacket(packet) => packet, - Packet::ClientboundStatusResponsePacket(packet) => packet, - } - } - - pub fn id(&self) -> u32 { - match self { - Packet::ClientIntentionPacket(_packet) => 0x00, - Packet::ServerboundStatusRequestPacket(_packet) => 0x00, - Packet::ClientboundStatusResponsePacket(_packet) => 0x00, - } - } +#[async_trait] +pub trait ProtocolPacket { + fn get_inner(&self) -> &P; + + fn id(&self) -> u32; /// Read a packet by its id, ConnectionProtocol, and flow - pub async fn read( + async fn read< + T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send, + P: ProtocolPacket, + >( id: u32, - protocol: &ConnectionProtocol, flow: &PacketFlow, buf: &mut BufReader, - ) -> Result { - match protocol { - ConnectionProtocol::Handshake => match id { - 0x00 => Ok( - handshake::client_intention_packet::ClientIntentionPacket::read(buf).await?, - ), - _ => Err(format!("Unknown packet id: {}", id)), - }, - ConnectionProtocol::Game => Err("Game protocol not implemented yet".to_string()), - ConnectionProtocol::Status => match flow { - PacketFlow::ServerToClient => match id { - 0x00 => Ok( - status::clientbound_status_response_packet::ClientboundStatusResponsePacket - ::read(buf) - .await?, - ), - _ => Err(format!("Unknown packet id: {}", id)), - }, - PacketFlow::ClientToServer => match id { - 0x00 => Ok( - status::serverbound_status_request_packet::ServerboundStatusRequestPacket - ::read(buf) - .await?, - ), - _ => Err(format!("Unknown packet id: {}", id)), - }, - }, - ConnectionProtocol::Login => Err("Login protocol not implemented yet".to_string()), - } - } - - pub fn write(&self, buf: &mut Vec) { - self.get_inner_packet().write(buf); - } + ) -> Result + where + Self: Sized; + + fn write(&self, buf: &mut Vec); } +// impl Packet { +// fn get_inner_packet(&self) -> &dyn PacketTrait { +// match self { +// Packet::ClientIntentionPacket(packet) => packet, +// Packet::ServerboundStatusRequestPacket(packet) => packet, +// Packet::ClientboundStatusResponsePacket(packet) => packet, +// Packet::ServerboundHelloPacket(packet) => packet, +// Packet::ClientboundHelloPacket(packet) => packet, +// } +// } + +// pub fn id(&self) -> u32 { +// match self { +// Packet::ClientIntentionPacket(_packet) => 0x00, +// Packet::ServerboundStatusRequestPacket(_packet) => 0x00, +// Packet::ClientboundStatusResponsePacket(_packet) => 0x00, +// Packet::ServerboundHelloPacket(_packet) => 0x00, +// Packet::ClientboundHelloPacket(_packet) => 0x01, +// } +// } + +// /// Read a packet by its id, ConnectionProtocol, and flow +// pub async fn read( +// id: u32, +// protocol: &ConnectionProtocol, +// flow: &PacketFlow, +// buf: &mut BufReader, +// ) -> Result { +// match protocol { +// ConnectionProtocol::Handshake => match flow { +// PacketFlow::ClientToServer => match id { +// 0x00 => Ok( +// handshake::client_intention_packet::ClientIntentionPacket::read(buf).await?, +// ), +// _ => Err(format!("Unknown ClientToServer handshake packet id: {}", id)), +// } +// PacketFlow::ServerToClient => Err("ServerToClient handshake packets not implemented".to_string()), +// }, + +// ConnectionProtocol::Game => Err("Game protocol not implemented yet".to_string()), + +// ConnectionProtocol::Status => match flow { +// PacketFlow::ServerToClient => match id { +// 0x00 => Ok( +// status::clientbound_status_response_packet::ClientboundStatusResponsePacket +// ::read(buf) +// .await?, +// ), +// _ => Err(format!("Unknown ServerToClient status packet id: {}", id)), +// }, +// PacketFlow::ClientToServer => match id { +// 0x00 => Ok( +// status::serverbound_status_request_packet::ServerboundStatusRequestPacket +// ::read(buf) +// .await?, +// ), +// _ => Err(format!("Unknown ClientToServer status packet id: {}", id)), +// }, +// }, + +// ConnectionProtocol::Login => match flow { +// PacketFlow::ServerToClient => match id { +// 0x01 => Ok( +// login::clientbound_hello_packet::ClientboundHelloPacket::read(buf).await?, +// ), +// _ => Err(format!("Unknown ServerToClient login packet id: {}", id)), +// }, +// PacketFlow::ClientToServer => match id { +// 0x00 => Ok( +// login::serverbound_hello_packet::ServerboundHelloPacket::read(buf).await?, +// ), +// _ => Err(format!("Unknown ClientToServer login packet id: {}", id)), +// }, +// }, +// } +// } + +// pub fn write(&self, buf: &mut Vec) { +// self.get_inner_packet().write(buf); +// } +// } + #[async_trait] pub trait PacketTrait { /// Return a version of the packet that you can actually use for stuff - fn get(self) -> Packet; + fn get(self) -> P; fn write(&self, buf: &mut Vec); - async fn read( + async fn read( buf: &mut BufReader, - ) -> Result + ) -> Result where Self: Sized; } diff --git a/minecraft-protocol/src/packets/status/clientbound_status_response_packet.rs b/minecraft-protocol/src/packets/status/clientbound_status_response_packet.rs index 99bef586..30b1403c 100644 --- a/minecraft-protocol/src/packets/status/clientbound_status_response_packet.rs +++ b/minecraft-protocol/src/packets/status/clientbound_status_response_packet.rs @@ -9,9 +9,11 @@ use crate::{ packets::{Packet, PacketTrait}, }; +use super::StatusPacket; + #[derive(Clone, Debug, Deserialize)] pub struct Version { - pub name: String, + pub name: Component, pub protocol: u32, } @@ -31,14 +33,16 @@ pub struct Players { // the entire packet is just json, which is why it has deserialize #[derive(Clone, Debug, Deserialize)] pub struct ClientboundStatusResponsePacket { - pub version: Version, pub description: Component, + pub favicon: Option, + pub players: Players, + pub version: Version, } #[async_trait] impl PacketTrait for ClientboundStatusResponsePacket { - fn get(self) -> Packet { - Packet::ClientboundStatusResponsePacket(self) + fn get(self) -> StatusPacket { + StatusPacket::ClientboundStatusResponsePacket(self) } fn write(&self, _buf: &mut Vec) {} diff --git a/minecraft-protocol/src/packets/status/mod.rs b/minecraft-protocol/src/packets/status/mod.rs index efc03631..7e327ca7 100644 --- a/minecraft-protocol/src/packets/status/mod.rs +++ b/minecraft-protocol/src/packets/status/mod.rs @@ -1,2 +1,80 @@ pub mod clientbound_status_response_packet; pub mod serverbound_status_request_packet; + +use async_trait::async_trait; +use tokio::io::BufReader; + +use crate::connect::PacketFlow; + +use super::{ConnectionProtocol, PacketTrait, ProtocolPacket}; + +#[derive(Clone, Debug)] +pub enum StatusPacket { + ServerboundStatusRequestPacket( + serverbound_status_request_packet::ServerboundStatusRequestPacket, + ), + ClientboundStatusResponsePacket( + clientbound_status_response_packet::ClientboundStatusResponsePacket, + ), +} + +// #[async_trait] +// impl ProtocolPacket for StatusPacket { +impl StatusPacket { + fn get_inner(self) -> impl PacketTrait { + match self { + StatusPacket::ServerboundStatusRequestPacket(packet) => packet, + StatusPacket::ClientboundStatusResponsePacket(packet) => packet, + } + } + // fn get_inner(&self) -> StatusPacket { + // match self { + // StatusPacket::ServerboundStatusRequestPacket(packet) => packet, + // StatusPacket::ClientboundStatusResponsePacket(packet) => packet, + // } + // } + + fn id(&self) -> u32 { + match self { + StatusPacket::ServerboundStatusRequestPacket(_packet) => 0x00, + StatusPacket::ClientboundStatusResponsePacket(_packet) => 0x00, + } + } + + fn write(&self, buf: &mut Vec) { + 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, + P: ProtocolPacket, + >( + id: u32, + flow: &PacketFlow, + buf: &mut BufReader, + ) -> Result + 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)), + }, + } + } +} diff --git a/minecraft-protocol/src/packets/status/serverbound_status_request_packet.rs b/minecraft-protocol/src/packets/status/serverbound_status_request_packet.rs index 56799677..066131cc 100644 --- a/minecraft-protocol/src/packets/status/serverbound_status_request_packet.rs +++ b/minecraft-protocol/src/packets/status/serverbound_status_request_packet.rs @@ -2,19 +2,21 @@ use async_trait::async_trait; use std::hash::Hash; use tokio::io::BufReader; -use crate::{ - packets::{Packet, PacketTrait}, -}; +use crate::packets::{Packet, PacketTrait, ProtocolPacket}; + +use super::StatusPacket; #[derive(Hash, Clone, Debug)] pub struct ServerboundStatusRequestPacket {} #[async_trait] impl PacketTrait for ServerboundStatusRequestPacket { - fn get(self) -> Packet { - Packet::ServerboundStatusRequestPacket(self) + fn get(self) -> StatusPacket { + StatusPacket::ServerboundStatusRequestPacket(self) + } + fn write(&self, _buf: &mut Vec) { + panic!("ServerboundStatusRequestPacket::write not implemented") } - fn write(&self, _buf: &mut Vec) {} async fn read( _buf: &mut BufReader, -- cgit v1.2.3