diff options
| author | mat <git@matdoes.dev> | 2025-03-27 21:28:08 +0000 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-03-27 21:28:13 +0000 |
| commit | 02de98240f3642019b1c8104b00bc4a9d6d17e71 (patch) | |
| tree | 1fd7074164a9cb1eb6d1012e4662cef61f10891d /azalea-client/tests | |
| parent | 37cde3ad3245675c54e70a4ded362f2a60f0d8a4 (diff) | |
| download | azalea-drasl-02de98240f3642019b1c8104b00bc4a9d6d17e71.tar.xz | |
fix not replying to ping packets in config state
Diffstat (limited to 'azalea-client/tests')
| -rw-r--r-- | azalea-client/tests/reply_to_ping_with_pong.rs | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/azalea-client/tests/reply_to_ping_with_pong.rs b/azalea-client/tests/reply_to_ping_with_pong.rs index 4ef5b2cc..d921c905 100644 --- a/azalea-client/tests/reply_to_ping_with_pong.rs +++ b/azalea-client/tests/reply_to_ping_with_pong.rs @@ -1,19 +1,63 @@ use std::sync::Arc; -use azalea_client::{packet::game::SendPacketEvent, test_simulation::*}; +use azalea_client::{ + packet::{config::SendConfigPacketEvent, game::SendPacketEvent}, + test_simulation::*, +}; +use azalea_core::resource_location::ResourceLocation; use azalea_protocol::packets::{ ConnectionProtocol, - game::{ClientboundPing, ServerboundGamePacket}, + config::{ + self, ClientboundFinishConfiguration, ClientboundRegistryData, ServerboundConfigPacket, + }, + game::{self, ServerboundGamePacket}, }; use bevy_ecs::observer::Trigger; use bevy_log::tracing_subscriber; use parking_lot::Mutex; +use simdnbt::owned::{NbtCompound, NbtTag}; #[test] fn reply_to_ping_with_pong() { let _ = tracing_subscriber::fmt::try_init(); - let mut simulation = Simulation::new(ConnectionProtocol::Game); + let mut simulation = Simulation::new(ConnectionProtocol::Configuration); + + let reply_count = Arc::new(Mutex::new(0)); + let reply_count_clone = reply_count.clone(); + simulation + .app + .add_observer(move |trigger: Trigger<SendConfigPacketEvent>| { + if trigger.sent_by == simulation.entity { + if let ServerboundConfigPacket::Pong(packet) = &trigger.packet { + assert_eq!(packet.id, 321); + *reply_count_clone.lock() += 1; + } + } + }); + + simulation.receive_packet(config::ClientboundPing { id: 321 }); + simulation.tick(); + assert_eq!(*reply_count.lock(), 1); + + // move into game state and test ClientboundPing there + + simulation.receive_packet(ClientboundRegistryData { + registry_id: ResourceLocation::new("minecraft:dimension_type"), + entries: vec![( + ResourceLocation::new("minecraft:overworld"), + Some(NbtCompound::from_values(vec![ + ("height".into(), NbtTag::Int(384)), + ("min_y".into(), NbtTag::Int(-64)), + ])), + )] + .into_iter() + .collect(), + }); + + simulation.receive_packet(ClientboundFinishConfiguration); + simulation.tick(); + let reply_count = Arc::new(Mutex::new(0)); let reply_count_clone = reply_count.clone(); simulation @@ -28,7 +72,7 @@ fn reply_to_ping_with_pong() { }); simulation.tick(); - simulation.receive_packet(ClientboundPing { id: 123 }); + simulation.receive_packet(game::ClientboundPing { id: 123 }); simulation.tick(); assert_eq!(*reply_count.lock(), 1); |
