Skip to content

Commit

Permalink
fix for hypixel (wasn't sending ClientInformation on configuration)
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-1 committed Feb 18, 2024
1 parent e08f2d8 commit 69f7eeb
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 23 deletions.
27 changes: 6 additions & 21 deletions azalea-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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,
},
Expand All @@ -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,
Expand All @@ -39,7 +38,6 @@ use azalea_protocol::{
packets::{
configuration::{
serverbound_client_information_packet::ClientInformation,
serverbound_custom_payload_packet::ServerboundCustomPayloadPacket,
ClientboundConfigurationPacket, ServerboundConfigurationPacket,
},
game::ServerboundGamePacket,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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::<SendPacketEvent>()
.init_resource::<InstanceContainer>()
.init_resource::<TabList>();
}
Expand Down Expand Up @@ -838,6 +822,7 @@ impl PluginGroup for DefaultPlugins {
.add(MinePlugin)
.add(AttackPlugin)
.add(ChunkPlugin)
.add(ConfigurationPlugin)
.add(TickBroadcastPlugin);
#[cfg(feature = "log")]
{
Expand Down
53 changes: 53 additions & 0 deletions azalea-client/src/configuration.rs
Original file line number Diff line number Diff line change
@@ -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<InConfigurationState>>,
mut send_packet_events: EventWriter<SendConfigurationPacketEvent>,
) {
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(),
});
}
}
1 change: 1 addition & 0 deletions azalea-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 25 additions & 1 deletion azalea-client/src/packet_handling/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<SendConfigurationPacketEvent>,
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}");
}
}
}
}
14 changes: 13 additions & 1 deletion azalea-client/src/packet_handling/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Events<game::PacketEvent>>()
.init_resource::<Events<configuration::ConfigurationPacketEvent>>()
.add_event::<game::SendPacketEvent>()
.add_event::<configuration::SendConfigurationPacketEvent>()
.add_event::<AddPlayerEvent>()
.add_event::<RemovePlayerEvent>()
.add_event::<UpdatePlayerEvent>()
Expand Down

0 comments on commit 69f7eeb

Please sign in to comment.