aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/mc_buf.rs
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2021-12-16 17:51:05 -0600
committermat <github@matdoes.dev>2021-12-16 17:51:05 -0600
commit227ba5511d50af8c7c46a47e09db7f55a0ed84b7 (patch)
tree1067828ee2082e0f073a4d16b201b2888c55b6e8 /azalea-protocol/src/mc_buf.rs
parent999116ed7c5edf113e12aae150c2e23974d539dc (diff)
downloadazalea-drasl-227ba5511d50af8c7c46a47e09db7f55a0ed84b7.tar.xz
add a few more login packets
Diffstat (limited to 'azalea-protocol/src/mc_buf.rs')
-rw-r--r--azalea-protocol/src/mc_buf.rs18
1 files changed, 16 insertions, 2 deletions
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<u8> {
}
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<u8> {
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::<BigEndian>(self, n)
+ }
}
#[async_trait]
@@ -133,6 +139,7 @@ pub trait Readable {
async fn read_utf(&mut self) -> Result<String, String>;
async fn read_utf_with_len(&mut self, max_length: u32) -> Result<String, String>;
async fn read_byte(&mut self) -> Result<u8, String>;
+ async fn read_int(&mut self) -> Result<i32, String>;
}
#[async_trait]
@@ -225,6 +232,13 @@ where
Err(_) => Err("Error reading byte".to_string()),
}
}
+
+ async fn read_int(&mut self) -> Result<i32, String> {
+ match AsyncReadExt::read_i32(self).await {
+ Ok(r) => Ok(r),
+ Err(_) => Err("Error reading int".to_string()),
+ }
+ }
}
#[cfg(test)]