chiark / gitweb /
movement: Prevent players moving things that they haven't grasped
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 31 Jan 2021 23:06:37 +0000 (23:06 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 31 Jan 2021 23:47:58 +0000 (23:47 +0000)
Also, a todo.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
squash! movement: Prevent players moving things that they haven't grasped

daemon/api.rs

index 1e96ba74a18797245d4c6e87d28b1ff210ce4e49..d863ba7fababc3794e52c6fcbfef2f0bfa683e5a 100644 (file)
@@ -322,6 +322,17 @@ api_route!{
   api_move, "/_/api/m",
   struct ApiPieceMove(Pos);
 
+  #[throws(OnlineError)]
+  fn check_held(&self, pc: &PieceState, player: PlayerId) {
+    // This will ensure that occultations are (in general) properly
+    // updated, because the player will (have to) release the thing
+    // again
+    if pc.held != Some(player) {
+      throw!(OnlineError::PieceHeld)
+    }
+    // xxx prevent moving anything that is occulting
+  }
+
   #[throws(ApiPieceOpError)]
   fn op(&self, a: ApiPieceOpArgs) -> PieceUpdate {
     let ApiPieceOpArgs { gs,piece, .. } = a;