E,
F: FnMut(&str) -> Result<(),E>
>
- (&'out self, ns: NS, f: F)
+ (&'out self, ns: NS, mut f: F)
{
const ENCODE : percent_encoding::AsciiSet =
percent_encoding::NON_ALPHANUMERIC.remove(b':');
let mut split = s.split(':');
let scope = {
- let next = ||{
+ let mut next = ||{
split.next()
.ok_or(InvalidScopedName::MissingScopeComponent)
};
#[throws(fmt::Error)]
/// Return value is parseable, and filesystem- and html-safeb
fn fmt(&self, f: &mut fmt::Formatter) {
- self.scope.display_name(&[ self.subaccount.as_str() ], |s| f.write_str(s))
+ self.scope.display_name(&[
+ self.subaccount.as_str()
+ ], |s| f.write_str(s))?
}
}
#[throws(InvalidScopedName)]
fn from_str(s: &str) -> Self {
- let subaccount = default();
+ let mut subaccount = default();
let names = std::slice::from_mut(&mut subaccount);
let scope = AccountScope::parse_name(s, names)?;
AccountName { scope, subaccount }
#[derive(Debug,Default)]
#[derive(Serialize,Deserialize)]
-struct Accounts {
+pub struct Accounts {
names: HashMap<Arc<AccountName>, AccountId>,
records: DenseSlotMap<AccountId, AccountRecord>,
}
// xxx load, incl reveleation expiry
// xxx periodic token reveleation expiry
-trait AccountNameOrId : Copy {
+pub trait AccountNameOrId : Copy {
fn initial_lookup(self, accounts: &Accounts) -> Option<AccountId>;
}
{
use hash_map::Entry::*;
let accounts = self.0.get_or_insert_with(default);
- let name_entry = accounts.names.entry(new_record.account.clone());
+ let mut name_entry = accounts.names.entry(new_record.account.clone());
if_chain!{
- if let Occupied(oe) = name_entry;
+ if let Occupied(ref mut oe) = name_entry;
let acctid = *oe.get();
if let Some(old_record) = accounts.records.get_mut(acctid);
then {
let acctid = accounts.records.insert(new_record);
match name_entry {
Vacant(ve) => { ve.insert(acctid); }
- Occupied(oe) => { oe.insert(acctid); }
+ Occupied(ref mut oe) => { oe.insert(acctid); }
}
}
}
impl<P:Perm> From<Acl<P>> for LoadedAcl<P> {
fn from(acl: Acl<P>) -> LoadedAcl<P> {
- (&acl).into()
- }
- }
-
- impl<P:Perm> From<&Acl<P>> for LoadedAcl<P> {
- fn from(acl: &Acl<P>) -> LoadedAcl<P> {
let ents = acl.ents.into_iter().filter_map(
|AclEntry { account_glob, allow, deny }|
{
impl<P:Perm> From<LoadedAcl<P>> for Acl<P> {
fn from(acl: LoadedAcl<P>) -> Acl<P> {
- (&acl).into()
- }
- }
-
- impl<P:Perm> From<&LoadedAcl<P>> for Acl<P> {
- fn from(acl: &LoadedAcl<P>) -> Acl<P> {
let LoadedAcl(ents) = acl;
Acl { ents: ents.into_iter().map(
|LoadedAclEntry { pat, allow, deny, .. }|
AclEntry {
account_glob: pat.to_string(),
- allow: unpack(allow),
- deny: unpack(deny),
+ allow: unpack(&allow),
+ deny: unpack(&deny),
}
).collect() }
}
player: PlayerId,
piece: PieceId,
p: &'a dyn Piece,
- iplayers: &'a SecondarySlotMap<PlayerId, PlayerRecord>,
lens: &'a dyn Lens /* used for LogEntry and PieceId but not Pos */
}
form.op.check_held(pc,player)?;
let (wrc, update, logents) =
form.op.op(ApiPieceOpArgs {
- gs, player, piece, iplayers,
+ gs, player, piece,
p: p.as_ref(),
lens: &lens,
})?;
// ---------- game command implementations ----------
-type ExecuteGameInsnResults<'igr, 'ig : 'igr> = (
+type ExecuteGameInsnResults<'igr, 'ig> = (
ExecuteGameChangeUpdates,
MgmtGameResponse,
&'igr mut InstanceGuard<'ig>,
{
let mut uh = UpdateHandler::from_how(how);
let mut responses = Vec::with_capacity(insns.len());
- let mut iga = None;
+ let mut auth = None;
let res = (||{
for insn in insns.drain(0..) {
let (updates, resp, ig) = execute_game_insn(cs, ag, igu, insn)?;
uh.accumulate(ig, updates)?;
responses.push(resp);
- iga = Some(ig);
+ auth = Some(Authorisation::authorised(&*ig.name));
}
- if let Some(ig) = iga { uh.complete(cs,ig)?; }
+ if let Some(auth) = auth { uh.complete(cs, igu.by_mut(auth))?; }
Ok(None)
})();
- if let Some(ig) = iga {
- ig.save_game_now()?;
+ if let Some(auth) = auth {
+ igu.by_mut(auth).save_game_now()?;
}
MgmtResponse::AlterGame {
responses,
Authorisation<InstanceName>)
{
let ipl_unauth = {
- let ig = ig.by(Authorisation::authorise_any());
+ let ig = ig.by_ref(Authorisation::authorise_any());
ig.iplayers.byid(player)?
};
let how = PCH::InstanceOrOnlyAffectedAccount(ipl_unauth.ipl.acctid);
PCH::InstanceOrOnlyAffectedPlayer(object_player) => {
if_chain!{
if let Some(object_ipr) =
- ig.by(Authorisation::authorise_any()).iplayers
+ ig.by_ref(Authorisation::authorise_any()).iplayers
.get(object_player);
then { subject_is(object_ipr.ipl.acctid) }
else { None }
let auth = {
let subject = ¤t_account.cooked;
let (acl, owner) = {
- let ig = ig.by(Authorisation::authorise_any());
+ let ig = ig.by_ref(Authorisation::authorise_any());
(&ig.acl, &ig.name.account)
};
- let eacl = EffectiveAcl {
- owner_account : Some(&owner.to_string()),
- acl : acl,
- };
+ let owner_account = owner.to_string();
+ let owner_account = Some(owner_account.as_str());
+ let eacl = EffectiveAcl { owner_account, acl };
eacl.check(subject, p)?
};
auth
|(player, PlayerRecord { ipl, .. })|
(player, ipl.clone())
).collect();
- let acl = (&s.c.g.acl).into();
+ let acl = s.c.g.acl.clone().into();
let isa = InstanceSaveAccesses {
ipieces, tokens_players, aplayers, acl
};
let g = Instance {
gs, iplayers,
- acl: (&acl).into(),
+ acl: acl.into(),
ipieces: PiecesLoaded(ipieces),
name: name.clone(),
clients : Default::default(),
pub mod implementation {
use super::*;
use crate::imports::*;
- type Insn = crate::commands::MgmtGameInstruction;
impl<P: Eq + Hash> Default for Acl<P> {
fn default() -> Self { Acl { ents: default() } }
}
#[typetag::serde(tag="access")]
- pub trait PlayerAccessSpec : Debug {
+ pub trait PlayerAccessSpec : Debug + Sync + Send {
fn override_token(&self) -> Option<&RawToken> {
// xxx check this on setting access
None