blob: 6370a932b8846ce94969852ac5fc6d2ec2932d80 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
use azalea_protocol::packets::{config, game};
use bevy_app::{App, Plugin};
use bevy_ecs::prelude::*;
use super::packet::{
config::{ConfigPingEvent, SendConfigPacketEvent},
game::GamePingEvent,
};
use crate::packet::game::SendGamePacketEvent;
/// 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(ping: On<GamePingEvent>, mut commands: Commands) {
commands.trigger(SendGamePacketEvent::new(
ping.entity,
game::ServerboundPong { id: ping.packet.id },
));
}
pub fn reply_to_config_ping(ping: On<ConfigPingEvent>, mut commands: Commands) {
commands.trigger(SendConfigPacketEvent::new(
ping.entity,
config::ServerboundPong { id: ping.packet.id },
));
}
|