@@ -3,11 +3,11 @@ use async_trait::async_trait;
3
3
use ferrumc_core:: identity:: player_identity:: PlayerIdentity ;
4
4
use ferrumc_net:: connection:: { ConnectionState , StreamWriter } ;
5
5
use ferrumc_net:: packets:: outgoing:: keep_alive:: { KeepAlive , KeepAlivePacket } ;
6
+ use ferrumc_net:: utils:: broadcast:: { BroadcastOptions , BroadcastToAll } ;
6
7
use ferrumc_net:: GlobalState ;
7
8
use std:: sync:: atomic:: { AtomicBool , Ordering } ;
8
9
use std:: sync:: Arc ;
9
10
use tracing:: { error, info, trace, warn} ;
10
- use ferrumc_net:: utils:: broadcast:: { BroadcastOptions , BroadcastToAll } ;
11
11
12
12
pub struct KeepAliveSystem {
13
13
shutdown : AtomicBool ,
@@ -24,6 +24,7 @@ impl KeepAliveSystem {
24
24
#[ async_trait]
25
25
impl System for KeepAliveSystem {
26
26
async fn start ( self : Arc < Self > , state : GlobalState ) {
27
+ info ! ( "Started keep_alive" ) ;
27
28
let mut last_time = std:: time:: SystemTime :: now ( )
28
29
. duration_since ( std:: time:: UNIX_EPOCH )
29
30
. expect ( "Time went backwards" )
@@ -71,7 +72,8 @@ impl System for KeepAliveSystem {
71
72
72
73
let packet = KeepAlivePacket :: default ( ) ;
73
74
74
- let broadcast_opts = BroadcastOptions :: default ( ) . only ( entities)
75
+ let broadcast_opts = BroadcastOptions :: default ( )
76
+ . only ( entities)
75
77
. with_sync_callback ( move |entity, state| {
76
78
let Ok ( mut keep_alive) = state. universe . get_mut :: < KeepAlive > ( entity) else {
77
79
warn ! ( "Failed to get <KeepAlive> component for entity {}" , entity) ;
@@ -84,7 +86,8 @@ impl System for KeepAliveSystem {
84
86
if let Err ( e) = state. broadcast ( & packet, broadcast_opts) . await {
85
87
error ! ( "Error sending keep alive packet: {}" , e) ;
86
88
} ;
87
-
89
+ // TODO, this should be configurable as some people may have bad network so the clients may end up disconnecting from the server moments before the keep alive is sent
90
+ tokio:: time:: sleep ( tokio:: time:: Duration :: from_secs ( 30 ) ) . await ;
88
91
}
89
92
}
90
93
0 commit comments