chiark / gitweb /
list all games
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 26 Jul 2020 21:40:24 +0000 (22:40 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 26 Jul 2020 21:40:24 +0000 (22:40 +0100)
src/cmdlistener.rs
src/commands.rs
src/global.rs

index e38f7fc18aa2d50366aaa5597446de24b72c1630..6d5866e9adb60d7826738c0f8a36a24f4744231c 100644 (file)
@@ -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)?;
 
   }
index a308c2fab4bf4bc5a72ba69394a673438a903592..064c89b30267b5f859ebe23e8876f0cc9f28da9c 100644 (file)
@@ -6,6 +6,7 @@ pub enum MgmtCommand {
   Noop { },
   SetScope { scope: ManagementScope },
   CreateGame { name: String, insns: Vec<MgmtGameInstruction> },
+  ListGames { },
 }
 
 #[derive(Debug,Serialize,Deserialize)]
@@ -19,6 +20,7 @@ pub enum MgmtResponse {
   Fine { },
   Error { error: MgmtError },
   ErrorAfter { successes: usize, error: MgmtError },
+  GamesList { games: Vec<Arc<InstanceName>> },
 }
 
 #[derive(Debug,Serialize,Deserialize)]
index 0956a56f8770eaee79560ed5b118adf64c3bb15e..7fcc1b9a2758836cf7f6c39d6b9ac8e582700b87 100644 (file)
@@ -328,6 +328,17 @@ impl InstanceGuard<'_> {
   }
 }
 
+pub fn list_games(scope: Option<&ManagementScope>)
+                  -> Vec<Arc<InstanceName>> {
+  let games = GLOBAL.games.read().unwrap();
+  let out : Vec<Arc<InstanceName>> =
+    games.keys()
+    .filter(|k| scope == None || scope == Some(&k.scope))
+    .map(|k| k.clone())
+    .collect();
+  out
+}
+
 // ---------- Lookup and token API ----------
 
 impl AccessId for PlayerId {