chiark / gitweb /
altergame
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 26 Jul 2020 22:45:44 +0000 (23:45 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 26 Jul 2020 22:45:44 +0000 (23:45 +0100)
src/cmdlistener.rs
src/commands.rs
src/global.rs

index cbc2b2e4bc7c8f8a65b4d8afe3fe2acdbf2dff77..8a2167a4fcf71387e35ea8676dbc5d9d15a252b2 100644 (file)
@@ -251,6 +251,16 @@ fn execute(cs: &mut CommandStream, cmd: MgmtCommand) -> MgmtResponse {
       GamesList { games }
     },
 
+    AlterGame { name, insns, how} => {
+      let name = InstanceName {
+        scope: cs.get_scope()?.clone(),
+        scoped_name: name
+      };
+      let gref = Instance::lookup_by_name(&name)?;
+      let mut g = gref.lock()?;
+      execute_for_game(cs, &mut g, insns, how)?
+    },
+
   }
 }
 
index b935d25ceb1454960fe484c40ab85cb543e05c50..fc48610e25064442fb6d330d0fe0b08ce71b9962 100644 (file)
@@ -7,6 +7,10 @@ pub enum MgmtCommand {
   SetScope { scope: ManagementScope },
   CreateGame { name: String, insns: Vec<MgmtGameInstruction> },
   ListGames { all: Option<bool>, },
+  AlterGame {
+    name: String, insns: Vec<MgmtGameInstruction>,
+    how: MgmtGameUpdateMode,
+  },
 }
 
 #[derive(Debug,Serialize,Deserialize)]
@@ -36,6 +40,7 @@ pub enum MgmtError {
   NoScope,
   AlreadyExists,
   GameBeingDestroyed,
+  GameNotFound,
   GameCorrupted,
   LimitExceeded,
   SVGProcessingFailed(#[from] SVGProcessingError),
index 0eb138ad0aa9e6a874e3c453d9b5c39ad77098b2..06775ac0cb085080edfdf672cbf183349e6f83b3 100644 (file)
@@ -177,6 +177,14 @@ impl Instance {
     gref
   }
 
+  #[throws(MgmtError)]
+  pub fn lookup_by_name(name: &InstanceName) -> InstanceRef {
+    GLOBAL.games.read().unwrap()
+      .get(name)
+      .ok_or(MgmtError::GameNotFound)?
+      .clone()
+  }
+
   pub fn destroy(mut g: InstanceGuard) {
     g.c.live = false;
     // remove the files