From: Ian Jackson Date: Sun, 26 Jul 2020 22:45:44 +0000 (+0100) Subject: altergame X-Git-Tag: otter-0.2.0~1233 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=2aab2a98ab0d4c1c75c5bdb6cbe61bf5f4195119;p=otter.git altergame --- diff --git a/src/cmdlistener.rs b/src/cmdlistener.rs index cbc2b2e4..8a2167a4 100644 --- a/src/cmdlistener.rs +++ b/src/cmdlistener.rs @@ -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)? + }, + } } diff --git a/src/commands.rs b/src/commands.rs index b935d25c..fc48610e 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -7,6 +7,10 @@ pub enum MgmtCommand { SetScope { scope: ManagementScope }, CreateGame { name: String, insns: Vec }, ListGames { all: Option, }, + AlterGame { + name: String, insns: Vec, + how: MgmtGameUpdateMode, + }, } #[derive(Debug,Serialize,Deserialize)] @@ -36,6 +40,7 @@ pub enum MgmtError { NoScope, AlreadyExists, GameBeingDestroyed, + GameNotFound, GameCorrupted, LimitExceeded, SVGProcessingFailed(#[from] SVGProcessingError), diff --git a/src/global.rs b/src/global.rs index 0eb138ad..06775ac0 100644 --- a/src/global.rs +++ b/src/global.rs @@ -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