From: Ian Jackson Date: Fri, 13 Nov 2020 22:58:26 +0000 (+0000) Subject: sort out Who X-Git-Tag: otter-0.2.0~519 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=8f59776873e432ff9f340ae17aa1d2bdc594fbd8;p=otter.git sort out Who Signed-off-by: Ian Jackson --- diff --git a/src/cmdlistener.rs b/src/cmdlistener.rs index 2f11c395..3e1bf341 100644 --- a/src/cmdlistener.rs +++ b/src/cmdlistener.rs @@ -40,19 +40,12 @@ pub struct CommandListener { listener : UnixListener, } -struct Who; -impl Display for Who { - #[throws(fmt::Error)] - fn fmt(&self, f: &mut Formatter) { write!(f, "The facilitator")? } -} - struct CommandStream<'d> { euid : Result, desc : &'d str, account : Option, superuser: Option, chan : MgmtChannel, - who: Who, } #[derive(Debug,Clone)] @@ -232,7 +225,7 @@ fn execute_game_insn<'cs, 'igr, 'ig : 'igr>( ag: &'_ mut AccountsGuard, ig: &'igr mut Unauthorised, InstanceName>, update: MgmtGameInstruction, - who: &impl Display) + who: &Html) -> Result ,ME> { type U = ExecuteGameChangeUpdates; @@ -369,7 +362,7 @@ fn execute_game_insn<'cs, 'igr, 'ig : 'igr>( let gpl = ig.gs.players.byid_mut(player)?; log.push(LogEntry { html: Html(format!("{} changed {}'s nick to {}", - &who, + &who.0, htmlescape::encode_minimal(&gpl.nick), htmlescape::encode_minimal(&new_nick))), }); @@ -484,7 +477,7 @@ fn execute_game_insn<'cs, 'igr, 'ig : 'igr>( (U{ pcs: updates, log: vec![ LogEntry { - html: Html(format!("{} added {} pieces", &who, count)), + html: Html(format!("{} added {} pieces", &who.0, count)), }], raw: None }, Fine, ig_g) @@ -506,7 +499,7 @@ fn execute_game_insn<'cs, 'igr, 'ig : 'igr>( } (U{ pcs: vec![ ], log: vec![ LogEntry { - html: Html(format!("{} cleared the log", &who)), + html: Html(format!("{} cleared the log", &who.0)), } ], raw: None }, Fine, ig) @@ -518,12 +511,12 @@ fn execute_game_insn<'cs, 'igr, 'ig : 'igr>( ig.acl = acl.into(); let mut log = vec![ LogEntry { html: Html(format!("{} set the table access control list", - &who)), + &who.0)), } ]; #[throws(InternalError)] fn remove_old_players(ag: &AccountsGuard, ig: &mut InstanceGuard, - who: &impl Display, log: &mut Vec) { + who: &Html, log: &mut Vec) { let owner_account = ig.name.account.to_string(); let eacl = EffectiveACL { owner_account: Some(&owner_account), @@ -554,7 +547,7 @@ fn execute_game_insn<'cs, 'igr, 'ig : 'igr>( "partial data?!".to_string() }; log.push(LogEntry { - html: Html(format!("{} removed a player {}", &who, &show)), + html: Html(format!("{} removed a player {}", &who.0, &show)), }); } } @@ -583,7 +576,20 @@ fn execute_for_game<'cs, 'igr, 'ig : 'igr>( let mut uh = UpdateHandler::from_how(how); let mut responses = Vec::with_capacity(insns.len()); let mut auth = None; - let who = Who; + let who = if_chain! { + let account = &cs.current_account()?.notional_account; + let ig = igu.by_ref(Authorisation::authorise_any()); + if let Ok((_, acctid)) = ag.lookup(account); + if let Some((player,_)) = ig.iplayers.iter() + .filter(|(_,ipr)| ipr.ipl.acctid == acctid) + .next(); + if let Some(gpl) = ig.gs.players.get(player); + then { Html(format!("{} [{}]", + &htmlescape::encode_minimal(&gpl.nick), + &account)) } + else { Html(format!("[{}]", + &account)) } + }; let res = (||{ for insn in insns.drain(0..) { let (updates, resp, ig) = execute_game_insn(cs, ag, igu, insn, &who)?; @@ -591,7 +597,7 @@ fn execute_for_game<'cs, 'igr, 'ig : 'igr>( responses.push(resp); auth = Some(Authorisation::authorised(&*ig.name)); } - if let Some(auth) = auth { uh.complete(cs, igu.by_mut(auth))?; } + if let Some(auth) = auth { uh.complete(igu.by_mut(auth), &who)?; } Ok(None) })(); if let Some(auth) = auth { @@ -664,7 +670,9 @@ impl UpdateHandler { } #[throws(SVGProcessingError)] - fn complete(self, cs: &CommandStream, g: &mut InstanceGuard) { + fn complete(self, + g: &mut InstanceGuard, + who: &Html) { use UpdateHandler::*; match self { Bulk(bulk) => { @@ -676,7 +684,7 @@ impl UpdateHandler { if bulk.logs { buf.log_updates(vec![LogEntry { - html: Html(format!("{} (re)configured the game", &cs.who)) + html: Html(format!("{} (re)configured the game", &who.0)) }]); } @@ -778,7 +786,6 @@ impl CommandListener { account: None, desc: &desc, chan, euid: euid.map(Uid::from_raw), superuser: None, - who: Who, }; cs.mainloop()?; diff --git a/src/commands.rs b/src/commands.rs index 83b712a0..b39df217 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -85,8 +85,6 @@ pub enum MgmtGameInstruction { // RemovePlayer { player: PlayerId }, todo, does a special setacl } -// xxx facilitator name? - #[derive(Debug,Serialize,Deserialize)] pub struct MgmtPlayerDetails { pub timezone: Option,