CreateGame { game, insns } => {
let ag = AccountsGuard::lock();
- let authorised = authorise_by_account(cs, &ag, &game)?;
+ let auth = authorise_by_account(cs, &ag, &game)?;
let gs = crate::gamestate::GameState {
table_size : DEFAULT_TABLE_SIZE,
};
let acl = default();
- let gref = Instance::new(game, gs, acl, authorised)?;
+ let gref = Instance::new(game, gs, acl, auth)?;
let ig = gref.lock()?;
execute_for_game(cs, &ag, &mut Unauthorised::of(ig),
insns, MgmtGameUpdateMode::Bulk)
.map_err(|e|{
let name = ig.name.clone();
- Instance::destroy_game(ig, authorised)
+ let InstanceGuard { c, .. } = ig;
+ Instance::destroy_game(c, auth)
.unwrap_or_else(|e| warn!(
"failed to tidy up failecd creation of {:?}: {:?}",
&name, &e
execute_for_game(cs, &ag, &mut g, insns, how)?
},
+ DestroyGame { game } => {
+ let ag = AccountsGuard::lock();
+ let auth = authorise_by_account(cs, &ag, &game)?;
+ let gref = Instance::lookup_by_name(&game, auth)?;
+ let ig = gref.lock_even_poisoned();
+ Instance::destroy_game(ig, auth)?;
+ Fine
+ }
+
LibraryListByGlob { glob: spec } => {
let lib = shapelib::libs_lookup(&spec.lib)?;
let results = lib.list_glob(&spec.item)?;
InstanceGuard { c, gref: self.clone() }
}
- fn lock_even_poisoned(&self) -> MutexGuard<InstanceContainer> {
+ pub fn lock_even_poisoned(&self) -> MutexGuard<InstanceContainer> {
match self.0.lock() {
Ok(g) => g,
Err(poison) => poison.into_inner(),
}
#[throws(InternalError)]
- pub fn destroy_game(mut g: InstanceGuard, _: Authorisation<InstanceName>) {
- let a_savefile = savefilename(&g.name, "a-", "");
+ pub fn destroy_game(mut g: MutexGuard<InstanceContainer>,
+ _: Authorisation<InstanceName>) {
+ let a_savefile = savefilename(&g.g.name, "a-", "");
let mut gw = GLOBAL.games.write().unwrap();
// xxx lock order wrong, this function should unlock and then relock
- let g_file = savefilename(&g.name, "g-", "");
+ let g_file = savefilename(&g.g.name, "g-", "");
fs::remove_file(&g_file).context("remove").context(g_file)?;
(||{ // Infallible:
- g.c.live = false;
- gw.remove(&g.name);
- InstanceGuard::forget_all_tokens(&mut g.tokens_clients);
- InstanceGuard::forget_all_tokens(&mut g.tokens_players);
+ g.live = false;
+ gw.remove(&g.g.name);
+ InstanceGuard::forget_all_tokens(&mut g.g.tokens_clients);
+ InstanceGuard::forget_all_tokens(&mut g.g.tokens_players);
})(); // <- No ?, ensures that IEFE is infallible (barring panics)
(||{ // Best effort: