-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent.rs
86 lines (73 loc) · 2.51 KB
/
event.rs
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//! Events exported from this crate.
//!
//! These events define a high-level API for a Minecraft client that is
//! compatible with multiple different server versions.
//!
//! The protocol defined by these events is similar but far from identical to
//! the actual Minecraft protocol defined at <https://wiki.vg/Protocol>. This
//! API is much more high-level, and the "back-end" is concerned with speaking
//! the actual protocol and converting to and from this higher-level API.
pub use uuid::Uuid;
pub mod serverbound {
//! Definitions for all serverbound events.
#[allow(unused)]
use super::clientbound;
/// Initiates login for the given user on the given server.
///
/// The protocol backend handles the entire login exchange.
///
/// # See also
///
/// * [`clientbound::LoginSuccess`]
/// * [`clientbound::Disconnect`]
#[derive(Debug, Clone, PartialEq)]
pub struct Login {
/// Hostname or IP address of the server.
pub server: String,
/// Username being used to join the game.
pub username: String,
}
pub(crate) fn add_events(app: &mut bevy::app::App) {
app.add_event::<Login>();
}
}
pub mod clientbound {
//! Definitions for all clientbound events.
#[allow(unused)]
use super::serverbound;
/// Notifies the client that they have successfully logged in to the server.
///
/// # See also
///
/// * [`serverbound::Login`]
#[derive(Debug, Clone, PartialEq)]
pub struct LoginSuccess {
/// UUID assigned by the server to this client.
pub uuid: uuid::Uuid,
/// Username that was used to join the game.
pub username: String,
}
/// Notifies the client they have been disconnected from the server.
///
/// This could happen for a number of reasons:
/// * Login failure.
/// * User is kicked from the server.
/// * Backend fails to keep the connection alive.
/// * Generic networking error.
/// * etc...
#[derive(Debug, Clone, PartialEq)]
pub struct Disconnect {
/// Human-readable reason for why the disconnect occurred.
pub reason: String,
}
/// Contains data relating to a 16x256x16 chunk of the Minecraft world.
#[derive(Debug, Clone, PartialEq)]
pub struct ChunkData {
pub chunk_data: brine_chunk::Chunk,
}
pub(crate) fn add_events(app: &mut bevy::app::App) {
app.add_event::<LoginSuccess>();
app.add_event::<Disconnect>();
app.add_event::<ChunkData>();
}
}