)}
}
+//---------- delete-game ----------
+
+mod delete_game {
+ use super::*;
+
+ #[derive(Default,Debug)]
+ struct Args {
+ table_name: String,
+ }
+
+ fn subargs(sa: &mut Args) -> ArgumentParser {
+ use argparse::*;
+ let mut ap = ArgumentParser::new();
+ ap.refer(&mut sa.table_name).required()
+ .add_argument("TABLE-NAME",Store,"table name");
+ ap
+ }
+
+ fn call(_sc: &Subcommand, ma: MainOpts, args: Vec<String>) ->Result<(),AE> {
+ let args = parse_args::<Args,_>(args, &subargs, &ok_id, None);
+ let mut chan = access_game(&ma, &args.table_name)?;
+ let game = chan.game.clone();
+ chan.cmd(&MC::DestroyGame { game })?;
+ Ok(())
+ }
+
+ inventory::submit!{Subcommand(
+ "delete-game",
+ "Delete a game (throwing all the players out of it)",
+ call,
+ )}
+}
+
//---------- library-list ----------
#[derive(Debug)]
let mut ag = AccountsGuard::lock();
let mut games = games_lock();
let auth = authorise_by_account(cs, &mut ag, &game)?;
- let gref = Instance::lookup_by_name(&game, auth)?;
+ let gref = Instance::lookup_by_name_locked(&games, &game, auth)?;
let ig = gref.lock_even_poisoned();
Instance::destroy_game(&mut games, ig, auth)?;
Fine
}
#[throws(MgmtError)]
- pub fn lookup_by_name_unauth(name: &InstanceName)
- -> Unauthorised<InstanceRef, InstanceName>
+ pub fn lookup_by_name_locked_unauth
+ (games_table: &GamesTable, name: &InstanceName)
+ -> Unauthorised<InstanceRef, InstanceName>
{
Unauthorised::of(
- GLOBAL.games_table.read().unwrap()
+ games_table
.get(name)
.ok_or(MgmtError::GameNotFound)?
.clone()
)
}
+ #[throws(MgmtError)]
+ pub fn lookup_by_name_locked(games: &GamesTable,
+ name: &InstanceName,
+ auth: Authorisation<InstanceName>)
+ -> InstanceRef {
+ Self::lookup_by_name_locked_unauth(games, name)?.by(auth)
+ }
+
+ #[throws(MgmtError)]
+ pub fn lookup_by_name_unauth(name: &InstanceName)
+ -> Unauthorised<InstanceRef, InstanceName>
+ {
+ let games = GLOBAL.games_table.read().unwrap();
+ Self::lookup_by_name_locked_unauth(&games, name)?
+ }
+
#[throws(MgmtError)]
pub fn lookup_by_name(name: &InstanceName, auth: Authorisation<InstanceName>)
-> InstanceRef {