diff options
| author | mat <github@matdoes.dev> | 2021-12-07 20:04:35 +0000 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2021-12-07 20:04:35 +0000 |
| commit | 500754eab0bb99e6bd1769ddd999241ce26b5f91 (patch) | |
| tree | ab4f84b7a227fc3eedd3d253f866eb086f3617cf /minecraft-protocol/src/connection.rs | |
| parent | fcaca28ff1d2cb54c9139941d4075676ca46c6e8 (diff) | |
| download | azalea-drasl-500754eab0bb99e6bd1769ddd999241ce26b5f91.tar.xz | |
reading packet almost complete
Diffstat (limited to 'minecraft-protocol/src/connection.rs')
| -rw-r--r-- | minecraft-protocol/src/connection.rs | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/minecraft-protocol/src/connection.rs b/minecraft-protocol/src/connection.rs index 96514486..b4e3595c 100644 --- a/minecraft-protocol/src/connection.rs +++ b/minecraft-protocol/src/connection.rs @@ -1,9 +1,9 @@ use crate::{mc_buf, packets::Packet, ServerIpAddress}; use bytes::BytesMut; -use std::io::{Cursor, Read, Seek, SeekFrom, Write}; +use std::io::{Cursor, Read, Write}; use tokio::io::AsyncWriteExt; use tokio::{ - io::{AsyncReadExt, BufReader, BufWriter}, + io::{AsyncReadExt, BufReader, BufWriter, SeekFrom, AsyncSeek, AsyncSeekExt}, net::TcpStream, }; @@ -46,21 +46,23 @@ impl Connection { // 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(5 * 1024, &mut self.stream); - - let packet_size = mc_buf::read_varint(&mut buf).await?; - - println!("packet size from varint: {}", packet_size); - + let (packet_size, packet_size_varint_size) = mc_buf::read_varint(&mut buf).await?; + // then, minecraft tells us the packet id as a single byte let packet_id = mc_buf::read_byte(&mut buf).await?; // read the rest of the packet - let mut packet_data = Vec::with_capacity(packet_size as usize); + let mut packet_data = Vec::with_capacity( + ( + packet_size // the total size of the packet + - 1 // we just read the packet id, so we don't read that byte again + ) as usize); buf.read_buf(&mut packet_data).await.unwrap(); - println!( - "packet id {}: {}", - packet_id, - String::from_utf8(packet_data.clone()).unwrap() - ); + println!("packet {}", packet_id); + // println!( + // "packet id {}: {}", + // packet_id, + // String::from_utf8(packet_data.clone()).unwrap() + // ); Ok(()) } |
