From: Ian Jackson Date: Sat, 3 Apr 2021 02:39:58 +0000 (+0100) Subject: updates: Send xupdates without by_client X-Git-Tag: otter-0.5.0~284 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=3ea77006e1d32b853155b93a977904839b2fcec6;p=otter.git updates: Send xupdates without by_client This was fundamentally wrong. Signed-off-by: Ian Jackson --- diff --git a/daemon/api.rs b/daemon/api.rs index 42f86e62..851f7738 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -165,11 +165,11 @@ fn api_piece_op(form: Json>) 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(form: Json>) 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(form: Json>) }); 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(); } diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index 4cab0716..3cb6d6d7 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -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 { diff --git a/src/clock.rs b/src/clock.rs index 945ae2dd..46d405ec 100644 --- a/src/clock.rs +++ b/src/clock.rs @@ -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)); })) } diff --git a/src/deck.rs b/src/deck.rs index 8b1f831f..ec0da91a 100644 --- a/src/deck.rs +++ b/src/deck.rs @@ -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)) } )) diff --git a/src/global.rs b/src/global.rs index c848bf50..1910b218 100644 --- a/src/global.rs +++ b/src/global.rs @@ -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(); diff --git a/src/hand.rs b/src/hand.rs index 8eb6b9e9..82777221 100644 --- a/src/hand.rs +++ b/src/hand.rs @@ -309,6 +309,6 @@ impl PieceTrait for Hand { (PieceUpdate { wrc, log, ops: PUOs::Simple(PUO::Modify(())), - }, xupdates.into_unprepared()) + }, xupdates.into_unprepared_nc()) } } diff --git a/src/updates.rs b/src/updates.rs index 263088c1..41cb4d27 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -529,7 +529,6 @@ impl PieceUpdateOp { pub struct PrepareUpdatesBuffer<'r> { g: &'r mut Instance, us: Vec, - by_client: IsResponseToClientOp, gen: Option, } @@ -554,15 +553,13 @@ pub enum WhatResponseToClientOp { } impl<'r> PrepareUpdatesBuffer<'r> { - pub fn new(g: &'r mut Instance, - by_client: IsResponseToClientOp, - estimate: Option) -> Self + pub fn new(g: &'r mut Instance, estimate: Option) -> 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) { - 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 - (&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(&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 :: ( - 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) })) } }