chiark / gitweb /
updates: Send xupdates without by_client
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 3 Apr 2021 02:39:58 +0000 (03:39 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 3 Apr 2021 02:40:12 +0000 (03:40 +0100)
This was fundamentally wrong.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/api.rs
daemon/cmdlistener.rs
src/clock.rs
src/deck.rs
src/global.rs
src/hand.rs
src/updates.rs

index 42f86e625ca954279ec62f242ff67be1d38a5cc3..851f77380cba6752a3343bda2dec5f0e482b5025 100644 (file)
@@ -165,11 +165,11 @@ fn api_piece_op<O: op::Complex>(form: Json<ApiPiece<O>>)
       Err(err)?;
     },
     Ok((PieceUpdate { wrc, log, ops }, unprepared)) => {
+      let by_client = Some((wrc, client, form.cseq));
       let mut buf = PrepareUpdatesBuffer::new(g,
-                                              Some((wrc, client, form.cseq)),
                                               Some(1 + log.len()));
 
-      buf.piece_update(piece, ops);
+      buf.piece_update(piece, &by_client, ops);
       buf.log_updates(log);
       if let Some(unprepared) = unprepared { unprepared(&mut buf); }
 
@@ -192,7 +192,7 @@ fn api_piece_op<O: op::Complex>(form: Json<ApiPiece<O>>)
     then { unprepared }
     else { None }
   } {
-    let mut prepub = PrepareUpdatesBuffer::new(&mut ig, None, None);
+    let mut prepub = PrepareUpdatesBuffer::new(&mut ig, None);
     unprepared(&mut prepub);
     prepub.finish();
   }
@@ -210,7 +210,7 @@ fn api_piece_op<O: op::Complex>(form: Json<ApiPiece<O>>)
   });
 
   if let Some(unprepared) = unprepared_outer {
-    let mut prepub = PrepareUpdatesBuffer::new(&mut ig, None, None);
+    let mut prepub = PrepareUpdatesBuffer::new(&mut ig, None);
     unprepared(&mut prepub);
     prepub.finish();
   }
index 4cab0716d324ac400565cfcddb1ac8fe5e37c293..3cb6d6d7f676ac22c3d22c7d2ab73f9691b7744e 100644 (file)
@@ -416,7 +416,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
 
     MGI::Synch => {
       let (mut ig, _) = cs.check_acl(&ag, ig, PCH::Instance, &[TP::Play])?;
-      let mut buf = PrepareUpdatesBuffer::new(&mut ig, None, None);
+      let mut buf = PrepareUpdatesBuffer::new(&mut ig, None);
       let gen = buf.gen();
       drop(buf); // does updatenocc
       (U{ pcs: vec![], // we handled the update ourselves,
@@ -667,7 +667,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
        if xupdates.len() != 0 {
          Some(
            Box::new(move |prepub: &mut PrepareUpdatesBuffer|
-                    prepub.piece_updates(xupdates))
+                    prepub.piece_updates_nc(xupdates))
              as SomeUnpreparedUpdates
          )
        } else { None },
@@ -920,7 +920,7 @@ fn execute_for_game<'cs, 'igr, 'ig: 'igr>(
       responses.push(resp);
       if let Some(unprepared) = unprepared {
         st.flush(ig,how,&who)?;
-        let mut prepub = PrepareUpdatesBuffer::new(ig, None, None);
+        let mut prepub = PrepareUpdatesBuffer::new(ig, None);
         unprepared(&mut prepub);
         prepub.finish();
       }
@@ -953,7 +953,7 @@ fn execute_for_game<'cs, 'igr, 'ig: 'igr>(
 
   if let Some(uu) = uu {
     let mut ig = igu.by_mut(Authorisation::authorise_any());
-    let mut prepub = PrepareUpdatesBuffer::new(&mut ig, None, None);
+    let mut prepub = PrepareUpdatesBuffer::new(&mut ig, None);
     uu(&mut prepub);
     prepub.finish();
   }
@@ -1011,9 +1011,9 @@ impl UpdateHandler {
       }
       Online => {
         let estimate = updates.pcs.len() + updates.log.len();
-        let mut buf = PrepareUpdatesBuffer::new(g, None, Some(estimate));
+        let mut buf = PrepareUpdatesBuffer::new(g, Some(estimate));
         for (upiece, uuop) in updates.pcs {
-          buf.piece_update(upiece, PUOs::Simple(uuop));
+          buf.piece_update(upiece, &None, PUOs::Simple(uuop));
         }
         buf.log_updates(updates.log);
         buf.raw_updates(raw);
@@ -1026,9 +1026,9 @@ impl UpdateHandler {
     use UpdateHandler::*;
     match self {
       Bulk(bulk) => {
-        let mut buf = PrepareUpdatesBuffer::new(g, None, None);
+        let mut buf = PrepareUpdatesBuffer::new(g, None);
         for (upiece, uuop) in bulk.pieces {
-          buf.piece_update(upiece, PUOs::Simple(uuop));
+          buf.piece_update(upiece, &None, PUOs::Simple(uuop));
         }
 
         if bulk.logs {
index 945ae2ddeca15358c75a8bba48b039b404c17c92..46d405ecdbd8b395bfd4d4b85030d706cb6c6612 100644 (file)
@@ -396,7 +396,7 @@ const OUTLINE: RectShape = RectShape { xy: PosC::new(W as f64, H as f64) };
 
 fn unprepared_update(piece: PieceId) -> UnpreparedUpdates {
   Some(Box::new(move |buf: &mut PrepareUpdatesBuffer| {
-    buf.piece_update_image(piece)
+    buf.piece_update_image(piece, &None)
       .unwrap_or_else(|e| error!("failed to prep clock: {:?}", e));
   }))
 }
index 8b1f831f0d883904c8a52eb0a2cd1b53fe4a4731..ec0da91a831dc357fc7c6c929232030c1b1f0354 100644 (file)
@@ -230,13 +230,13 @@ impl PieceTrait for Deck {
       wrc, log,
       ops: PUOs::Simple(PUO::Modify(())),
     },
-     xupdates.into_unprepared())
+     xupdates.into_unprepared_nc())
   }
 
   fn occultation_notify_hook(&self, piece: PieceId) -> UnpreparedUpdates {
     Some(Box::new(
       move |updates: &mut PrepareUpdatesBuffer| {
-        updates.piece_update_image(piece)
+        updates.piece_update_image(piece, &None)
           .unwrap_or_else(|e| error!("unable to send update! {:?}", e))
       }
     ))
index c848bf50f94fe1b3967cc9d05ec6d4667b994269..1910b2183a8afb28a8bf3bcfa2c67b06f8b971ea 100644 (file)
@@ -726,9 +726,9 @@ impl<'ig> InstanceGuard<'ig> {
       }
 
       let estimate = updated_pieces.len() + 1;
-      let mut buf = PrepareUpdatesBuffer::new(self, None , Some(estimate));
+      let mut buf = PrepareUpdatesBuffer::new(self, Some(estimate));
       for &piece in &updated_pieces {
-        buf.piece_update(piece, PieceUpdateOp::Modify(()).into());
+        buf.piece_update(piece, &None, PieceUpdateOp::Modify(()).into());
       }
       buf.finish();
 
index 8eb6b9e900c51633c5fa261dc5ca3f51970a6da9..827772219a3387ccb24ccfb4e6daff7f4dbbec75 100644 (file)
@@ -309,6 +309,6 @@ impl PieceTrait for Hand {
     (PieceUpdate {
       wrc, log,
       ops: PUOs::Simple(PUO::Modify(())),
-    }, xupdates.into_unprepared())
+    }, xupdates.into_unprepared_nc())
   }
 }
index 263088c16be7fcb1cc55e96a8e8c7e67154c7cd6..41cb4d2709fbc204ec9a1681a792b52e072a9c1a 100644 (file)
@@ -529,7 +529,6 @@ impl<NS,ZC> PieceUpdateOp<NS,ZC> {
 pub struct PrepareUpdatesBuffer<'r> {
   g: &'r mut Instance,
   us: Vec<PreparedUpdateEntry>,
-  by_client: IsResponseToClientOp,
   gen: Option<Generation>,
 }
 
@@ -554,15 +553,13 @@ pub enum WhatResponseToClientOp {
 }
 
 impl<'r> PrepareUpdatesBuffer<'r> {
-  pub fn new(g: &'r mut Instance,
-             by_client: IsResponseToClientOp,
-             estimate: Option<usize>) -> Self
+  pub fn new(g: &'r mut Instance, estimate: Option<usize>) -> Self
   {
     let us = estimate.map_or(vec![], Vec::with_capacity);
 
     PrepareUpdatesBuffer {
       gen: None,
-      by_client, us, g,
+      us, g,
     }
   }
 
@@ -571,8 +568,8 @@ impl<'r> PrepareUpdatesBuffer<'r> {
                            piece: PieceId,
                            estimate: Option<usize>)
   {
-    let mut updates = PrepareUpdatesBuffer::new(g, None, estimate);
-    updates.piece_update_image(piece)?;
+    let mut updates = PrepareUpdatesBuffer::new(g, estimate);
+    updates.piece_update_image(piece, &None)?;
     updates.finish();
   }
 
@@ -591,10 +588,10 @@ impl<'r> PrepareUpdatesBuffer<'r> {
                             client: ClientId, cseq: ClientSequence)
                             -> Result<(),OE> {
     let by_client = (WRC::Unpredictable, client, cseq);
-    let mut buf = PrepareUpdatesBuffer::new(ig, Some(by_client), None);
+    let mut buf = PrepareUpdatesBuffer::new(ig, None);
     let ops = PUOs::Simple(PieceUpdateOp::Modify(()));
     let state = buf.piece_update_fallible(
-      piece, ops, |pc, gen, _by_client| {
+      piece, &Some(by_client), ops, |pc, gen, _by_client| {
         match partially {
           POEPP::Unprocessed => { }
           POEPP::Partially => { pc.gen = gen; pc.lastclient = default(); }
@@ -631,7 +628,8 @@ impl<'r> PrepareUpdatesBuffer<'r> {
 
   #[throws(InternalError)]
   fn piece_update_fallible_players<U,GUF,WMZ,MUF,MPF>
-    (&mut self, piece: PieceId, gen_update: GUF,
+    (&mut self, piece: PieceId, by_client: &IsResponseToClientOp,
+     gen_update: GUF,
      mut with_max_z: WMZ,
      mut mk_update: MUF,
      mut missing: MPF,
@@ -653,7 +651,7 @@ impl<'r> PrepareUpdatesBuffer<'r> {
     let ipc = self.g.ipieces.get(piece);
 
     if let Some(ref mut gpc) = gpc {
-      gen_update(gpc, gen, &self.by_client);
+      gen_update(gpc, gen, by_client);
     }
     let gpc = gs.pieces.byid(piece).ok();
 
@@ -687,6 +685,7 @@ impl<'r> PrepareUpdatesBuffer<'r> {
 
   #[throws(InternalError)]
   fn piece_update_fallible<GUF>(&mut self, piece: PieceId,
+                                by_client: &IsResponseToClientOp,
                                 ops: PieceUpdateOps,
                                 gen_update: GUF)
                                 -> PreparedUpdateEntry_Piece
@@ -695,7 +694,7 @@ impl<'r> PrepareUpdatesBuffer<'r> {
     let ops = self.piece_update_fallible_players
       ::<PreparedPieceUpdate,_,_,_,_>
     (
-      piece, gen_update,
+      piece,by_client, gen_update,
 
       |max_z, gpc| max_z.update_max(&gpc.zlevel.z),
 
@@ -723,17 +722,19 @@ impl<'r> PrepareUpdatesBuffer<'r> {
     )?;
 
     PreparedUpdateEntry_Piece {
-      by_client: self.by_client,
+      by_client: by_client.clone(),
       ops
     }
   }
 
-  pub fn piece_update(&mut self, piece: PieceId, ops: PieceUpdateOps) {
+  pub fn piece_update(&mut self, piece: PieceId,
+                      by_client: &IsResponseToClientOp,
+                      ops: PieceUpdateOps) {
     // Caller needs us to be infallible since it is too late by
     // this point to back out a game state change.
 
     let update = self.piece_update_fallible(
-      piece, ops,
+      piece,by_client, ops,
       |pc, gen, by_client|
     {
       match *by_client {
@@ -765,11 +766,12 @@ impl<'r> PrepareUpdatesBuffer<'r> {
   }
 
   #[throws(InternalError)]
-  pub fn piece_update_image(&mut self, piece: PieceId) {
+  pub fn piece_update_image(&mut self, piece: PieceId,
+                            by_client: &IsResponseToClientOp) {
     // Use this only for updates which do not change the set of valid UOs
     // or other operations or move the piece etc.
     let ims = self.piece_update_fallible_players(
-      piece, |_,_,_|(), |_,_|(),
+      piece,by_client, |_,_,_|(), |_,_|(),
 
       |ioccults,gs,gpc,ipc,_player,pri| {
         let im = pri.as_ref().map(|pri| {
@@ -784,9 +786,9 @@ impl<'r> PrepareUpdatesBuffer<'r> {
     self.us.push(PUE::Image(PreparedUpdateEntry_Image { ims }))
   }
 
-  pub fn piece_updates(&mut self, updates: Vec<(PieceId, PieceUpdateOps)>) {
+  pub fn piece_updates_nc(&mut self, updates: Vec<(PieceId, PieceUpdateOps)>) {
     for (piece, ops) in updates {
-      self.piece_update(piece, ops);
+      self.piece_update(piece,&None, ops);
     }
   }
 
@@ -967,10 +969,10 @@ impl PreparedUpdate {
 
 #[ext(pub)]
 impl Vec<(PieceId, PieceUpdateOps)> {
-  fn into_unprepared(self) -> UnpreparedUpdates {
+  fn into_unprepared_nc(self) -> UnpreparedUpdates {
     Some(Box::new(
       move |buf: &mut PrepareUpdatesBuffer| {
-        buf.piece_updates(self)
+        buf.piece_updates_nc(self)
       }))
   }
 }