chiark / gitweb /
wip join-game etc.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 15 Nov 2020 12:45:47 +0000 (12:45 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 15 Nov 2020 12:45:47 +0000 (12:45 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/otter.rs
src/cmdlistener.rs
src/commands.rs
src/global.rs
src/spec.rs

index 9ea72f2d31de22ebbfa370b7538a7d6d5a6c16b9..1537481a9bf6ad09ee2aa5bb0f896247c6cad875 100644 (file)
@@ -66,6 +66,8 @@ struct MainOpts {
   gaccount: AccountName,
   nick: Option<String>,
   timezone: Option<String>,
+  // xxx default to UrlOnStdout
+  // xxx options for others
   access: Option<Box<dyn PlayerAccessSpec>>,
   socket_path: String,
   verbose: i32,
index 3e1bf34149b549d285bbeb3f61dcd80be02c2039..ee74b66d065618a3437d8b85f861e24d90d026a9 100644 (file)
@@ -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},
index c8cec6929eba551ea1ad488cb3ccce082cecb3cb..21756ecdf195b96f9c572f16e402075a52068f6e 100644 (file)
@@ -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<String>,
-}
+pub struct AccessTokenInfo { pub url: String }
+
+#[derive(Debug,Clone,Serialize,Deserialize)]
+pub struct AccessTokenReport { pub lines: Vec<String> }
 
 #[derive(Debug,Clone,Serialize,Deserialize)]
 pub struct MgmtGameResponseGameInfo {
@@ -185,3 +186,12 @@ impl From<InternalError> for MgmtError {
     MgmtError::ServerFailure(format!("ServerFailure {}\n", &e))
   }
 }
+
+impl AccessTokenInfo {
+  pub fn report(self) -> Vec<String> {
+    vec![
+      "Game access url:".to_string(),
+      self.url,
+    ]
+  }
+}
index 8bf880a1828882ed5684aacec7162e3a1df1d504..1fda65470c135a147463e6f049d858b93db0d90e 100644 (file)
@@ -645,7 +645,7 @@ impl<'ig> InstanceGuard<'ig> {
                                    player: PlayerId,
                                    _auth: Authorisation<AccountName>,
                                    reset: bool)
-                                   -> Option<AccessTokenReport> {
+                                   -> 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<AccountName>)
-                             -> Option<AccessTokenReport> {
+                             -> 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<AccountName>)
-                                 -> Option<AccessTokenReport> {
+                                 -> AccessTokenReport {
     self.player_access_reset_redeliver(accounts, player, auth, false)?
   }
 
index d61b2e68b1fd26b5f93a9f16d826083e2534f537..8b40bdcd542a0773ab2af6e8dd3c2ee6d13e73a1 100644 (file)
@@ -321,19 +321,11 @@ pub mod implementation {
     #[throws(MgmtError)]
     fn check_spec_permission(&self, _: Option<AuthorisationSuperuser>) {
     }
-    fn server_deliver<'t>(&self,
-                          _gpl: &GPlayerState,
-                          _ipl: &IPlayerState,
-                          _token: &'t AccessTokenReport)
-                          -> Result<Option<&'t AccessTokenReport>, TDE> {
-      Ok(None)
-    }
-    fn client_deliver(&self,
-                      _pi: &MgmtPlayerInfo,
-                      _token: &AccessTokenReport)
-                      -> Result<(), TDE> {
-      panic!()
-    }
+    fn deliver(&self,
+               gpl: &GPlayerState,
+               ipl: &IPlayerState,
+               token: AccessTokenInfo)
+               -> Result<AccessTokenReport, TDE>;
     fn describe_html(&self) -> Html {
       let inner = Html::from_txt(&format!("{:?}", self));
       Html(format!("<code>{}</code>", 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() }
     }
   }