From: Ian Jackson Date: Thu, 25 Mar 2021 18:44:05 +0000 (+0000) Subject: commands etc.: Delete old aliases when resetting the game X-Git-Tag: otter-0.5.0~403 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=16ba7bfbbb59169f11de5c89416c405bcaade357;p=otter.git commands etc.: Delete old aliases when resetting the game * Make ListPieces return the aliases too (changing its ABI) * Make list_pieces return the aliases too, so we make sure we don't miss any * Actually delete old aliases in the game reset in otter(1) Signed-off-by: Ian Jackson --- diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index 9d275890..5fa1bda7 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -435,7 +435,8 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>( } }))().transpose() ).collect::,_>>()?; - Ok(MGR::Pieces(pieces)) + let pcaliases = ig.pcaliases.keys().cloned().collect(); + Ok(MGR::Pieces { pieces, pcaliases }) })?, MGI::UpdatePlayer { diff --git a/src/bin/otter.rs b/src/bin/otter.rs index a6da6273..0d36043c 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -687,9 +687,13 @@ mod reset_game { insns.extend(setup_table(&ma, &table_spec)?); } - for p in chan.list_pieces()? { + let (pcs, aliases) = chan.list_pieces()?; + for p in pcs { insns.push(MgmtGameInstruction::DeletePiece(p.piece)); } + for p in aliases { + insns.push(MgmtGameInstruction::DeletePieceAlias(p)); + } if let Some(table_size) = table_size { insns.push(MGI::SetTableSize(table_size)); @@ -1046,7 +1050,7 @@ mod library_add { let args = parse_args::(args, &subargs, &ok_id, None); let mut chan = access_game(&ma, &args.table_name)?; - let pieces = chan.list_pieces()?; + let (pieces, _pcaliases) = chan.list_pieces()?; let markers = pieces.iter().filter(|p| p.itemname == MAGIC) .collect::>(); diff --git a/src/commands.rs b/src/commands.rs index e10239d5..c5f7bc0d 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -117,7 +117,10 @@ pub enum MgmtGameResponse { Info(MgmtGameResponseGameInfo), Synch(Generation), - Pieces(Vec), + Pieces { + pieces: Vec, + pcaliases: BTreeSet, + }, JoinGame { nick: String, diff --git a/src/mgmtchannel.rs b/src/mgmtchannel.rs index 9a9bf45e..eac95917 100644 --- a/src/mgmtchannel.rs +++ b/src/mgmtchannel.rs @@ -180,11 +180,14 @@ impl MgmtChannelForGame { } #[throws(AE)] - pub fn list_pieces(&mut self) -> Vec { + pub fn list_pieces(&mut self) -> (Vec, BTreeSet) { let insns = vec![ MGI::ListPieces ]; let mut responses = self.alter_game(insns, None)?; match responses.as_mut_slice() { - [MGR::Pieces(pieces)] => return mem::take(pieces), + [MGR::Pieces { pieces, pcaliases }] => return ( + mem::take(pieces), + mem::take(pcaliases), + ), wat => Err(anyhow!("ListPieces => {:?}", &wat))?, } }