From: Ian Jackson Date: Sun, 15 Nov 2020 12:45:47 +0000 (+0000) Subject: wip join-game etc. X-Git-Tag: otter-0.2.0~510 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=bc077f85d2f38f339f58433ea8c792db9c6819a9;p=otter.git wip join-game etc. Signed-off-by: Ian Jackson --- diff --git a/src/bin/otter.rs b/src/bin/otter.rs index 9ea72f2d..1537481a 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -66,6 +66,8 @@ struct MainOpts { gaccount: AccountName, nick: Option, timezone: Option, + // xxx default to UrlOnStdout + // xxx options for others access: Option>, socket_path: String, verbose: i32, diff --git a/src/cmdlistener.rs b/src/cmdlistener.rs index 3e1bf341..ee74b66d 100644 --- a/src/cmdlistener.rs +++ b/src/cmdlistener.rs @@ -84,7 +84,7 @@ fn execute(cs: &mut CommandStream, cmd: MgmtCommand) -> MgmtResponse { Fine }, - CreateAccont(AccountDetails { account, nick, timezone, access }) => { + CreateAccount(AccountDetails { account, nick, timezone, access }) => { let mut ag = AccountsGuard::lock(); let auth = authorise_for_account(cs, &ag, &account)?; let access = cs.accountrecord_from_spec(access)? @@ -99,7 +99,7 @@ fn execute(cs: &mut CommandStream, cmd: MgmtCommand) -> MgmtResponse { Fine } - UpdateAccont(AccountDetails { account, nick, timezone, access }) => { + UpdateAccount(AccountDetails { account, nick, timezone, access }) => { let mut ag = AccountsGuard::lock(); let mut games = games_lock(); let auth = authorise_for_account(cs, &ag, &account)?; @@ -110,6 +110,13 @@ fn execute(cs: &mut CommandStream, cmd: MgmtCommand) -> MgmtResponse { } update_from(nick, &mut record.nick ); update_from(timezone, &mut record.timezone); +/* + xxx + if let Some(new_timezone) = timezone { + let ipr = ig.iplayers.byid_mut(player)?; + ipr.ipl.tz = tz_from_str(&new_timezone); + } +*/ Fine }) ? @@ -294,18 +301,20 @@ fn execute_game_insn<'cs, 'igr, 'ig : 'igr>( } Insn::JoinGame { - details: MgmtPlayerDetails { timezone, nick } + details: MgmtPlayerDetails { nick } } => { let account = &cs.current_account()?.notional_account; - let (_arecord, acctid) = ag.lookup(account)?; + let (arecord, acctid) = ag.lookup(account)?; let (ig, auth) = cs.check_acl(ag, ig, PCH::Instance, &[TP::Play])?; let nick = nick.ok_or(ME::ParameterMissing)?; let logentry = LogEntry { html: Html(format!("{} ({}) joined the game", &nick, &account)), }; - let timezone = timezone.as_ref().map(String::as_str) - .unwrap_or(""); + let timezone = &arecord.timezone +/*.as_ref().map(String::as_str) + .unwrap_or("");*/ +; let tz = tz_from_str(&timezone); let gpl = GPlayerState { nick: nick.to_string(), @@ -352,7 +361,7 @@ fn execute_game_insn<'cs, 'igr, 'ig : 'igr>( UpdatePlayer { player, - details: MgmtPlayerDetails { nick, timezone }, + details: MgmtPlayerDetails { nick }, } => { let ig = cs.check_acl_modify_player(ag, ig, player, &[TP::ModifyOtherPlayer])?.0; @@ -368,10 +377,6 @@ fn execute_game_insn<'cs, 'igr, 'ig : 'igr>( }); gpl.nick = new_nick; } - if let Some(new_timezone) = timezone { - let ipr = ig.iplayers.byid_mut(player)?; - ipr.ipl.tz = tz_from_str(&new_timezone); - } (U{ log, pcs: vec![], raw: None}, diff --git a/src/commands.rs b/src/commands.rs index c8cec692..21756ecd 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -9,8 +9,8 @@ pub enum MgmtCommand { Noop, SetSuperuser(bool), - CreateAccont(AccountDetails), - UpdateAccont(AccountDetails), + CreateAccount(AccountDetails), + UpdateAccount(AccountDetails), DeleteAccount(AccountName), SelectAccount(AccountName), // success does not mean account exists @@ -106,9 +106,10 @@ pub enum MgmtGameResponse { } #[derive(Debug,Clone,Serialize,Deserialize)] -pub struct AccessTokenReport { - lines: Vec, -} +pub struct AccessTokenInfo { pub url: String } + +#[derive(Debug,Clone,Serialize,Deserialize)] +pub struct AccessTokenReport { pub lines: Vec } #[derive(Debug,Clone,Serialize,Deserialize)] pub struct MgmtGameResponseGameInfo { @@ -185,3 +186,12 @@ impl From for MgmtError { MgmtError::ServerFailure(format!("ServerFailure {}\n", &e)) } } + +impl AccessTokenInfo { + pub fn report(self) -> Vec { + vec![ + "Game access url:".to_string(), + self.url, + ] + } +} diff --git a/src/global.rs b/src/global.rs index 8bf880a1..1fda6547 100644 --- a/src/global.rs +++ b/src/global.rs @@ -645,7 +645,7 @@ impl<'ig> InstanceGuard<'ig> { player: PlayerId, _auth: Authorisation, reset: bool) - -> Option { + -> AccessTokenReport { let acctid = self.iplayers.byid(player)?.ipl.acctid; let access = { @@ -722,10 +722,9 @@ impl<'ig> InstanceGuard<'ig> { let url = format!("{}/{}", &config().public_url.trim_start_matches("/"), token.0); - let report = AccessTokenReport { url }; - let report = access - .server_deliver(&gpl, &ipl, &report)?; - report.cloned() + let info = AccessTokenInfo { url }; + let report = access.deliver(&gpl, &ipl, info)?; + report } #[throws(MgmtError)] @@ -733,7 +732,7 @@ impl<'ig> InstanceGuard<'ig> { accounts: &mut AccountsGuard, player: PlayerId, auth: Authorisation) - -> Option { + -> AccessTokenReport { self.player_access_reset_redeliver(accounts, player, auth, true)? } @@ -742,7 +741,7 @@ impl<'ig> InstanceGuard<'ig> { accounts: &mut AccountsGuard, player: PlayerId, auth: Authorisation) - -> Option { + -> AccessTokenReport { self.player_access_reset_redeliver(accounts, player, auth, false)? } diff --git a/src/spec.rs b/src/spec.rs index d61b2e68..8b40bdcd 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -321,19 +321,11 @@ pub mod implementation { #[throws(MgmtError)] fn check_spec_permission(&self, _: Option) { } - fn server_deliver<'t>(&self, - _gpl: &GPlayerState, - _ipl: &IPlayerState, - _token: &'t AccessTokenReport) - -> Result, TDE> { - Ok(None) - } - fn client_deliver(&self, - _pi: &MgmtPlayerInfo, - _token: &AccessTokenReport) - -> Result<(), TDE> { - panic!() - } + fn deliver(&self, + gpl: &GPlayerState, + ipl: &IPlayerState, + token: AccessTokenInfo) + -> Result; fn describe_html(&self) -> Html { let inner = Html::from_txt(&format!("{:?}", self)); Html(format!("{}", inner.0)) @@ -342,6 +334,16 @@ pub mod implementation { #[typetag::serde] impl PlayerAccessSpec for PlayerAccessUnset { + #[throws(TokenDeliveryError)] + fn deliver(&self, + _gpl: &GPlayerState, + _ipl: &IPlayerState, + _token: AccessTokenInfo) -> AccessTokenReport { + AccessTokenReport { lines: vec![ + "Player access not set, game not accessible to this player" + .to_string(), + ] } + } } #[typetag::serde] @@ -353,24 +355,24 @@ pub mod implementation { fn override_token(&self) -> Option<&RawToken> { Some(&self.token) } + #[throws(TokenDeliveryError)] + fn deliver(&self, + _gpl: &GPlayerState, + _ipl: &IPlayerState, + _token: AccessTokenInfo) -> AccessTokenReport { + AccessTokenReport { lines: vec![ "Fixed access token".to_string() ] } + } } #[typetag::serde] impl PlayerAccessSpec for UrlOnStdout { #[throws(TDE)] - fn server_deliver<'t>(&self, - _gpl: &GPlayerState, - _ipl: &IPlayerState, - token: &'t AccessTokenReport) - -> Option<&'t AccessTokenReport> { - Some(token) - } - #[throws(TDE)] - fn client_deliver(&self, - pi: &MgmtPlayerInfo, - token: &AccessTokenReport) { - println!("access account={} nick={:?} url:\n{}", - &pi.account, &pi.nick, token.url); + fn deliver<'t>(&self, + _gpl: &GPlayerState, + _ipl: &IPlayerState, + token: AccessTokenInfo) + -> AccessTokenReport { + AccessTokenReport { lines: token.report() } } }