From: Ian Jackson Date: Fri, 23 Oct 2020 20:36:12 +0000 (+0100) Subject: wip new account etc., just starting new ig from exec X-Git-Tag: otter-0.2.0~608 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=9c650acdcfd4b1c78a81e69f3b99f3f533801bb0;p=otter.git wip new account etc., just starting new ig from exec Signed-off-by: Ian Jackson --- diff --git a/src/cmdlistener.rs b/src/cmdlistener.rs index c0fa3849..6bbd367b 100644 --- a/src/cmdlistener.rs +++ b/src/cmdlistener.rs @@ -149,7 +149,8 @@ fn execute(cs: &mut CommandStream, cmd: MgmtCommand) -> MgmtResponse { // ---------- game command implementations ---------- -type ExecuteGameInsnResults = ( +type ExecuteGameInsnResults<'r> = ( + &'r mut InstanceGuard, ExecuteGameChangeUpdates, MgmtGameResponse, ); @@ -166,17 +167,18 @@ fn execute_game_insn(cs: &CommandStream, type Resp = MgmtGameResponse; let who = &cs.who; + #[throws(MgmtError)] fn readonly MgmtGameResponse, P: Into>> ( cs: &CommandStream, - ig: &Unauthorised, + ig: &mut Unauthorised, p: P, f: F ) -> ExecuteGameInsnResults { - let ig = cs.check_acl(ig, PCH::InstanceOnly, p)?; + let (ig, _) = cs.check_acl(ig, PCH::Instance, p)?; let resp = f(ig); (U{ pcs: vec![], log: vec![], raw: None }, resp) } @@ -193,13 +195,14 @@ fn execute_game_insn(cs: &CommandStream, PCH::InstanceOrOnlyAffectedPlayer(player), &[perm])?; fn auth_map(n: &InstanceName) -> &AccountName { &n.account } - let auth = auth.map(&auth_map); +// let auth_map = |n: &InstanceName| -> &AccountName { &n.account }; + let auth = auth.map(auth_map); (ig, auth) } } let y = match update { - Noop { } => readonly(cs,ig, &[], |ig| Fine), + Noop { } => readonly(cs,ig, &[], |ig| Fine)?, Insn::SetTableSize(size) => { let ig = cs.check_acl(ig, PCH::Instance, &[TP::ChangePieces])?.0; @@ -261,7 +264,7 @@ fn execute_game_insn(cs: &CommandStream, }) }).flatten().collect(); Resp::Pieces(pieces) - }), + })?, RemovePlayer(account) => { // todo let you remove yourself unconditionally @@ -301,7 +304,7 @@ fn execute_game_insn(cs: &CommandStream, let table_size = ig.gs.table_size; let info = MgmtGameResponseGameInfo { table_size, players }; Resp::Info(info) - }), + })?, ResetPlayerAccess(player) => { let (ig, auth) = cs.check_acl_manip_player_access @@ -840,17 +843,17 @@ mod authproofs { pub struct Authorisation (PhantomData); impl Authorisation { - pub const fn authorise_any() -> Authorisation { - Authorisation(PhantomData) - } pub const fn authorised(v: &T) -> Authorisation { Authorisation(PhantomData) } + pub fn map(self, f: fn(&T) -> &U) -> Authorisation { + self.therefore_ok() + } pub fn therefore_ok(self) -> Authorisation { Authorisation(PhantomData) } - - pub fn map(self, f: &fn(&T) -> &U) -> Authorisation { + pub const fn authorise_any() -> Authorisation { + Authorisation(PhantomData) } }