diff options
| author | mat <git@matdoes.dev> | 2025-03-25 05:16:10 +0000 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-03-25 05:16:10 +0000 |
| commit | 8af265e48bf9f3d5263c074d034770e4216bb3f3 (patch) | |
| tree | 2605ce1d6ed8c74d47b6c355e6918721b0dc07aa /azalea-client/src/plugins/pong.rs | |
| parent | 4c53498f0795f821066941f39917ad2e4fa9a3cc (diff) | |
| download | azalea-drasl-8af265e48bf9f3d5263c074d034770e4216bb3f3.tar.xz | |
PongPlugin
Diffstat (limited to 'azalea-client/src/plugins/pong.rs')
| -rw-r--r-- | azalea-client/src/plugins/pong.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/azalea-client/src/plugins/pong.rs b/azalea-client/src/plugins/pong.rs new file mode 100644 index 00000000..827ddfb1 --- /dev/null +++ b/azalea-client/src/plugins/pong.rs @@ -0,0 +1,37 @@ +use bevy_app::{App, Plugin}; +use bevy_ecs::prelude::*; + +use super::packet::{ + config::{ConfigPingEvent, SendConfigPacketEvent}, + game::PingEvent, +}; +use crate::packet::game::SendPacketEvent; + +/// A plugin that replies to [`ClientboundPing`] packets with +/// [`ServerboundPong`]. +/// +/// This works in both the `game` and `config` states. +/// +/// [`ClientboundPing`]: azalea_protocol::packets::game::ClientboundPing +/// [`ServerboundPong`]: azalea_protocol::packets::game::ServerboundPong +pub struct PongPlugin; +impl Plugin for PongPlugin { + fn build(&self, app: &mut App) { + app.add_observer(reply_to_game_ping) + .add_observer(reply_to_config_ping); + } +} + +pub fn reply_to_game_ping(trigger: Trigger<PingEvent>, mut commands: Commands) { + commands.trigger(SendPacketEvent::new( + trigger.entity(), + azalea_protocol::packets::game::ServerboundPong { id: trigger.0.id }, + )); +} + +pub fn reply_to_config_ping(trigger: Trigger<ConfigPingEvent>, mut commands: Commands) { + commands.trigger(SendConfigPacketEvent::new( + trigger.entity(), + azalea_protocol::packets::config::ServerboundPong { id: trigger.0.id }, + )); +} |
