diff options
| author | mat <github@matdoes.dev> | 2022-07-29 02:59:40 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-07-29 02:59:40 -0500 |
| commit | 4ee4687053b7442f518823b08099c156f4da4e83 (patch) | |
| tree | 11bb56330ed172a961d0a19069a086798d0aa804 /azalea-protocol/src/connect.rs | |
| parent | aadf2de3cb751d563e743599a7fb345c08010f5a (diff) | |
| download | azalea-drasl-4ee4687053b7442f518823b08099c156f4da4e83.tar.xz | |
Split clientbound and serverbound packets
Diffstat (limited to 'azalea-protocol/src/connect.rs')
| -rwxr-xr-x | azalea-protocol/src/connect.rs | 52 |
1 files changed, 17 insertions, 35 deletions
diff --git a/azalea-protocol/src/connect.rs b/azalea-protocol/src/connect.rs index 67771d8e..bf730fc4 100755 --- a/azalea-protocol/src/connect.rs +++ b/azalea-protocol/src/connect.rs @@ -1,29 +1,21 @@ //! parse sending and receiving packets with a server. -use crate::packets::game::GamePacket; -use crate::packets::handshake::HandshakePacket; -use crate::packets::login::LoginPacket; -use crate::packets::status::StatusPacket; +use crate::packets::game::{ClientboundGamePacket, ServerboundGamePacket}; +use crate::packets::handshake::{ClientboundHandshakePacket, ServerboundHandshakePacket}; +use crate::packets::login::{ClientboundLoginPacket, ServerboundLoginPacket}; +use crate::packets::status::{ClientboundStatusPacket, ServerboundStatusPacket}; use crate::read::read_packet; use crate::write::write_packet; use crate::ServerIpAddress; use azalea_crypto::{Aes128CfbDec, Aes128CfbEnc}; use tokio::net::TcpStream; -#[derive(Debug, Clone, Copy)] -pub enum PacketFlow { - ClientToServer, - ServerToClient, -} - pub struct HandshakeConnection { - pub flow: PacketFlow, /// The buffered writer pub stream: TcpStream, } pub struct GameConnection { - pub flow: PacketFlow, /// The buffered writer pub stream: TcpStream, pub compression_threshold: Option<u32>, @@ -32,13 +24,11 @@ pub struct GameConnection { } pub struct StatusConnection { - pub flow: PacketFlow, /// The buffered writer pub stream: TcpStream, } pub struct LoginConnection { - pub flow: PacketFlow, /// The buffered writer pub stream: TcpStream, pub compression_threshold: Option<u32>, @@ -60,15 +50,11 @@ impl HandshakeConnection { .set_nodelay(true) .expect("Error enabling tcp_nodelay"); - Ok(HandshakeConnection { - flow: PacketFlow::ServerToClient, - stream, - }) + Ok(HandshakeConnection { stream }) } pub fn login(self) -> LoginConnection { LoginConnection { - flow: self.flow, stream: self.stream, compression_threshold: None, enc_cipher: None, @@ -78,25 +64,23 @@ impl HandshakeConnection { pub fn status(self) -> StatusConnection { StatusConnection { - flow: self.flow, stream: self.stream, } } - pub async fn read(&mut self) -> Result<HandshakePacket, String> { - read_packet::<HandshakePacket, _>(&self.flow, &mut self.stream, None, &mut None).await + pub async fn read(&mut self) -> Result<ClientboundHandshakePacket, String> { + read_packet::<ClientboundHandshakePacket, _>(&mut self.stream, None, &mut None).await } /// Write a packet to the server - pub async fn write(&mut self, packet: HandshakePacket) { + pub async fn write(&mut self, packet: ServerboundHandshakePacket) { 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, + pub async fn read(&mut self) -> Result<ClientboundGamePacket, String> { + read_packet::<ClientboundGamePacket, _>( &mut self.stream, self.compression_threshold, &mut self.dec_cipher, @@ -105,7 +89,7 @@ impl GameConnection { } /// Write a packet to the server - pub async fn write(&mut self, packet: GamePacket) { + pub async fn write(&mut self, packet: ServerboundGamePacket) { write_packet( packet, &mut self.stream, @@ -117,20 +101,19 @@ impl GameConnection { } impl StatusConnection { - pub async fn read(&mut self) -> Result<StatusPacket, String> { - read_packet::<StatusPacket, _>(&self.flow, &mut self.stream, None, &mut None).await + pub async fn read(&mut self) -> Result<ClientboundStatusPacket, String> { + read_packet::<ClientboundStatusPacket, _>(&mut self.stream, None, &mut None).await } /// Write a packet to the server - pub async fn write(&mut self, packet: StatusPacket) { + pub async fn write(&mut self, packet: ServerboundStatusPacket) { 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, + pub async fn read(&mut self) -> Result<ClientboundLoginPacket, String> { + read_packet::<ClientboundLoginPacket, _>( &mut self.stream, self.compression_threshold, &mut self.dec_cipher, @@ -139,7 +122,7 @@ impl LoginConnection { } /// Write a packet to the server - pub async fn write(&mut self, packet: LoginPacket) { + pub async fn write(&mut self, packet: ServerboundLoginPacket) { write_packet( packet, &mut self.stream, @@ -167,7 +150,6 @@ impl LoginConnection { pub fn game(self) -> GameConnection { GameConnection { - flow: self.flow, stream: self.stream, compression_threshold: self.compression_threshold, enc_cipher: self.enc_cipher, |
