diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-04-25 03:50:17 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-25 03:50:17 +0000 |
| commit | dac943e3d79def7d2c322450790f16f027735941 (patch) | |
| tree | 3beafa3c8035c69a33b7d0f12779236bf786cf36 /azalea-protocol/src/connect.rs | |
| parent | b7641ff308aab7840d2a2253ae50f8ee496b2a97 (diff) | |
| parent | f4dd3a9293367fa8f3d839a184e8055b22595204 (diff) | |
| download | azalea-drasl-dac943e3d79def7d2c322450790f16f027735941.tar.xz | |
Merge pull request #3 from mat-1/auth
Auth
Diffstat (limited to 'azalea-protocol/src/connect.rs')
| -rwxr-xr-x | azalea-protocol/src/connect.rs | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/azalea-protocol/src/connect.rs b/azalea-protocol/src/connect.rs index 3d910d3a..e81bc368 100755 --- a/azalea-protocol/src/connect.rs +++ b/azalea-protocol/src/connect.rs @@ -7,6 +7,7 @@ use crate::packets::status::StatusPacket; use crate::read::read_packet; use crate::write::write_packet; use crate::ServerIpAddress; +use azalea_auth::encryption::Aes128Cfb; use tokio::net::TcpStream; pub enum PacketFlow { @@ -25,6 +26,7 @@ pub struct GameConnection { /// The buffered writer pub stream: TcpStream, pub compression_threshold: Option<u32>, + pub cipher: Option<Aes128Cfb>, } pub struct StatusConnection { @@ -38,6 +40,7 @@ pub struct LoginConnection { /// The buffered writer pub stream: TcpStream, pub compression_threshold: Option<u32>, + pub cipher: Option<Aes128Cfb>, } impl HandshakeConnection { @@ -65,6 +68,7 @@ impl HandshakeConnection { flow: self.flow, stream: self.stream, compression_threshold: None, + cipher: None, } } @@ -76,46 +80,69 @@ impl HandshakeConnection { } pub async fn read(&mut self) -> Result<HandshakePacket, String> { - read_packet::<HandshakePacket, _>(&self.flow, &mut self.stream, None).await + read_packet::<HandshakePacket, _>(&self.flow, &mut self.stream, None, &mut None).await } /// Write a packet to the server pub async fn write(&mut self, packet: HandshakePacket) { - write_packet(packet, &mut self.stream, None).await; + write_packet(packet, &mut self.stream, None, &mut None).await; } } impl GameConnection { pub async fn read(&mut self) -> Result<GamePacket, String> { - read_packet::<GamePacket, _>(&self.flow, &mut self.stream, self.compression_threshold).await + read_packet::<GamePacket, _>( + &self.flow, + &mut self.stream, + self.compression_threshold, + &mut self.cipher, + ) + .await } /// Write a packet to the server pub async fn write(&mut self, packet: GamePacket) { - write_packet(packet, &mut self.stream, self.compression_threshold).await; + write_packet( + packet, + &mut self.stream, + self.compression_threshold, + &mut self.cipher, + ) + .await; } } impl StatusConnection { pub async fn read(&mut self) -> Result<StatusPacket, String> { - read_packet::<StatusPacket, _>(&self.flow, &mut self.stream, None).await + read_packet::<StatusPacket, _>(&self.flow, &mut self.stream, None, &mut None).await } /// Write a packet to the server pub async fn write(&mut self, packet: StatusPacket) { - write_packet(packet, &mut self.stream, None).await; + write_packet(packet, &mut self.stream, None, &mut None).await; } } impl LoginConnection { pub async fn read(&mut self) -> Result<LoginPacket, String> { - read_packet::<LoginPacket, _>(&self.flow, &mut self.stream, self.compression_threshold) - .await + read_packet::<LoginPacket, _>( + &self.flow, + &mut self.stream, + self.compression_threshold, + &mut self.cipher, + ) + .await } /// Write a packet to the server pub async fn write(&mut self, packet: LoginPacket) { - write_packet(packet, &mut self.stream, self.compression_threshold).await; + write_packet( + packet, + &mut self.stream, + self.compression_threshold, + &mut self.cipher, + ) + .await; } pub fn set_compression_threshold(&mut self, threshold: i32) { @@ -127,11 +154,18 @@ impl LoginConnection { } } + pub fn set_encryption_key(&mut self, key: [u8; 16]) { + // minecraft has a cipher decoder and encoder, i don't think it matters though? + let cipher = azalea_auth::encryption::create_cipher(&key); + self.cipher = Some(cipher); + } + pub fn game(self) -> GameConnection { GameConnection { flow: self.flow, stream: self.stream, compression_threshold: self.compression_threshold, + cipher: self.cipher, } } } |
