aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/connect.rs
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2021-12-16 23:33:06 -0600
committermat <github@matdoes.dev>2021-12-16 23:33:06 -0600
commitc4eecaf13a4f8f0a81dc278078727df23caa8411 (patch)
tree5082f54d1a9242281d80c250e587235a3ac3755b /azalea-protocol/src/connect.rs
parent1dc56b6f519f386b6e0b5eac47a84576cedbbb33 (diff)
downloadazalea-drasl-c4eecaf13a4f8f0a81dc278078727df23caa8411.tar.xz
try to implement compression
Diffstat (limited to 'azalea-protocol/src/connect.rs')
-rw-r--r--azalea-protocol/src/connect.rs28
1 files changed, 24 insertions, 4 deletions
diff --git a/azalea-protocol/src/connect.rs b/azalea-protocol/src/connect.rs
index f6dd9fe7..cc06eec3 100644
--- a/azalea-protocol/src/connect.rs
+++ b/azalea-protocol/src/connect.rs
@@ -24,6 +24,7 @@ pub struct GameConnection {
pub flow: PacketFlow,
/// The buffered writer
pub stream: TcpStream,
+ pub compression_threshold: Option<u32>,
}
pub struct StatusConnection {
@@ -36,6 +37,7 @@ pub struct LoginConnection {
pub flow: PacketFlow,
/// The buffered writer
pub stream: TcpStream,
+ pub compression_threshold: Option<u32>,
}
impl HandshakeConnection {
@@ -62,6 +64,7 @@ impl HandshakeConnection {
LoginConnection {
flow: self.flow,
stream: self.stream,
+ compression_threshold: None,
}
}
@@ -73,7 +76,7 @@ impl HandshakeConnection {
}
pub async fn read(&mut self) -> Result<HandshakePacket, String> {
- read_packet::<HandshakePacket>(&self.flow, &mut self.stream).await
+ read_packet::<HandshakePacket>(&self.flow, &mut self.stream, None).await
}
/// Write a packet to the server
@@ -84,7 +87,7 @@ impl HandshakeConnection {
impl GameConnection {
pub async fn read(&mut self) -> Result<GamePacket, String> {
- read_packet::<GamePacket>(&self.flow, &mut self.stream).await
+ read_packet::<GamePacket>(&self.flow, &mut self.stream, self.compression_threshold).await
}
/// Write a packet to the server
@@ -95,7 +98,7 @@ impl GameConnection {
impl StatusConnection {
pub async fn read(&mut self) -> Result<StatusPacket, String> {
- read_packet::<StatusPacket>(&self.flow, &mut self.stream).await
+ read_packet::<StatusPacket>(&self.flow, &mut self.stream, None).await
}
/// Write a packet to the server
@@ -106,11 +109,28 @@ impl StatusConnection {
impl LoginConnection {
pub async fn read(&mut self) -> Result<LoginPacket, String> {
- read_packet::<LoginPacket>(&self.flow, &mut self.stream).await
+ read_packet::<LoginPacket>(&self.flow, &mut self.stream, self.compression_threshold).await
}
/// Write a packet to the server
pub async fn write(&mut self, packet: LoginPacket) {
write_packet(packet, &mut self.stream).await;
}
+
+ pub fn set_compression_threshold(&mut self, threshold: i32) {
+ // if you pass a threshold of 0 or less, compression is disabled
+ if threshold > 0 {
+ self.compression_threshold = Some(threshold as u32);
+ } else {
+ self.compression_threshold = None;
+ }
+ }
+
+ pub fn game(self) -> GameConnection {
+ GameConnection {
+ flow: self.flow,
+ stream: self.stream,
+ compression_threshold: self.compression_threshold,
+ }
+ }
}