aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-04-30 23:04:18 -0500
committermat <github@matdoes.dev>2022-04-30 23:04:18 -0500
commit8313952541c049615af944b87b80c686bbf62073 (patch)
treebda219f25ae448c2bd0054ce2187be63f513b02e /azalea-client/src
parent0dc6decf7f3a4ea273e0eabccd74815c528ba6bd (diff)
downloadazalea-drasl-8313952541c049615af944b87b80c686bbf62073.tar.xz
Simplify packet macro
Now every packet implements McBufWritable and McBufReadable and uses those so the code doesn't have to be duplicated.
Diffstat (limited to 'azalea-client/src')
-rwxr-xr-xazalea-client/src/connect.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/azalea-client/src/connect.rs b/azalea-client/src/connect.rs
index 7049ab81..2a5066c6 100755
--- a/azalea-client/src/connect.rs
+++ b/azalea-client/src/connect.rs
@@ -1,7 +1,9 @@
+use crate::Player;
+use azalea_core::resource_location::ResourceLocation;
use azalea_protocol::{
connect::{GameConnection, HandshakeConnection},
packets::{
- game::GamePacket,
+ game::{serverbound_custom_payload_packet::ServerboundCustomPayloadPacket, GamePacket},
handshake::client_intention_packet::ClientIntentionPacket,
login::{
serverbound_hello_packet::ServerboundHelloPacket,
@@ -15,8 +17,6 @@ use std::sync::Arc;
use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender};
use tokio::sync::Mutex;
-use crate::Player;
-
///! Connect to Minecraft servers.
/// Something that can join Minecraft servers.
@@ -148,7 +148,7 @@ impl Client {
loop {
let r = conn.lock().await.read().await;
match r {
- Ok(packet) => Self::handle(&packet, &tx, &state).await,
+ Ok(packet) => Self::handle(&packet, &tx, &state, &conn).await,
Err(e) => {
panic!("Error: {:?}", e);
}
@@ -160,12 +160,21 @@ impl Client {
packet: &GamePacket,
tx: &UnboundedSender<Event>,
state: &Arc<Mutex<ClientState>>,
+ conn: &Arc<Mutex<GameConnection>>,
) {
match packet {
GamePacket::ClientboundLoginPacket(p) => {
println!("Got login packet {:?}", p);
state.lock().await.player.entity.id = p.player_id;
+ conn.lock().await.write(
+ ServerboundCustomPayloadPacket {
+ identifier: ResourceLocation::new("brand").unwrap(),
+ // they don't have to know :)
+ data: "vanilla".into(),
+ }
+ .get(),
+ );
tx.send(Event::Login).unwrap();
}
@@ -221,6 +230,7 @@ impl Client {
GamePacket::ClientboundAddMobPacket(p) => {
println!("Got add mob packet {:?}", p);
}
+ GamePacket::ServerboundCustomPayloadPacket(_) => todo!(),
}
println!();
}