Skip to content

Commit

Permalink
fix brand and client info so they're only sent when leaving login ins…
Browse files Browse the repository at this point in the history
…tead of entering config

closes #206
  • Loading branch information
mat-1 committed Feb 22, 2025
1 parent 444993b commit 6fdf5fc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
7 changes: 5 additions & 2 deletions azalea-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ use crate::{
mining::{self, MinePlugin},
movement::{LastSentLookDirection, PhysicsState, PlayerMovePlugin},
packet_handling::{
login::{self, LoginSendPacketQueue},
login::{self, InLoginState, LoginSendPacketQueue},
PacketHandlerPlugin,
},
player::retroactively_add_game_profile_component,
Expand Down Expand Up @@ -371,6 +371,7 @@ impl Client {
ecs_lock.lock().entity_mut(entity).insert((
LoginSendPacketQueue { tx: ecs_packets_tx },
login::IgnoreQueryIds::default(),
InLoginState,
));

// login
Expand Down Expand Up @@ -457,6 +458,7 @@ impl Client {
p.game_profile
);
conn.write(ServerboundLoginAcknowledged {}).await?;

break (conn.config(), p.game_profile);
}
ClientboundLoginPacket::LoginDisconnect(p) => {
Expand Down Expand Up @@ -485,7 +487,8 @@ impl Client {
.lock()
.entity_mut(entity)
.remove::<login::IgnoreQueryIds>()
.remove::<LoginSendPacketQueue>();
.remove::<LoginSendPacketQueue>()
.remove::<InLoginState>();

Ok((conn, profile))
}
Expand Down
24 changes: 19 additions & 5 deletions azalea-client/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,30 @@ use azalea_protocol::{
};
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
use tracing::{debug, warn};

use crate::{client::InConfigState, packet_handling::configuration::SendConfigurationEvent};
use crate::{
client::InConfigState,

Check warning on line 15 in azalea-client/src/configuration.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `client::InConfigState`

warning: unused import: `client::InConfigState` --> azalea-client/src/configuration.rs:15:5 | 15 | client::InConfigState, | ^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default
packet_handling::{configuration::SendConfigurationEvent, login::InLoginState},
};

pub struct ConfigurationPlugin;
impl Plugin for ConfigurationPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
Update,
handle_in_configuration_state
handle_end_login_state
.before(crate::packet_handling::configuration::handle_send_packet_event),
);
}
}

fn handle_in_configuration_state(
query: Query<(Entity, &ClientInformation), Added<InConfigState>>,
fn handle_end_login_state(
mut removed: RemovedComponents<InLoginState>,
query: Query<&ClientInformation>,
mut send_packet_events: EventWriter<SendConfigurationEvent>,
) {
for (entity, client_information) in query.iter() {
for entity in removed.read() {
let mut brand_data = Vec::new();
// they don't have to know :)
"vanilla".azalea_write(&mut brand_data).unwrap();
Expand All @@ -39,6 +44,15 @@ fn handle_in_configuration_state(
},
));

let client_information = match query.get(entity).ok() {
Some(i) => i,
None => {
warn!("ClientInformation component was not set before leaving login state, using a default");
&ClientInformation::default()
}
};

debug!("Writing ClientInformation while in config state: {client_information:?}");
send_packet_events.send(SendConfigurationEvent::new(
entity,
ServerboundClientInformation {
Expand Down
5 changes: 5 additions & 0 deletions azalea-client/src/packet_handling/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ pub struct LoginSendPacketQueue {
pub tx: mpsc::UnboundedSender<ServerboundLoginPacket>,
}

/// A marker component for local players that are currently in the
/// `login` state.
#[derive(Component, Clone, Debug)]
pub struct InLoginState;

pub fn handle_send_packet_event(
mut send_packet_events: EventReader<SendLoginPacketEvent>,
mut query: Query<&mut LoginSendPacketQueue>,
Expand Down

0 comments on commit 6fdf5fc

Please sign in to comment.