@@ -8,7 +8,7 @@ use bevy::{
88 prelude:: * ,
99 time:: common_conditions:: on_timer,
1010} ;
11- use log:: { Level , debug, log_enabled, trace } ;
11+ use log:: { Level , debug, log_enabled} ;
1212
1313use crate :: {
1414 prelude:: * ,
@@ -17,23 +17,14 @@ use crate::{
1717 replication:: {
1818 rules:: ReplicationRules ,
1919 send:: {
20- DespawnBuffer , ServerChangeTick , buffer_despawn, buffer_removals,
21- check_mutation_ticks, cleanup_acks,
22- client_pools:: ClientPools ,
23- client_ticks:: ClientTicks ,
24- collect_changes, collect_despawns, collect_mappings, collect_removals,
25- prepare_messages,
26- priority_map:: PriorityMap ,
27- receive_acks,
28- related_entities:: RelatedEntities ,
29- removal_buffer:: RemovalBuffer ,
20+ self , AuthorizedClient , DespawnBuffer , SendSystems , ServerChangeTick ,
21+ buffer_despawn, buffer_removals, check_mutation_ticks, cleanup_acks,
22+ client_pools:: ClientPools , collect_changes, collect_despawns, collect_mappings,
23+ collect_removals, increment_tick, prepare_messages, receive_acks,
24+ related_entities:: RelatedEntities , removal_buffer:: RemovalBuffer ,
3025 replicated_archetypes:: ReplicatedArchetypes ,
31- replication_messages:: {
32- mutations:: Mutations , serialized_data:: SerializedData , updates:: Updates ,
33- } ,
34- send_messages,
35- server_tick:: ServerTick ,
36- visibility:: { client_visibility:: ClientVisibility , registry:: FilterRegistry } ,
26+ replication_messages:: serialized_data:: SerializedData , send_messages,
27+ server_tick:: ServerTick , visibility:: registry:: FilterRegistry ,
3728 } ,
3829 } ,
3930 } ,
@@ -109,14 +100,14 @@ impl Plugin for ServerPlugin {
109100 . init_resource :: < FilterRegistry > ( )
110101 . configure_sets (
111102 PreUpdate ,
112- ( ServerSystems :: ReceivePackets , ServerSystems :: Receive ) . chain ( ) ,
103+ ( SendSystems :: ReceivePackets , SendSystems :: Receive ) . chain ( ) ,
113104 )
114105 . configure_sets (
115106 PostUpdate ,
116107 (
117- ServerSystems :: IncrementTick ,
118- ServerSystems :: Send ,
119- ServerSystems :: SendPackets ,
108+ SendSystems :: IncrementTick ,
109+ SendSystems :: Send ,
110+ SendSystems :: SendPackets ,
120111 )
121112 . chain ( ) ,
122113 )
@@ -131,10 +122,10 @@ impl Plugin for ServerPlugin {
131122 cleanup_acks ( self . mutations_timeout ) . run_if ( on_timer ( self . mutations_timeout ) ) ,
132123 )
133124 . chain ( )
134- . in_set ( ServerSystems :: Receive )
125+ . in_set ( SendSystems :: Receive )
135126 . run_if ( in_state ( ServerState :: Running ) ) ,
136127 )
137- . add_systems ( OnExit ( ServerState :: Running ) , reset)
128+ . add_systems ( OnExit ( ServerState :: Running ) , send :: reset)
138129 . add_systems (
139130 PostUpdate ,
140131 (
@@ -147,7 +138,7 @@ impl Plugin for ServerPlugin {
147138 )
148139 . chain ( )
149140 . run_if ( resource_changed :: < ServerTick > )
150- . in_set ( ServerSystems :: Send )
141+ . in_set ( SendSystems :: Send )
151142 . run_if ( in_state ( ServerState :: Running ) ) ,
152143 ) ;
153144
@@ -156,7 +147,7 @@ impl Plugin for ServerPlugin {
156147 app. add_systems (
157148 tick_schedule,
158149 increment_tick
159- . in_set ( ServerSystems :: IncrementTick )
150+ . in_set ( SendSystems :: IncrementTick )
160151 . run_if ( in_state ( ServerState :: Running ) ) ,
161152 ) ;
162153 }
@@ -242,74 +233,3 @@ fn check_protocol(
242233 disconnects. write ( DisconnectRequest { client } ) ;
243234 }
244235}
245-
246- /// Increments current server tick which causes the server to replicate this frame.
247- pub fn increment_tick ( mut server_tick : ResMut < ServerTick > ) {
248- trace ! ( "incrementing `{:?}`" , * server_tick) ;
249- server_tick. increment ( ) ;
250- }
251-
252- fn reset (
253- mut commands : Commands ,
254- mut messages : ResMut < ServerMessages > ,
255- mut server_tick : ResMut < ServerTick > ,
256- mut related_entities : ResMut < RelatedEntities > ,
257- clients : Query < Entity , With < ConnectedClient > > ,
258- mut message_buffer : ResMut < MessageBuffer > ,
259- ) {
260- messages. clear ( ) ;
261- * server_tick = Default :: default ( ) ;
262- message_buffer. clear ( ) ;
263- related_entities. clear ( ) ;
264- for client in & clients {
265- commands. entity ( client) . despawn ( ) ;
266- }
267- }
268-
269- /// Set with replication and event systems related to server.
270- #[ derive( SystemSet , Debug , Hash , PartialEq , Eq , Clone , Copy ) ]
271- pub enum ServerSystems {
272- /// Systems that receive packets from the messaging backend and update [`ServerState`].
273- ///
274- /// Used by the messaging backend.
275- ///
276- /// Runs in [`PreUpdate`].
277- ReceivePackets ,
278- /// Systems that read data from [`ServerMessages`].
279- ///
280- /// Runs in [`PreUpdate`].
281- Receive ,
282- /// Systems that build the initial graph with all related entities registered via
283- /// [`crate::shared::replication::send::related_entities::SyncRelatedAppExt::sync_related_entities`].
284- ///
285- /// The graph is kept in sync with observers.
286- ///
287- /// Runs in [`OnEnter`] for [`ServerState::Running`].
288- ReadRelations ,
289- /// System that increments [`ServerTick`].
290- ///
291- /// Runs in [`ServerPlugin::tick_schedule`].
292- IncrementTick ,
293- /// Systems that write data to [`ServerMessages`].
294- ///
295- /// Runs in [`PostUpdate`] if [`ServerTick`] changes.
296- Send ,
297- /// Systems that send packets to the messaging backend.
298- ///
299- /// Used by the messaging backend.
300- ///
301- /// Runs in [`PostUpdate`] if [`ServerTick`] changes.
302- SendPackets ,
303- }
304-
305- /// Marker that enables replication and all events for a client.
306- ///
307- /// Until authorization happened, the client and server can still exchange network events that are marked as
308- /// independent via [`ServerMessageAppExt::make_message_independent`] or [`ServerEventAppExt::make_event_independent`].
309- /// **All other events will be ignored**.
310- ///
311- /// See also [`ConnectedClient`] and [`RepliconSharedPlugin::auth_method`].
312- #[ derive( Component , Reflect , Default ) ]
313- #[ component( immutable) ]
314- #[ require( ClientTicks , ClientVisibility , PriorityMap , Updates , Mutations ) ]
315- pub struct AuthorizedClient ;
0 commit comments