type SE = SpecError;
type CSE = anyhow::Error;
-use MgmtCommand::*;
-use MgmtResponse::*;
-
type TP = TablePermission;
+use MgmtResponse::Fine;
+
const USERLIST: &str = "/etc/userlist";
const CREATE_PIECES_MAX: u32 = 300;
#[throws(ME)]
fn execute(cs: &mut CommandStream, cmd: MgmtCommand) -> MgmtResponse {
match cmd {
- Noop => Fine,
+ MC::Noop => Fine,
- SetSuperuser(enable) => {
+ MC::SetSuperuser(enable) => {
if !enable {
cs.superuser = None;
} else {
Fine
},
- CreateAccount(AccountDetails {
+ MC::CreateAccount(AccountDetails {
account, nick, timezone, access, layout
}) => {
let mut ag = AccountsGuard::lock();
Fine
}
- UpdateAccount(AccountDetails {
+ MC::UpdateAccount(AccountDetails {
account, nick, timezone, access, layout
}) => {
let mut ag = AccountsGuard::lock();
.map_err(|(e,_)|e) ?
}
- DeleteAccount(account) => {
+ MC::DeleteAccount(account) => {
let mut ag = AccountsGuard::lock();
let mut games = games_lock();
let auth = authorise_for_account(cs, &ag, &account)?;
Fine
}
- SelectAccount(wanted_account) => {
+ MC::SelectAccount(wanted_account) => {
let auth = authorise_scope_direct(cs, &wanted_account.scope)?;
cs.account = Some(AccountSpecified {
cooked: wanted_account.to_string(),
Fine
}
- CheckAccount => {
+ MC::CheckAccount => {
let ag = AccountsGuard::lock();
let _ok = ag.lookup(&cs.current_account()?.notional_account)?;
Fine
}
- CreateGame { game, insns } => {
+ MC::CreateGame { game, insns } => {
let mut ag = AccountsGuard::lock();
let mut games = games_lock();
let auth = authorise_by_account(cs, &ag, &game)?;
resp
}
- ListGames { all } => {
+ MC::ListGames { all } => {
let (scope, auth) = if all == Some(true) {
let auth = authorise_scope_direct(cs, &AS::Server)?;
(None, auth.therefore_ok())
};
let mut games = Instance::list_names(scope, auth);
games.sort_unstable();
- GamesList(games)
+ MR::GamesList(games)
}
- MgmtCommand::AlterGame { game, insns, how } => {
+ MC::AlterGame { game, insns, how } => {
let mut ag = AccountsGuard::lock();
let gref = Instance::lookup_by_name_unauth(&game)?;
let mut g = gref.lock()?;
execute_for_game(cs, &mut ag, &mut g, insns, how)?
}
- DestroyGame { game } => {
+ MC::DestroyGame { game } => {
let mut ag = AccountsGuard::lock();
let mut games = games_lock();
let auth = authorise_by_account(cs, &mut ag, &game)?;
Fine
}
- LibraryListByGlob { glob: spec } => {
+ MC::LibraryListByGlob { glob: spec } => {
let lib = shapelib::libs_lookup(&spec.lib)?;
let results = lib.list_glob(&spec.item)?;
- LibraryItems(results)
+ MR::LibraryItems(results)
}
}
}
-> Result<ExecuteGameInsnResults<'igr, 'ig> ,ME>
{
type U = ExecuteGameChangeUpdates;
- use MgmtGameInstruction::*;
- use MgmtGameResponse::*;
- type Insn = MgmtGameInstruction;
- type Resp = MgmtGameResponse;
+ use MgmtGameResponse::Fine;
fn tz_from_str(s: &str) -> Timezone {
match Timezone::from_str(s) {
}
let y = match update {
- Noop { } => readonly(cs,ag,ig, &[], |_| Ok(Fine))?,
+ MGI::Noop { } => readonly(cs,ag,ig, &[], |_| Ok(Fine))?,
- Insn::SetTableSize(size) => {
+ MGI::SetTableSize(size) => {
let ig = cs.check_acl(ag, ig, PCH::Instance, &[TP::ChangePieces])?.0;
ig.gs.table_size = size;
(U{ pcs: vec![],
Fine, ig)
}
- Insn::SetTableColour(colour) => {
+ MGI::SetTableColour(colour) => {
let ig = cs.check_acl(ag, ig, PCH::Instance, &[TP::ChangePieces])?.0;
let colour: Colour = (&colour).try_into()?;
ig.gs.table_colour = colour.clone();
Fine, ig)
}
- Insn::JoinGame {
+ MGI::JoinGame {
details: MgmtPlayerDetails { nick },
} => {
let account = &cs.current_account()?.notional_account;
(U{ pcs: vec![],
log: vec![ logentry ],
raw: Some(vec![ update ] )},
- Resp::JoinGame { nick, player, token: atr },
+ MGR::JoinGame { nick, player, token: atr },
ig)
},
- Insn::Synch => {
+ MGI::Synch => {
let (mut ig, _) = cs.check_acl(&ag, ig, PCH::Instance, &[TP::Play])?;
let mut buf = PrepareUpdatesBuffer::new(&mut ig, None, None);
let gen = buf.gen();
(U{ pcs: vec![], // we handled the update ourselves,
log: vec![], // return no update info
raw: None },
- Resp::Synch(gen),
+ MGR::Synch(gen),
ig)
},
- Insn::ListPieces => readonly(cs,ag,ig, &[TP::ViewNotSecret], |ig|{
+ MGI::ListPieces => readonly(cs,ag,ig, &[TP::ViewNotSecret], |ig|{
let pieces = ig.gs.pieces.iter().map(|(piece,p)|{
let &PieceState { pos, face, .. } = p;
let pinfo = ig.ipieces.get(piece)?;
visible
})
}).flatten().collect();
- Ok(Resp::Pieces(pieces))
+ Ok(MGR::Pieces(pieces))
})?,
- UpdatePlayer {
+ MGI::UpdatePlayer {
player,
details: MgmtPlayerDetails { nick },
} => {
Fine, ig)
},
- Insn::Info => readonly(cs,ag,ig, &[TP::ViewNotSecret], |ig|{
+ MGI::Info => readonly(cs,ag,ig, &[TP::ViewNotSecret], |ig|{
let players = ig.gs.players.iter().map(
|(player, gpl)| {
let nick = gpl.nick.clone();
Some((k.clone(), UrlSpec(v.as_ref()?.clone())))
).collect();
let info = MgmtGameResponseGameInfo { table_size, players, links };
- Ok(Resp::Info(info))
+ Ok(MGR::Info(info))
})?,
- Insn::SetLinks(mut spec_links) => {
+ MGI::SetLinks(mut spec_links) => {
update_links(cs,ag,ig, |ig_links|{
let mut new_links: LinksTable = default();
// todo want a FromIterator impl
})?
}
- Insn::SetLink { kind, url } => {
+ MGI::SetLink { kind, url } => {
update_links(cs,ag,ig, |ig_links|{
let mut new_links: LinksTable = (**ig_links).clone();
let url: Url = (&url).try_into()?;
})?
}
- Insn::RemoveLink { kind } => {
+ MGI::RemoveLink { kind } => {
update_links(cs,ag,ig, |ig_links|{
let mut new_links: LinksTable = (**ig_links).clone();
new_links[kind] = None;
})?
}
- ResetPlayerAccess(player) => {
+ MGI::ResetPlayerAccess(player) => {
let (ig, auth) = cs.check_acl_manip_player_access
(ag, ig, player, TP::ResetOthersAccess)?;
(U{ pcs: vec![],
log: vec![],
raw: None },
- PlayerAccessToken(token), ig)
+ MGR::PlayerAccessToken(token), ig)
}
- RedeliverPlayerAccess(player) => {
+ MGI::RedeliverPlayerAccess(player) => {
let (ig, auth) = cs.check_acl_manip_player_access
(ag, ig, player, TP::RedeliverOthersAccess)?;
(U{ pcs: vec![],
log: vec![],
raw: None },
- PlayerAccessToken(token), ig)
+ MGR::PlayerAccessToken(token), ig)
},
- LeaveGame(player) => {
+ MGI::LeaveGame(player) => {
let account = &cs.current_account()?.notional_account;
let (ig, _auth) = cs.check_acl_manip_player_access
(ag, ig, player, TP::ModifyOtherPlayer)?;
Fine, ig)
},
- DeletePiece(piece) => {
+ MGI::DeletePiece(piece) => {
let (ig, modperm, _) = cs.check_acl_modify_pieces(ag, ig)?;
let p = ig.ipieces.as_mut(modperm)
.remove(piece).ok_or(ME::PieceNotFound)?;
Fine, ig)
},
- AddPieces(PiecesSpec{ pos,posd,count,face,pinned,angle,info }) => {
+ MGI::AddPieces(PiecesSpec{ pos,posd,count,face,pinned,angle,info }) => {
let (ig_g, modperm, _) = cs.check_acl_modify_pieces(ag, ig)?;
let ig = &mut **ig_g;
let gs = &mut ig.gs;
Fine, ig_g)
},
- ClearLog => {
+ MGI::ClearLog => {
let (ig, _) = cs.check_acl(&ag, ig, PCH::Instance, &[TP::Super])?;
ig.gs.log.clear();
for ipr in ig.iplayers.values_mut() {
Fine, ig)
},
- SetACL { acl } => {
+ MGI::SetACL { acl } => {
let (ig, _) = cs.check_acl(&ag, ig, PCH::Instance, &[TP::Super])?;
ig.acl = acl.into();
let mut log = vec![ LogEntry {