mirror of
https://github.com/mat-1/azalea.git
synced 2024-09-19 14:42:32 +00:00
reading packets works
This commit is contained in:
parent
f6a3f088ac
commit
f9f7e3498e
6 changed files with 15 additions and 14 deletions
|
@ -36,7 +36,7 @@ impl Connection {
|
|||
|
||||
Ok(Connection {
|
||||
state: ConnectionProtocol::Handshake,
|
||||
flow: PacketFlow::ClientToServer,
|
||||
flow: PacketFlow::ServerToClient,
|
||||
stream,
|
||||
})
|
||||
}
|
||||
|
@ -61,12 +61,15 @@ impl Connection {
|
|||
|
||||
// if we recognize the packet id, parse it
|
||||
|
||||
// TODO
|
||||
let packet = Packet::read(
|
||||
packet_id.try_into().unwrap(),
|
||||
&self.state,
|
||||
&self.flow,
|
||||
&mut buf,
|
||||
)
|
||||
.await?;
|
||||
|
||||
// otherwise, read the rest of the packet and throw it away
|
||||
let mut packet_data = Vec::with_capacity((packet_size - packet_id_size as i32) as usize);
|
||||
buf.read_buf(&mut packet_data).await.unwrap();
|
||||
println!("packet {:?}", packet_data);
|
||||
println!("packet: {:?}", packet);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -5,8 +5,6 @@ use std::io::{Cursor, Write};
|
|||
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
|
||||
use tokio::io::{AsyncRead, AsyncReadExt, BufReader};
|
||||
|
||||
// const MAX_VARINT_SIZE: u32 = 5;
|
||||
// const MAX_VARLONG_SIZE: u32 = 10;
|
||||
// const DEFAULT_NBT_QUOTA: u32 = 2097152;
|
||||
const MAX_STRING_LENGTH: u16 = 32767;
|
||||
// const MAX_COMPONENT_STRING_LENGTH: u32 = 262144;
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
|||
packets::{ConnectionProtocol, Packet, PacketTrait},
|
||||
};
|
||||
|
||||
#[derive(Hash, Clone)]
|
||||
#[derive(Hash, Clone, Debug)]
|
||||
pub struct ClientIntentionPacket {
|
||||
pub protocol_version: u32,
|
||||
pub hostname: String,
|
||||
|
|
|
@ -16,7 +16,7 @@ pub enum ConnectionProtocol {
|
|||
Login = 2,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Packet {
|
||||
// game
|
||||
|
||||
|
@ -55,8 +55,8 @@ impl Packet {
|
|||
/// Read a packet by its id, ConnectionProtocol, and flow
|
||||
pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
|
||||
id: u32,
|
||||
protocol: ConnectionProtocol,
|
||||
flow: PacketFlow,
|
||||
protocol: &ConnectionProtocol,
|
||||
flow: &PacketFlow,
|
||||
buf: &mut BufReader<T>,
|
||||
) -> Result<Packet, String> {
|
||||
match protocol {
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
|||
packets::{Packet, PacketTrait},
|
||||
};
|
||||
|
||||
#[derive(Hash, Clone)]
|
||||
#[derive(Hash, Clone, Debug)]
|
||||
pub struct ClientboundStatusResponsePacket {
|
||||
status: String,
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
|||
packets::{Packet, PacketTrait},
|
||||
};
|
||||
|
||||
#[derive(Hash, Clone)]
|
||||
#[derive(Hash, Clone, Debug)]
|
||||
pub struct ServerboundStatusRequestPacket {}
|
||||
|
||||
#[async_trait]
|
||||
|
|
Loading…
Reference in a new issue