chiark / gitweb /
wip new accounts
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 6 Nov 2020 21:52:23 +0000 (21:52 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 6 Nov 2020 21:52:23 +0000 (21:52 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/accounts.rs
src/bin/otter.rs
src/spec.rs

index ad4c563a44a2b816c9ebe0186f3f5dea8a82e1d0..bf91e66b642708ec2cd9eabf34b8946ad60d4dfa 100644 (file)
@@ -104,6 +104,13 @@ impl AccountScope {
     }
     scope
   }
+
+  pub fn default_nick(&self) -> String {
+    match self {
+      AS::Server => "*SERVER*".into(),
+      AS::Unix { user } => user.clone(),
+    }
+  }
 }
 
 impl Display for AccountName {
index 59600205e5e3c1239403d3c5f8d52f663e4ef32a..1788ed9ce898cdc83913a97fbcf88f4776665cc4 100644 (file)
@@ -357,9 +357,10 @@ fn setup_table(ma: &MainOpts, chan: &mut ConnForGame,
 
     let mut insns = vec![];
     for pspec in &spec.players {
-      let st = nick2st.entry(pspec.nick.clone()).or_default();
+      let nick = pspec.unwrap_or(|| pspec.account.default_nick());
+      let st = nick2st.entry(nick.clone()).or_default();
       if st.new {
-        Err(anyhow!("duplicate player nick {:?} in spec", &pspec.nick))?;
+        Err(anyhow!("duplicate player nick {:?} in spec", &nick))?;
       }
       st.new = true;
       let timezone = pspec.timezone.as_ref().or(
@@ -367,12 +368,13 @@ fn setup_table(ma: &MainOpts, chan: &mut ConnForGame,
       ).cloned();
       // ^ todo use client program timezone?
       if !st.old {
-        insns.push(MgmtGameInstruction::AddPlayer(MgmtPlayerState {
-          timezone,
-          st: PlayerState {
-            nick: pspec.nick.clone(),
+        insns.push(MgmtGameInstruction::AddPlayer {
+          account,
+          MgmtPlayerDetails {
+            nick,
+            timezone,
           },
-        }));
+        });
       }
     }
 
index 4ca6e3fa21fee93e10d0d4b6ca1773a870e7cc08..6b192e2a3063d0e8512868be59a93bcdc21a25a6 100644 (file)
@@ -60,8 +60,16 @@ display_as_debug!{SpecError}
 
 #[derive(Debug,Serialize,Deserialize)]
 pub struct TableSpec {
-  pub players : Vec<AccountName>,
-  pub acl : Acl<TablePermission>
+  #[serde(default)] pub players: Vec<TablePlayerSpec>,
+  #[serde(default)] pub acl: Acl<TablePermission>,
+  pub timezone: Option<String>,
+}
+
+#[derive(Debug,Serialize,Deserialize)]
+pub struct TablePlayerSpec {
+  account: AccountName,
+  nick: Option<String>,
+  timezone: Option<String>,
 }
 
 type RawAcl<Perm> = Vec<AclEntry<Perm>>;