chiark / gitweb /
commands etc.: Delete old aliases when resetting the game
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 25 Mar 2021 18:44:05 +0000 (18:44 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 25 Mar 2021 19:20:16 +0000 (19:20 +0000)
 * 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 <ijackson@chiark.greenend.org.uk>
daemon/cmdlistener.rs
src/bin/otter.rs
src/commands.rs
src/mgmtchannel.rs

index 9d27589003d7fd34266c073ce18e2166e3fb000a..5fa1bda73ac2f9ad89fef130c2b1918be2ac692e 100644 (file)
@@ -435,7 +435,8 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
           }
         }))().transpose()
       ).collect::<Result<Vec<_>,_>>()?;
-      Ok(MGR::Pieces(pieces))
+      let pcaliases = ig.pcaliases.keys().cloned().collect();
+      Ok(MGR::Pieces { pieces, pcaliases })
     })?,
 
     MGI::UpdatePlayer {
index a6da62739f23589662de13e69ceb1b076ca75522..0d36043cbac99c2bfc91b3579512cfb9b841d630 100644 (file)
@@ -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,_>(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::<Vec<_>>();
 
index e10239d5b4f6a61289e99ffe5a45ccb65c457703..c5f7bc0da817fb59fe615f6d2fa910186fea8ec7 100644 (file)
@@ -117,7 +117,10 @@ pub enum MgmtGameResponse {
   Info(MgmtGameResponseGameInfo),
   Synch(Generation),
 
-  Pieces(Vec<MgmtGamePieceInfo>),
+  Pieces {
+    pieces: Vec<MgmtGamePieceInfo>,
+    pcaliases: BTreeSet<String>,
+  },
 
   JoinGame {
     nick: String,
index 9a9bf45ea47bd2dfbc948f749e8999bcea7f3d3f..eac95917d15a6f49cf85dd402d7e11f96f2f79a5 100644 (file)
@@ -180,11 +180,14 @@ impl MgmtChannelForGame {
   }
 
   #[throws(AE)]
-  pub fn list_pieces(&mut self) -> Vec<MgmtGamePieceInfo> {
+  pub fn list_pieces(&mut self) -> (Vec<MgmtGamePieceInfo>, BTreeSet<String>) {
     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))?,
     }
   }