From 227ba5511d50af8c7c46a47e09db7f55a0ed84b7 Mon Sep 17 00:00:00 2001 From: mat Date: Thu, 16 Dec 2021 17:51:05 -0600 Subject: add a few more login packets --- azalea-protocol/src/mc_buf.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'azalea-protocol/src/mc_buf.rs') diff --git a/azalea-protocol/src/mc_buf.rs b/azalea-protocol/src/mc_buf.rs index 5a1ac274..0a47f637 100644 --- a/azalea-protocol/src/mc_buf.rs +++ b/azalea-protocol/src/mc_buf.rs @@ -1,6 +1,6 @@ //! Utilities for reading and writing for the Minecraft protocol -use std::{future::Future, io::Write}; +use std::io::Write; use async_trait::async_trait; use byteorder::{BigEndian, WriteBytesExt}; @@ -35,6 +35,7 @@ pub trait Writable { fn write_utf(&mut self, string: &str) -> Result<(), std::io::Error>; fn write_short(&mut self, n: u16) -> Result<(), std::io::Error>; fn write_byte_array(&mut self, bytes: &[u8]) -> Result<(), std::io::Error>; + fn write_int(&mut self, n: i32) -> Result<(), std::io::Error>; } #[async_trait] @@ -79,7 +80,8 @@ impl Writable for Vec { } fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), std::io::Error> { - Ok(self.extend_from_slice(bytes)) + self.extend_from_slice(bytes); + Ok(()) } fn write_varint(&mut self, mut value: i32) -> Result<(), std::io::Error> { @@ -122,6 +124,10 @@ impl Writable for Vec { self.write_varint(bytes.len() as i32)?; self.write_bytes(bytes) } + + fn write_int(&mut self, n: i32) -> Result<(), std::io::Error> { + WriteBytesExt::write_i32::(self, n) + } } #[async_trait] @@ -133,6 +139,7 @@ pub trait Readable { async fn read_utf(&mut self) -> Result; async fn read_utf_with_len(&mut self, max_length: u32) -> Result; async fn read_byte(&mut self) -> Result; + async fn read_int(&mut self) -> Result; } #[async_trait] @@ -225,6 +232,13 @@ where Err(_) => Err("Error reading byte".to_string()), } } + + async fn read_int(&mut self) -> Result { + match AsyncReadExt::read_i32(self).await { + Ok(r) => Ok(r), + Err(_) => Err("Error reading int".to_string()), + } + } } #[cfg(test)] -- cgit v1.2.3