From: Ian Jackson Date: Sun, 26 Jul 2020 21:40:24 +0000 (+0100) Subject: list all games X-Git-Tag: otter-0.2.0~1239 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=798a3e7eaa170a08bf907966c89f1cda75e75648;p=otter.git list all games --- diff --git a/src/cmdlistener.rs b/src/cmdlistener.rs index e38f7fc1..6d5866e9 100644 --- a/src/cmdlistener.rs +++ b/src/cmdlistener.rs @@ -227,6 +227,13 @@ fn execute(cs: &mut CommandStream, cmd: MgmtCommand) -> MgmtResponse { Fine { } }, + ListGames { } => { + let scope = cs.scope.as_ref().ok_or(NoScope)?; + let mut games = list_games(Some(scope)); + games.sort_unstable(); + GamesList { games } + }, + // let game = cs.lookup_game(&game)?; } diff --git a/src/commands.rs b/src/commands.rs index a308c2fa..064c89b3 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -6,6 +6,7 @@ pub enum MgmtCommand { Noop { }, SetScope { scope: ManagementScope }, CreateGame { name: String, insns: Vec }, + ListGames { }, } #[derive(Debug,Serialize,Deserialize)] @@ -19,6 +20,7 @@ pub enum MgmtResponse { Fine { }, Error { error: MgmtError }, ErrorAfter { successes: usize, error: MgmtError }, + GamesList { games: Vec> }, } #[derive(Debug,Serialize,Deserialize)] diff --git a/src/global.rs b/src/global.rs index 0956a56f..7fcc1b9a 100644 --- a/src/global.rs +++ b/src/global.rs @@ -328,6 +328,17 @@ impl InstanceGuard<'_> { } } +pub fn list_games(scope: Option<&ManagementScope>) + -> Vec> { + let games = GLOBAL.games.read().unwrap(); + let out : Vec> = + games.keys() + .filter(|k| scope == None || scope == Some(&k.scope)) + .map(|k| k.clone()) + .collect(); + out +} + // ---------- Lookup and token API ---------- impl AccessId for PlayerId {