From ef4f845885198a6720708595f1b9929b8170975a Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 17 Oct 2020 18:00:48 +0100 Subject: [PATCH] new command api etc. Signed-off-by: Ian Jackson --- src/cmdlistener.rs | 1 + src/commands.rs | 75 ++++++++++++++++++++++++++++++++++++++-------- src/global.rs | 1 + src/spec.rs | 29 ++++++++++-------- 4 files changed, 81 insertions(+), 25 deletions(-) diff --git a/src/cmdlistener.rs b/src/cmdlistener.rs index 39370b23..bffcb9c5 100644 --- a/src/cmdlistener.rs +++ b/src/cmdlistener.rs @@ -182,6 +182,7 @@ fn execute_game_insn(cs: &CommandStream, }, Insn::ListPieces => readonly(ig, { + // xxx put something in log let pieces = ig.gs.pieces.iter().map(|(piece,p)|{ let &PieceState { pos, face, .. } = p; let pinfo = ig.pieces.get(piece)?; diff --git a/src/commands.rs b/src/commands.rs index 6a81118d..6666c82b 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -7,19 +7,62 @@ use crate::imports::*; #[derive(Debug,Serialize,Deserialize)] pub enum MgmtCommand { Noop, - SetScope(AccountScope), - CreateGame { name: String, insns: Vec }, - ListGames { all: Option, }, + + CreateAccont(AccountDetails), + UpdateAccont(AccountDetails), + DeleteAccount(AccountDetails), + + SetAccount(ScopedName), + + CreateGame { + game: ScopedName, + insns: Vec, + }, + ListGames { + all: Option, // in same scope by default + }, AlterGame { - // todo option scope, access control - name: String, insns: Vec, + game: ScopedName, + insns: Vec, how: MgmtGameUpdateMode, }, + LibraryListByGlob { glob: shapelib::ItemSpec, }, } +//---------- Accounts file ---------- + +#[derive(Debug,Serialize,Deserialize)] +pub struct AccountDetails { + pub account: ScopedName, + pub nick: String, + pub timezone: Option, + #[serde(flatten)] + pub access: Option>, +// pub invite: Acl, todo +} + +//#[derive(Debug,Clone,Copy,Serialize,Deserialize)] +//enum AccountPerm { +// InviteToGame, +// GameRunnerResetToken, +//} + +#[derive(Debug,Serialize,Deserialize)] +struct FixedToken { token: RawToken } + +#[derive(Debug,Serialize,Deserialize)] +struct TokenOnStdout; + +//#[derive(Debug,Serialize,Deserialize)] +//struct TokenByEmail { email: String }; +// xxx ^ implement this +// xxx ^ + + + #[derive(Debug,Serialize,Deserialize)] pub enum MgmtResponse { Fine, @@ -39,21 +82,23 @@ pub enum MgmtGameInstruction { AddPieces(PiecesSpec), DeletePiece(PieceId), - AddPlayer(MgmtPlayerState), - RemovePlayer(PlayerId), ResetPlayerAccesses { players: Vec }, ReportPlayerAccesses { players: Vec }, SetFixedPlayerAccess { player: PlayerId, token: RawToken }, + + AddPlayer(MgmtPlayerDetails), + UpdatePlayer(MgmtPlayerDetails), + RemovePlayer(ScopedName), + BlockPlayer(String), } -// xxx self-add players -// xxx permission system // xxx facilitator name? #[derive(Debug,Serialize,Deserialize)] -pub struct MgmtPlayerState { +pub struct MgmtPlayerDetails { + pub account: ScopedName, pub timezone: Option, - #[serde(flatten)] pub st: PlayerState, + pub nick: Option, } #[derive(Debug,Serialize,Deserialize)] @@ -70,7 +115,13 @@ pub enum MgmtGameResponse { #[derive(Debug,Clone,Serialize,Deserialize)] pub struct MgmtGameResponseGameInfo { pub table_size: Pos, - pub players: PlayerMap, + pub players: DenseSlotMap, +} + +#[derive(Debug,Clone,Serialize,Deserialize)] +pub struct MgmtPlayerInfo { + pub account: ScopedName, + pub nick: String, } #[derive(Debug,Clone,Serialize,Deserialize)] diff --git a/src/global.rs b/src/global.rs index 676888f8..5522e281 100644 --- a/src/global.rs +++ b/src/global.rs @@ -497,6 +497,7 @@ impl InstanceGuard<'_> { #[throws(MgmtError)] pub fn players_access_reset(&mut self, players: &[PlayerId]) -> Vec { + // xxx disconnect everyone when token changes for &player in players { self.c.g.gs.players.get(player).ok_or(MgmtError::PlayerNotFound)?; } diff --git a/src/spec.rs b/src/spec.rs index 5002452e..7c93727a 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -55,23 +55,26 @@ display_as_debug!{SpecError} #[derive(Debug,Serialize,Deserialize)] pub struct TableSpec { - pub players : Vec, - pub timezone: Option, // default for player timezones + pub players : Vec, + pub acl : Acl } -#[derive(Debug,Serialize,Deserialize)] -pub struct PlayerSpec { - pub nick: String, - pub timezone: Option, - #[serde(flatten)] - pub access: Option>, -} +pub type Acl = Vec>; -#[derive(Debug,Serialize,Deserialize)] -struct FixedToken { token: RawToken } +#[derive(Debug,Clone,Serialize,Deserialize)] +pub struct AclEntry { + pub account_glob: String, + pub allow: HashSet, + pub deny: HashSet, +} -#[derive(Debug,Serialize,Deserialize)] -struct TokenOnStdout; +#[derive(Debug,Clone,Copy,Serialize,Deserialize)] +enum TablePermission { + AddPlayer, + ChangePieces, + RemovePlayer, + ChangeACL, +} //---------- Game TOML file ---------- -- 2.30.2