1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

don't send chat signing certs on offline-mode servers

This commit is contained in:
mat 2025-05-09 14:12:51 -10:30
parent 1493c06de5
commit e9b3128103
3 changed files with 34 additions and 14 deletions

View file

@ -12,7 +12,7 @@ use chrono::Utc;
use tracing::{debug, error};
use uuid::Uuid;
use super::{chat, packet::game::SendPacketEvent};
use super::{chat, login::IsAuthenticated, packet::game::SendPacketEvent};
use crate::{Account, InGameState};
pub struct ChatSigningPlugin;
@ -149,7 +149,7 @@ pub struct QueuedCertsToSend {
pub fn handle_queued_certs_to_send(
mut commands: Commands,
query: Query<(Entity, &QueuedCertsToSend)>,
query: Query<(Entity, &QueuedCertsToSend), With<IsAuthenticated>>,
) {
for (entity, queued_certs) in &query {
let certs = &queued_certs.certs;

View file

@ -7,6 +7,7 @@ use bevy_ecs::prelude::*;
use derive_more::Deref;
use tracing::info;
use super::login::IsAuthenticated;
use crate::{InstanceHolder, chat_signing, client::JoinedClientBundle, connection::RawConnection};
pub struct DisconnectPlugin;
@ -44,6 +45,27 @@ pub struct DisconnectEvent {
pub reason: Option<FormattedText>,
}
/// A bundle of components that are removed when a client disconnects.
///
/// This shouldn't be used for inserts because not all of the components should
/// always be present.
#[derive(Bundle)]
pub struct RemoveOnDisconnectBundle {
pub joined_client: JoinedClientBundle,
pub entity: EntityBundle,
pub instance_holder: InstanceHolder,
pub player_metadata: PlayerMetadataBundle,
pub in_loaded_chunk: InLoadedChunk,
//// This makes it close the TCP connection.
pub raw_connection: RawConnection,
/// This makes it not send [`DisconnectEvent`] again.
pub is_connection_alive: IsConnectionAlive,
/// Resend our chat signing certs next time.
pub chat_signing_session: chat_signing::ChatSigningSession,
/// They're not authenticated anymore if they disconnected.
pub is_authenticated: IsAuthenticated,
}
/// A system that removes the several components from our clients when they get
/// a [`DisconnectEvent`].
pub fn remove_components_from_disconnected_players(
@ -62,17 +84,7 @@ pub fn remove_components_from_disconnected_players(
);
commands
.entity(*entity)
.remove::<JoinedClientBundle>()
.remove::<EntityBundle>()
.remove::<InstanceHolder>()
.remove::<PlayerMetadataBundle>()
.remove::<InLoadedChunk>()
// this makes it close the tcp connection
.remove::<RawConnection>()
// this makes it not send DisconnectEvent again
.remove::<IsConnectionAlive>()
// resend our chat signing certs next time
.remove::<chat_signing::ChatSigningSession>();
.remove::<RemoveOnDisconnectBundle>();
// note that we don't remove the client from the ECS, so if they decide
// to reconnect they'll keep their state

View file

@ -33,6 +33,11 @@ fn handle_receive_hello_event(trigger: Trigger<ReceiveHelloEvent>, mut commands:
commands.entity(player).insert(AuthTask(task));
}
/// A marker component on our clients that indicates that the server is
/// online-mode and the client has authenticated their join with Mojang.
#[derive(Component)]
pub struct IsAuthenticated;
pub fn poll_auth_task(
mut commands: Commands,
mut query: Query<(Entity, &mut AuthTask, &mut RawConnection)>,
@ -40,7 +45,10 @@ pub fn poll_auth_task(
for (entity, mut auth_task, mut raw_conn) in query.iter_mut() {
if let Some(poll_res) = future::block_on(future::poll_once(&mut auth_task.0)) {
debug!("Finished auth");
commands.entity(entity).remove::<AuthTask>();
commands
.entity(entity)
.remove::<AuthTask>()
.insert(IsAuthenticated);
match poll_res {
Ok((packet, private_key)) => {
// we use this instead of SendLoginPacketEvent to ensure that it's sent right