@@ -338,6 +338,9 @@ impl PlayerClient {
338338 dest_z : i32 ,
339339 actor_ref : ActorRef < PlayerClient > ,
340340 ) -> anyhow:: Result < ( i32 , i32 , i32 ) > {
341+ if self . status != ClientStatus :: InGame {
342+ bail ! ( "Can't start movement. PlayerClient is not in game" ) ;
343+ }
341344 // Compute effective current position consistent with validation logic
342345 let ( current_x, current_y, current_z) = self . effective_current_position ( ) ?;
343346
@@ -363,7 +366,7 @@ impl PlayerClient {
363366 let controller = self . controller . clone ( ) ;
364367
365368 let task_handle = tokio:: spawn ( async move {
366- let mut interval = tokio:: time:: interval ( std :: time :: Duration :: from_millis ( 300 ) ) ;
369+ let mut interval = tokio:: time:: interval ( Duration :: from_millis ( 300 ) ) ;
367370
368371 loop {
369372 // Check movement state BEFORE waiting
@@ -388,7 +391,7 @@ impl PlayerClient {
388391 error ! ( "Error while broadcasting movement packet" ) ;
389392 }
390393 } else {
391- // Error or no movement state, stop a task
394+ // Error or no movement state, or movement is not allowed, stop a task
392395 break ;
393396 }
394397
@@ -588,6 +591,10 @@ impl Message<GetMovementPosition> for PlayerClient {
588591 _: GetMovementPosition ,
589592 _ctx : & mut Context < Self , Self :: Reply > ,
590593 ) -> Self :: Reply {
594+ if self . status != ClientStatus :: InGame {
595+ self . stop_movement ( ) ;
596+ bail ! ( "Can't get movement position. PlayerClient is not in game" ) ;
597+ }
591598 if let Some ( movement) = self . movement_state . as_ref ( ) {
592599 let ( x, y, z) = movement. calculate_current_position ( ) ;
593600 let has_arrived = movement. has_arrived ( ) ;
0 commit comments