From: Ian Jackson Date: Sun, 28 Feb 2021 21:47:19 +0000 (+0000) Subject: Prevent [un]pinning of occulting/occulted pieces X-Git-Tag: otter-0.4.0~258 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=af6029552a63283bcc14c5f1adaefeea99b864ec;p=otter.git Prevent [un]pinning of occulting/occulted pieces Signed-off-by: Ian Jackson --- diff --git a/daemon/api.rs b/daemon/api.rs index 11587c62..4729a6cc 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -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, diff --git a/src/error.rs b/src/error.rs index dd12b80e..b410fd86 100644 --- a/src/error.rs +++ b/src/error.rs @@ -26,6 +26,8 @@ pub enum OnlineError { BadOperation, #[error("overlapping occultation")] OverlappingOccultation, + #[error("piece is occulting, or occulted")] + Occultation, } from_instance_lock_error!{OnlineError} diff --git a/src/hidden.rs b/src/hidden.rs index 7eb368c8..a03d27b1 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -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)]