chiark / gitweb /
Prevent [un]pinning of occulting/occulted pieces
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 28 Feb 2021 21:47:19 +0000 (21:47 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 28 Feb 2021 21:47:19 +0000 (21:47 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/api.rs
src/error.rs
src/hidden.rs

index 11587c622a17b5253b7d36695ce50276f61b2f93..4729a6cc5a888034557aef1ff5e2370c45ce0cf1 100644 (file)
@@ -77,7 +77,7 @@ impl From<&OnlineErrorResponse> for rocket::http::Status {
       NoClient | NoPlayer(_) | GameBeingDestroyed
         => Status::NotFound,
       OE::PieceHeld | OE::PieceGone |
-      OE::OverlappingOccultation
+      OE::OverlappingOccultation | OE::Occultation
         => Status::Conflict,
       InvalidZCoord | BadOperation | BadJSON(_)
         => Status::BadRequest,
@@ -422,6 +422,7 @@ api_route!{
       &gs.occults, player, gpl, piece, gpc, p,
       if gpc.pinned { "pinned" } else { "unpinned" },
     )?;
+    forbid_piece_involved_in_occultation(&gpc)?;
     gpc.pinned = self.0;
     let update = PieceUpdateOp::Modify(());
     (WhatResponseToClientOp::Predictable,
index dd12b80e889c2b00195d991faff060f70abab3d3..b410fd862e4ea8861a62ee5b4ad4c3d4b3d26d25 100644 (file)
@@ -26,6 +26,8 @@ pub enum OnlineError {
   BadOperation,
   #[error("overlapping occultation")]
   OverlappingOccultation,
+  #[error("piece is occulting, or occulted")]
+  Occultation,
 }
 from_instance_lock_error!{OnlineError}
 
index 7eb368c8bc778399c25e06da4a51ae17dab4b750..a03d27b16db8df14972921b5b72e16f27d03fc98 100644 (file)
@@ -207,6 +207,10 @@ pub fn piece_involved_in_occultation(gpc: &GPiece) -> bool {
   gpc.occult.passive.is_some() ||
   gpc.occult.active.is_some()
 }
+#[throws(OE)]
+pub fn forbid_piece_involved_in_occultation(gpc: &GPiece) {
+  if piece_involved_in_occultation(&gpc) { throw!(OE::Occultation) }
+}
 
 pub fn vpiece_decode(
   _gs: &GameState, // xxx
@@ -231,7 +235,6 @@ pub fn massage_prep_piecestate(
 
 // xxx prevent addpiece and removepiece in places that would be occulted
 // xxx this means this only happens on ungrab I think ?
-// xxx prevent occultation of pinned things / pinning of occulted things
 // xxx prevent occultation scrambling of grasped things
 
 #[throws(InternalError)]