From: Ian Jackson Date: Fri, 6 Nov 2020 21:52:23 +0000 (+0000) Subject: wip new accounts X-Git-Tag: otter-0.2.0~556 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=6ac32cbe2361de443632f7f62928f2580bfe704d;p=otter.git wip new accounts Signed-off-by: Ian Jackson --- diff --git a/src/accounts.rs b/src/accounts.rs index ad4c563a..bf91e66b 100644 --- a/src/accounts.rs +++ b/src/accounts.rs @@ -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 { diff --git a/src/bin/otter.rs b/src/bin/otter.rs index 59600205..1788ed9c 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -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, }, - })); + }); } } diff --git a/src/spec.rs b/src/spec.rs index 4ca6e3fa..6b192e2a 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -60,8 +60,16 @@ display_as_debug!{SpecError} #[derive(Debug,Serialize,Deserialize)] pub struct TableSpec { - pub players : Vec, - pub acl : Acl + #[serde(default)] pub players: Vec, + #[serde(default)] pub acl: Acl, + pub timezone: Option, +} + +#[derive(Debug,Serialize,Deserialize)] +pub struct TablePlayerSpec { + account: AccountName, + nick: Option, + timezone: Option, } type RawAcl = Vec>;