From: Ian Jackson Date: Mon, 15 Mar 2021 16:40:46 +0000 (+0000) Subject: Do not leak item name etc. of occulted pieces X-Git-Tag: otter-0.4.0~27 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=7ef260c8a99e64aeb255c70f5b6d6126004ae409;p=otter.git Do not leak item name etc. of occulted pieces Signed-off-by: Ian Jackson --- diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index b03dfa65..9931141b 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -397,23 +397,31 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>( if let Some(ipc) = ig.ipieces.get(piece); let visible = if ! piece_at_all_occulted(gpc) { // todo: something more sophisticated would be nice - let pri = PieceRenderInstructions::new_visible( - // visible id is internal one here - VisiblePieceId(piece.data()) + let (pri, unocc_ok) = ( + PieceRenderInstructions::new_visible( + // visible id is internal one here + VisiblePieceId(piece.data()) + ), + ShowUnocculted::new_visible(), ); let bbox = ipc.p.bbox_approx()?; let desc_html = pri.describe(ioccults, gpc, ipc); - Some(MgmtGamePieceVisibleInfo { + Some((MgmtGamePieceVisibleInfo { pos, face, desc_html, bbox - }) + }, unocc_ok)) } else { None }; - let itemname = ipc.p.itemname().to_string(); + let itemname = if let Some((_,unocc_ok)) = visible { + ipc.p.itemname(unocc_ok).to_string() + } else { + "occulted-item".to_string() + }; then { Some(MgmtGamePieceInfo { - piece, itemname, - visible + piece, + itemname, + visible: visible.map(|v| v.0) }) } else { None diff --git a/src/gamestate.rs b/src/gamestate.rs index 3f94693b..ec9836f5 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -154,7 +154,7 @@ pub trait PieceTrait: OutlineTrait + Send + Debug + 'static { ExecuteGameChangeUpdates{ pcs: vec![], log: vec![], raw: None } } - fn itemname(&self) -> &str; + fn itemname(&self, _y: ShowUnocculted) -> &str; } #[typetag::serde] diff --git a/src/hand.rs b/src/hand.rs index 2b61db41..3462e598 100644 --- a/src/hand.rs +++ b/src/hand.rs @@ -110,7 +110,7 @@ impl PieceTrait for Hand { delegate!{ to self.shape { - fn itemname(&self) -> &str; + fn itemname(&self, y: ShowUnocculted) -> &str; } } diff --git a/src/pieces.rs b/src/pieces.rs index 675258fa..1ef48572 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -144,7 +144,7 @@ impl PieceTrait for SimpleShape { } fn nfaces(&self) -> RawFaceId { self.count_faces().try_into().unwrap() } - fn itemname(&self) -> &str { self.itemname() } + fn itemname(&self, y: ShowUnocculted) -> &str { self.itemname(y) } } impl GenericSimpleShape @@ -154,7 +154,7 @@ impl GenericSimpleShape pub fn count_faces(&self) -> usize { max(self.colours.len(), self.edges.len()) } - pub fn itemname(&self) -> &str { &self.itemname } + pub fn itemname(&self, _: ShowUnocculted) -> &str { &self.itemname } #[throws(SpecError)] pub fn new(desc: Desc, outline: Outl, diff --git a/src/shapelib.rs b/src/shapelib.rs index df1977ee..ab275b7a 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -226,7 +226,7 @@ impl PieceTrait for Item { self.descs[ self.faces[gpc.face].desc ].clone() } - fn itemname(&self) -> &str { &self.itemname } + fn itemname(&self, _: ShowUnocculted) -> &str { &self.itemname } } static SHAPELIBS: RwLock> = const_rwlock(None);