From 69f7eebcb300bbefdc8b10c191a09db250bde630 Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 18 Feb 2024 02:25:20 -0600 Subject: fix for hypixel (wasn't sending ClientInformation on configuration) --- azalea-client/src/client.rs | 27 +++-------- azalea-client/src/configuration.rs | 53 ++++++++++++++++++++++ azalea-client/src/lib.rs | 1 + azalea-client/src/packet_handling/configuration.rs | 26 ++++++++++- azalea-client/src/packet_handling/mod.rs | 14 +++++- 5 files changed, 98 insertions(+), 23 deletions(-) create mode 100644 azalea-client/src/configuration.rs diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs index 2dec635d..af535415 100644 --- a/azalea-client/src/client.rs +++ b/azalea-client/src/client.rs @@ -2,6 +2,7 @@ use crate::{ attack::{self, AttackPlugin}, chat::ChatPlugin, chunks::{ChunkBatchInfo, ChunkPlugin}, + configuration::ConfigurationPlugin, disconnect::{DisconnectEvent, DisconnectPlugin}, events::{Event, EventPlugin, LocalPlayerEvents}, interact::{CurrentSequenceNumber, InteractPlugin}, @@ -13,7 +14,6 @@ use crate::{ mining::{self, MinePlugin}, movement::{LastSentLookDirection, PhysicsState, PlayerMovePlugin}, packet_handling::{ - game::{handle_send_packet_event, SendPacketEvent}, login::{self, LoginSendPacketQueue}, PacketHandlerPlugin, }, @@ -25,9 +25,8 @@ use crate::{ }; use azalea_auth::{game_profile::GameProfile, sessionserver::ClientSessionServerError}; -use azalea_buf::McBufWritable; use azalea_chat::FormattedText; -use azalea_core::{position::Vec3, resource_location::ResourceLocation, tick::GameTick}; +use azalea_core::{position::Vec3, tick::GameTick}; use azalea_entity::{ indexing::{EntityIdIndex, EntityUuidIndex}, metadata::Health, @@ -39,7 +38,6 @@ use azalea_protocol::{ packets::{ configuration::{ serverbound_client_information_packet::ClientInformation, - serverbound_custom_payload_packet::ServerboundCustomPayloadPacket, ClientboundConfigurationPacket, ServerboundConfigurationPacket, }, game::ServerboundGamePacket, @@ -242,23 +240,11 @@ impl Client { }; let conn = Connection::new(resolved_address).await?; - let (mut conn, game_profile) = + let (conn, game_profile) = Self::handshake(ecs_lock.clone(), entity, conn, account, address).await?; - { - // quickly send the brand here - let mut brand_data = Vec::new(); - // they don't have to know :) - "vanilla".write_into(&mut brand_data).unwrap(); - conn.write( - ServerboundCustomPayloadPacket { - identifier: ResourceLocation::new("brand"), - data: brand_data.into(), - } - .get(), - ) - .await?; - } + // note that we send the proper packets in + // crate::configuration::handle_in_configuration_state let (read_conn, write_conn) = conn.into_split(); let (read_conn, write_conn) = (read_conn.raw, write_conn.raw); @@ -678,10 +664,8 @@ impl Plugin for AzaleaPlugin { death_event, // add GameProfileComponent when we get an AddPlayerEvent retroactively_add_game_profile_component.after(EntityUpdateSet::Index), - handle_send_packet_event, ), ) - .add_event::() .init_resource::() .init_resource::(); } @@ -838,6 +822,7 @@ impl PluginGroup for DefaultPlugins { .add(MinePlugin) .add(AttackPlugin) .add(ChunkPlugin) + .add(ConfigurationPlugin) .add(TickBroadcastPlugin); #[cfg(feature = "log")] { diff --git a/azalea-client/src/configuration.rs b/azalea-client/src/configuration.rs new file mode 100644 index 00000000..21e31b24 --- /dev/null +++ b/azalea-client/src/configuration.rs @@ -0,0 +1,53 @@ +use azalea_buf::McBufWritable; +use azalea_core::resource_location::ResourceLocation; +use azalea_protocol::packets::configuration::{ + serverbound_client_information_packet::{ + ClientInformation, ServerboundClientInformationPacket, + }, + serverbound_custom_payload_packet::ServerboundCustomPayloadPacket, +}; +use bevy_app::prelude::*; +use bevy_ecs::prelude::*; + +use crate::{ + client::InConfigurationState, packet_handling::configuration::SendConfigurationPacketEvent, +}; + +pub struct ConfigurationPlugin; +impl Plugin for ConfigurationPlugin { + fn build(&self, app: &mut App) { + app.add_systems( + Update, + handle_in_configuration_state + .after(crate::packet_handling::configuration::handle_send_packet_event), + ); + } +} + +fn handle_in_configuration_state( + query: Query<(Entity, &ClientInformation), Added>, + mut send_packet_events: EventWriter, +) { + for (entity, client_information) in query.iter() { + // quickly send the brand here + let mut brand_data = Vec::new(); + // they don't have to know :) + "vanilla".write_into(&mut brand_data).unwrap(); + send_packet_events.send(SendConfigurationPacketEvent { + entity, + packet: ServerboundCustomPayloadPacket { + identifier: ResourceLocation::new("brand"), + data: brand_data.into(), + } + .get(), + }); + + send_packet_events.send(SendConfigurationPacketEvent { + entity, + packet: ServerboundClientInformationPacket { + information: client_information.clone(), + } + .get(), + }); + } +} diff --git a/azalea-client/src/lib.rs b/azalea-client/src/lib.rs index 1eaf4605..41399ce9 100644 --- a/azalea-client/src/lib.rs +++ b/azalea-client/src/lib.rs @@ -13,6 +13,7 @@ pub mod attack; pub mod chat; pub mod chunks; mod client; +pub mod configuration; pub mod disconnect; mod entity_query; mod events; diff --git a/azalea-client/src/packet_handling/configuration.rs b/azalea-client/src/packet_handling/configuration.rs index ddf77a52..da5ce57f 100644 --- a/azalea-client/src/packet_handling/configuration.rs +++ b/azalea-client/src/packet_handling/configuration.rs @@ -6,7 +6,9 @@ use azalea_protocol::packets::configuration::serverbound_finish_configuration_pa use azalea_protocol::packets::configuration::serverbound_keep_alive_packet::ServerboundKeepAlivePacket; use azalea_protocol::packets::configuration::serverbound_pong_packet::ServerboundPongPacket; use azalea_protocol::packets::configuration::serverbound_resource_pack_packet::ServerboundResourcePackPacket; -use azalea_protocol::packets::configuration::ClientboundConfigurationPacket; +use azalea_protocol::packets::configuration::{ + ClientboundConfigurationPacket, ServerboundConfigurationPacket, +}; use azalea_protocol::packets::ConnectionProtocol; use azalea_protocol::read::deserialize_packet; use azalea_world::Instance; @@ -201,3 +203,25 @@ pub fn process_packet_events(ecs: &mut World) { } } } + +/// An event for sending a packet to the server while we're in the +/// `configuration` state. +#[derive(Event)] +pub struct SendConfigurationPacketEvent { + pub entity: Entity, + pub packet: ServerboundConfigurationPacket, +} + +pub fn handle_send_packet_event( + mut send_packet_events: EventReader, + mut query: Query<&mut RawConnection>, +) { + for event in send_packet_events.read() { + if let Ok(raw_connection) = query.get_mut(event.entity) { + // debug!("Sending packet: {:?}", event.packet); + if let Err(e) = raw_connection.write_packet(event.packet.clone()) { + error!("Failed to send packet: {e}"); + } + } + } +} diff --git a/azalea-client/src/packet_handling/mod.rs b/azalea-client/src/packet_handling/mod.rs index 9823035d..19de27eb 100644 --- a/azalea-client/src/packet_handling/mod.rs +++ b/azalea-client/src/packet_handling/mod.rs @@ -49,10 +49,22 @@ impl Plugin for PacketHandlerPlugin { login::process_packet_events, ), ) - .add_systems(Update, death_event_on_0_health.before(death_listener)) + .add_systems( + Update, + ( + ( + configuration::handle_send_packet_event, + game::handle_send_packet_event, + ) + .chain(), + death_event_on_0_health.before(death_listener), + ), + ) // we do this instead of add_event so we can handle the events ourselves .init_resource::>() .init_resource::>() + .add_event::() + .add_event::() .add_event::() .add_event::() .add_event::() -- cgit v1.2.3