chiark / gitweb /
PieceMoveable: Enforce in /m api call
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 20 Mar 2021 22:58:41 +0000 (22:58 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 20 Mar 2021 22:58:41 +0000 (22:58 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/api.rs
src/error.rs

index b90e401ab9bed9ff50d36769e9cf328c4fe353a2..147c8b3887734f728aabe12772d2bef8445ce1e6 100644 (file)
@@ -76,7 +76,7 @@ impl From<&OnlineErrorResponse> for rocket::http::Status {
       ServerFailure(_) => Status::InternalServerError,
       NoClient | NoPlayer(_) | GameBeingDestroyed
         => Status::NotFound,
-      OE::PieceHeld |
+      OE::PieceHeld | OE::PieceImmoveable |
       OE::OverlappingOccultation | OE::Occultation |
       OE::BadPieceStateForOperation
         => Status::Conflict,
@@ -411,6 +411,11 @@ api_route!{
       // again
       if gpc.held != Some(player) { throw!(OnlineError::PieceHeld) }
       if gpc.occult.is_active() { throw!(OE::Occultation) }
+      if matches_doesnot!(
+        gpc.moveable(),
+        = PieceMoveable::No,
+        ! PieceMoveable::Yes | PieceMoveable::IfWresting,
+      ) { throw!(OE::PieceImmoveable) }
     }
   }
 
index 64436285815b1b39f00cc58c4ecf5d47ec42e9d3..5e63931755c0649a9dbac53c9f46fd9f87b953ec 100644 (file)
@@ -21,6 +21,8 @@ pub enum OnlineError {
   #[error("referenced piece is gone (maybe race)")]
   PieceHeld,
   #[error("improper UI operation")]
+  PieceImmoveable,
+  #[error("improper UI operation")]
   BadOperation,
   #[error("overlapping occultation")]
   OverlappingOccultation,