aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-09-19 21:44:15 -0500
committermat <github@matdoes.dev>2022-09-19 21:44:15 -0500
commita87c4cf718fcf7b16fecf463333bd46310c88c87 (patch)
tree83b0f3463f269e76486b58af0a6020e12f620a14 /azalea-client/src
parent788e9e875ab1d64441673497076dde8a50a4394c (diff)
parente46577a214ae30159d14c128c45488e3772c8f84 (diff)
downloadazalea-drasl-a87c4cf718fcf7b16fecf463333bd46310c88c87.tar.xz
Merge branch 'main' of https://github.com/mat-1/azalea
Diffstat (limited to 'azalea-client/src')
-rw-r--r--azalea-client/src/client.rs39
-rw-r--r--azalea-client/src/movement.rs2
2 files changed, 22 insertions, 19 deletions
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs
index e422e89a..60bb324b 100644
--- a/azalea-client/src/client.rs
+++ b/azalea-client/src/client.rs
@@ -4,7 +4,7 @@ use azalea_block::BlockState;
use azalea_chat::component::Component;
use azalea_core::{ChunkPos, ResourceLocation, Vec3};
use azalea_protocol::{
- connect::{Connection, ConnectionError},
+ connect::{Connection, ConnectionError, ReadConnection, WriteConnection},
packets::{
game::{
clientbound_player_chat_packet::ClientboundPlayerChatPacket,
@@ -67,7 +67,8 @@ impl ChatPacket {
#[derive(Clone)]
pub struct Client {
game_profile: GameProfile,
- pub conn: Arc<tokio::sync::Mutex<Connection<ClientboundGamePacket, ServerboundGamePacket>>>,
+ pub read_conn: Arc<tokio::sync::Mutex<ReadConnection<ClientboundGamePacket>>>,
+ pub write_conn: Arc<tokio::sync::Mutex<WriteConnection<ServerboundGamePacket>>>,
pub player: Arc<Mutex<Player>>,
pub dimension: Arc<Mutex<Dimension>>,
pub physics_state: Arc<Mutex<PhysicsState>>,
@@ -185,14 +186,18 @@ impl Client {
}
};
- let conn = Arc::new(tokio::sync::Mutex::new(conn));
+ let (read_conn, write_conn) = conn.into_split();
+
+ let read_conn = Arc::new(tokio::sync::Mutex::new(read_conn));
+ let write_conn = Arc::new(tokio::sync::Mutex::new(write_conn));
let (tx, rx) = mpsc::unbounded_channel();
// we got the GameConnection, so the server is now connected :)
let client = Client {
game_profile,
- conn,
+ read_conn,
+ write_conn,
player: Arc::new(Mutex::new(Player::default())),
dimension: Arc::new(Mutex::new(Dimension::default())),
physics_state: Arc::new(Mutex::new(PhysicsState::default())),
@@ -209,9 +214,14 @@ impl Client {
Ok((client, rx))
}
+ /// Write a packet directly to the server.
+ pub async fn write_packet(&self, packet: ServerboundGamePacket) -> Result<(), std::io::Error> {
+ self.write_conn.lock().await.write(packet).await
+ }
+
async fn protocol_loop(client: Client, tx: UnboundedSender<Event>) {
loop {
- let r = client.conn.lock().await.read().await;
+ let r = client.read_conn.lock().await.read().await;
match r {
Ok(packet) => match Self::handle(&packet, &client, &tx).await {
Ok(_) => {}
@@ -323,10 +333,7 @@ impl Client {
}
client
- .conn
- .lock()
- .await
- .write(
+ .write_packet(
ServerboundCustomPayloadPacket {
identifier: ResourceLocation::new("brand").unwrap(),
// they don't have to know :)
@@ -444,12 +451,11 @@ impl Client {
(new_pos, y_rot, x_rot)
};
- let mut conn_lock = client.conn.lock().await;
- conn_lock
- .write(ServerboundAcceptTeleportationPacket { id: p.id }.get())
+ client
+ .write_packet(ServerboundAcceptTeleportationPacket { id: p.id }.get())
.await?;
- conn_lock
- .write(
+ client
+ .write_packet(
ServerboundMovePlayerPosRotPacket {
x: new_pos.x,
y: new_pos.y,
@@ -567,10 +573,7 @@ impl Client {
ClientboundGamePacket::KeepAlive(p) => {
debug!("Got keep alive packet {:?}", p);
client
- .conn
- .lock()
- .await
- .write(ServerboundKeepAlivePacket { id: p.id }.get())
+ .write_packet(ServerboundKeepAlivePacket { id: p.id }.get())
.await?;
}
ClientboundGamePacket::RemoveEntities(p) => {
diff --git a/azalea-client/src/movement.rs b/azalea-client/src/movement.rs
index ddc44c0a..0a4a05e8 100644
--- a/azalea-client/src/movement.rs
+++ b/azalea-client/src/movement.rs
@@ -121,7 +121,7 @@ impl Client {
};
if let Some(packet) = packet {
- self.conn.lock().await.write(packet).await?;
+ self.write_packet(packet).await?;
}
Ok(())