From: Ian Jackson Date: Sun, 14 Mar 2021 23:17:43 +0000 (+0000) Subject: cmdlistener: Allow game insns access to a PrepareUpdatesBuffer X-Git-Tag: otter-0.4.0~44 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=b79dfc32d26bcfe8bf7192777943133af9429dc8;p=otter.git cmdlistener: Allow game insns access to a PrepareUpdatesBuffer Signed-off-by: Ian Jackson --- diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index ed7aba55..8985ee61 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -227,10 +227,14 @@ fn execute(cs: &mut CommandStream, cmd: MgmtCommand) -> MgmtResponse { // ---------- game command implementations ---------- +type ExecuteGameInsnResultsPrepub = Box< + dyn for<'r> FnOnce(&'r mut PrepareUpdatesBuffer) + >; + type ExecuteGameInsnResults<'igr, 'ig> = ( ExecuteGameChangeUpdates, MgmtGameResponse, - Option, + Option, // These happena after everything else &'igr mut InstanceGuard<'ig>, ); @@ -780,12 +784,19 @@ fn execute_for_game<'cs, 'igr, 'ig: 'igr>( let res = (||{ for insn in insns.drain(0..) { let (updates, resp, for_prepub, ig) = - execute_game_insn(cs, ag, igu, insn, &who, &mut to_permute)?; + execute_game_insn(cs, ag, igu, insn, &who, + &mut to_permute)?; uh.accumulate(ig, updates)?; responses.push(resp); - match for_prepub { None => (), Some(x) => match x { }}; let auth_y = Authorisation::authorised(&*ig.name); auth = Some(auth_y); + if let Some(for_prepub) = for_prepub { + uh.complete(ig, &who)?; + let mut prepub = PrepareUpdatesBuffer::new(ig, None, None); + for_prepub(&mut prepub); + prepub.finish(); + uh = UpdateHandler::from_how(how); + } } if let Some(auth) = auth { uh.complete(igu.by_mut(auth), &who)?; } Ok(None)