aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/client.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2024-11-27 19:31:40 -0600
committerGitHub <noreply@github.com>2024-11-27 19:31:40 -0600
commit08958c2278b15ebeac8a964f392ebb792e479b61 (patch)
tree4ae3664cea38d7fd1a8f1e95ed06fac04ffe519e /azalea-client/src/client.rs
parent139d77d3c2b0922fba5e9d4fa2bd9819d78bd773 (diff)
downloadazalea-drasl-08958c2278b15ebeac8a964f392ebb792e479b61.tar.xz
Refactor azalea-protocol (#190)
* start updating to 1.21.4 * fix block codegen and stop using block data from burger * rename packet related modules and structs to be simpler * ItemSlot -> ItemStack for more consistency with mojmap * .get() -> .into_packet() * simplify declare_state_packets by removing packet ids * rename read_from and write_into to azalea_read and azalea_write * rename McBufReadable and McBufWritable to AzaleaRead and AzaleaWrite * McBuf -> AzBuf * remove most uses of into_variant * update codegen and use resourcelocation names for packets * implement #[limit(i)] attribute for AzBuf derive macro * fixes for 1.21.4 * fix examples * update some physics code and fix ChatType * remove unused imports in codegen * re-add some things to migrate.py and update +mc version numbers automatically * downgrade to 1.21.3 lol
Diffstat (limited to 'azalea-client/src/client.rs')
-rw-r--r--azalea-client/src/client.rs77
1 files changed, 36 insertions, 41 deletions
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs
index 9083a80b..5158eedf 100644
--- a/azalea-client/src/client.rs
+++ b/azalea-client/src/client.rs
@@ -17,24 +17,21 @@ use azalea_entity::{
};
use azalea_physics::PhysicsPlugin;
use azalea_protocol::{
+ common::client_information::ClientInformation,
connect::{Connection, ConnectionError, Proxy},
packets::{
- configuration::{
- serverbound_client_information_packet::ClientInformation,
- ClientboundConfigurationPacket, ServerboundConfigurationPacket,
- },
+ self,
+ config::{ClientboundConfigPacket, ServerboundConfigPacket},
game::ServerboundGamePacket,
- handshaking::{
- client_intention_packet::ClientIntentionPacket, ClientboundHandshakePacket,
+ handshake::{
+ s_intention::ServerboundIntention, ClientboundHandshakePacket,
ServerboundHandshakePacket,
},
login::{
- serverbound_hello_packet::ServerboundHelloPacket,
- serverbound_key_packet::ServerboundKeyPacket,
- serverbound_login_acknowledged_packet::ServerboundLoginAcknowledgedPacket,
- ClientboundLoginPacket,
+ s_hello::ServerboundHello, s_key::ServerboundKey,
+ s_login_acknowledged::ServerboundLoginAcknowledged, ClientboundLoginPacket,
},
- ClientIntention, ConnectionProtocol, PROTOCOL_VERSION,
+ ClientIntention, ConnectionProtocol, Packet, PROTOCOL_VERSION,
},
resolver, ServerAddress,
};
@@ -347,21 +344,18 @@ impl Client {
address: &ServerAddress,
) -> Result<
(
- Connection<ClientboundConfigurationPacket, ServerboundConfigurationPacket>,
+ Connection<ClientboundConfigPacket, ServerboundConfigPacket>,
GameProfile,
),
JoinError,
> {
// handshake
- conn.write(
- ClientIntentionPacket {
- protocol_version: PROTOCOL_VERSION,
- hostname: address.host.clone(),
- port: address.port,
- intention: ClientIntention::Login,
- }
- .get(),
- )
+ conn.write(ServerboundIntention {
+ protocol_version: PROTOCOL_VERSION,
+ hostname: address.host.clone(),
+ port: address.port,
+ intention: ClientIntention::Login,
+ })
.await?;
let mut conn = conn.login();
@@ -374,15 +368,12 @@ impl Client {
));
// login
- conn.write(
- ServerboundHelloPacket {
- name: account.username.clone(),
- // TODO: pretty sure this should generate an offline-mode uuid instead of just
- // Uuid::default()
- profile_id: account.uuid.unwrap_or_default(),
- }
- .get(),
- )
+ conn.write(ServerboundHello {
+ name: account.username.clone(),
+ // TODO: pretty sure this should generate an offline-mode uuid instead of just
+ // Uuid::default()
+ profile_id: account.uuid.unwrap_or_default(),
+ })
.await?;
let (conn, profile) = loop {
@@ -442,13 +433,10 @@ impl Client {
}
}
- conn.write(
- ServerboundKeyPacket {
- key_bytes: e.encrypted_public_key,
- encrypted_challenge: e.encrypted_challenge,
- }
- .get(),
- )
+ conn.write(ServerboundKey {
+ key_bytes: e.encrypted_public_key,
+ encrypted_challenge: e.encrypted_challenge,
+ })
.await?;
conn.set_encryption_key(e.secret_key);
@@ -462,8 +450,7 @@ impl Client {
"Got profile {:?}. handshake is finished and we're now switching to the configuration state",
p.game_profile
);
- conn.write(ServerboundLoginAcknowledgedPacket {}.get())
- .await?;
+ conn.write(ServerboundLoginAcknowledged {}).await?;
break (conn.configuration(), p.game_profile);
}
ClientboundLoginPacket::LoginDisconnect(p) => {
@@ -477,6 +464,13 @@ impl Client {
}
ClientboundLoginPacket::CookieRequest(p) => {
debug!("Got cookie request {:?}", p);
+
+ conn.write(packets::login::ServerboundCookieResponse {
+ key: p.key,
+ // cookies aren't implemented
+ payload: None,
+ })
+ .await?;
}
}
};
@@ -493,8 +487,9 @@ impl Client {
/// Write a packet directly to the server.
pub fn write_packet(
&self,
- packet: ServerboundGamePacket,
+ packet: impl Packet<ServerboundGamePacket>,
) -> Result<(), crate::raw_connection::WritePacketError> {
+ let packet = packet.into_variant();
self.raw_connection_mut(&mut self.ecs.lock())
.write_packet(packet)
}
@@ -605,7 +600,7 @@ impl Client {
"Sending client information (already logged in): {:?}",
client_information
);
- self.write_packet(azalea_protocol::packets::game::serverbound_client_information_packet::ServerboundClientInformationPacket { information: client_information.clone() }.get())?;
+ self.write_packet(azalea_protocol::packets::game::s_client_information::ServerboundClientInformation { information: client_information.clone() })?;
}
Ok(())