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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//! Bevy adapter for the naia server.
//!
//! Adds naia's replication and messaging into a Bevy application. Entities and
//! components that carry the [`Replicate`] marker are automatically tracked and
//! replicated to connected clients; no manual diff loop is required.
//!
//! # Setup
//!
//! Add the plugin and call [`listen_on_app`] (or call [`Server::listen`] in a
//! startup system):
//!
//! ```no_run
//! # use bevy_app::App;
//! # use naia_bevy_server::Plugin;
//! fn main() {
//! App::new()
//! // .add_plugins(DefaultPlugins)
//! .add_plugins(Plugin::new(server_config(), protocol()))
//! // .add_systems(Startup, init)
//! .run();
//! }
//! # fn server_config() -> naia_bevy_server::ServerConfig { todo!() }
//! # fn protocol() -> naia_bevy_shared::Protocol { todo!() }
//! ```
//!
//! Interact with the server via the [`Server`] Bevy resource, or use
//! [`CommandsExt`] / [`ServerCommandsExt`] on [`Commands`] to spawn entities
//! and configure replication.
//!
//! # Quick start
//!
//! ```no_run
//! use bevy_app::{App, Startup, Update};
//! use bevy_ecs::prelude::*;
//! use naia_bevy_server::{
//! events::ConnectEvent,
//! transport::webrtc,
//! Plugin, Server, ServerConfig, UserKey,
//! };
//! use naia_bevy_shared::Protocol;
//!
//! fn main() {
//! App::new()
//! .add_plugins(Plugin::new(ServerConfig::default(), Protocol::builder().build()))
//! .add_systems(Startup, init)
//! .add_systems(Update, on_connect)
//! .run();
//! }
//!
//! fn init(mut server: Server) {
//! server.listen(webrtc::Socket::new(&server_addrs(), None));
//! }
//!
//! fn on_connect(mut server: Server, mut connect_events: EventReader<ConnectEvent>) {
//! for ConnectEvent(user_key) in connect_events.read() {
//! server.accept_connection(user_key);
//! // server.user_mut(user_key).enter_room(&room_key);
//! }
//! }
//! # fn server_addrs() -> naia_bevy_server::transport::webrtc::ServerAddrs { todo!() }
//! ```
//!
//! # Key types
//!
//! | Type | Purpose |
//! |------|---------|
//! | [`Plugin`] | Registers systems and the [`Server`] resource |
//! | [`Server`] | Bevy-wrapped server resource |
//! | [`CommandsExt`] | Extension methods on [`Commands`] for replication setup |
//! | [`ServerCommandsExt`] | Server-only extension methods on [`Commands`] |
//! | [`events`] | Bevy events mirroring naia world events |
//!
//! [`Commands`]: bevy_ecs::system::Commands
//! [`Replicate`]: naia_bevy_shared::Replicate
pub use ;
pub use ;
pub use AppRegisterComponentEvents;
pub use ;
pub use ;
pub use Plugin;
pub use Server;
/// Call `listen` on the naia server resource directly via the App,
/// before any systems run. Use this when you want to initialize the
/// server during app construction rather than in a startup system.
/// Phantom tag type for single-server Bevy apps.
///
/// Pass this as the `T` parameter to [`Plugin`], [`Server`], and event types
/// when your app connects to exactly one server instance. For multi-server
/// apps define your own tag structs instead.
;
/// Alias for [`Plugin`] — for single-server apps.
pub type DefaultPlugin = Plugin;