RwLockReadGuard, RwLockWriteGuard,
MappedRwLockReadGuard, MappedRwLockWriteGuard};
+slotmap::new_key_type!{
+// #[derive(Serialize,Deserialize,Debug)] xxx
+ pub struct AccountId;
+}
+
#[derive(Debug,Clone,Deserialize,Serialize)]
#[derive(Eq,PartialEq,Ord,PartialOrd,Hash)]
pub enum AccountScope {
pub earliest: Timestamp,
}
-static ACCOUNTS : RwLock<Option<HashMap<AccountName, AccountRecord>>>
- = const_rwlock(None);
+#[derive(Debug)]
+#[derive(Serialize,Deserialize)]
+struct Accounts {
+ names: HashMap<AccountName, AccountId>,
+ records: DenseSlotMap<AccountId, AccountRecord>,
+}
+
+static ACCOUNTS : RwLock<Option<Accounts>> = const_rwlock(None);
// xxx load, incl reveleation expiry
// xxx periodic token reveleation expiry
|accounts| accounts.as_mut()?.get_mut(account)
).ok()
}
+
+ #[throws(MgmtError)]
pub fn with_entry_mut<T, F>(account: &AccountName,
auth: Authorisation<AccountName>,
f: F)
-> Result<T, (InternalError, T)>
- where F: FnOnce(Option<&mut AccountRecord>) -> T
+ where F: FnOnce(&mut AccountRecord) -> T
{
- let entry = AccountRecord::lookup_mut_caller_must_save(account, auth);
- let output = f(entry.as_deref_mut());
+ let entry = AccountRecord::lookup_mut_caller_must_save(account, auth)
+ .ok_or(MgmtError::AccountNotFound)?;
+ let old_access = entry.access.clone();
+ let output = f(entry);
+ let mut ok = true;
+ if ! Arc::ptr_eq(old_access, entry.access) {
+// xxx actually do this
+// invalidate_all_tokens_for_account(accid)
+// .dont_just_questionmark
+ }
let ok = if entry.is_some() { save_accounts_now() } else { Ok(()) };
match ok {
Ok(()) => Ok(output),
AccountRecord::insert_entry(account, auth, record)?;
Fine
}
+/*
+ UpdateAccont(AccountDetails { account, nick, timezone, access }) => {
+ let auth = authorise_for_account(cs, &account)?;
+ let access = access.map(Into::into);
+
+ .unwrap_or_else(|| Arc::new(PlayerAccessUnset) as Arc<_>);
+ let record = AccountRecord {
+ nick, access,
+ timezone: timezone.unwrap_or_default(),
+ tokens_revealed: default(),
+ };
+ AccountRecord::insert_entry(account, auth, record)?;
+ Fine
+ }*/
SetAccount(wanted_account) => {
let auth = authorise_scope_direct(cs, &wanted_account.scope)?;
raw: None },
PlayerAccessToken(token), ig)
},
-/*
- SetFixedPlayerAccess { player, token } => {
- let authorised : AuthorisedSatisfactory =
- authorise_scope(cs, &AS::Server)?;
- let authorised = match authorised.into_inner() {
- AS::Server => Authorisation::<RawToken>::authorise(),
- _ => panic!(),
- };
- ig.player_access_register_fixed(
- player, token, authorised
- )?;
- (U{ pcs: vec![],
- log: vec![],
- raw: None},
- Fine)
- }
-*/
DeletePiece(piece) => {
let (ig, modperm, _) = cs.check_acl_modify_pieces(ig)?;
pub struct InstanceAccessDetails<Id> {
pub gref : InstanceRef,
pub ident : Id,
+ pub accid : AccountId,
}
#[derive(Clone,Debug)]
Ok((old_account, old_pst))
}
- #[throws(MgmtError)]
- pub fn player_access_register_fixed(&mut self,
- player: PlayerId, token: RawToken,
- _safe: Authorisation<RawToken>
- ) {
- // xxx get rid of this or something ?
- self.tokens_deregister_for_id(|id:PlayerId| id==player);
- let iad = InstanceAccessDetails {
- gref : self.gref.clone(),
- ident : player
- };
- self.token_register(token, iad);
- self.save_access_now()?;
- }
-
#[throws(MgmtError)]
fn player_access_reset_redeliver(&mut self, player: PlayerId,
authorised: Authorisation<AccountName>,
let access = AccountRecord::with_entry_mut(
&pst.account, authorised,
- |acct|
+ |acct, acctid|
{
- let acct = acct.ok_or(MgmtError::AccountNotFound)?;
let access = acct.access;
let desc = access.describe_html();
let now = Timestamp::now();
.latest = now;
acct.expire_tokens_revealed();
Ok::<_,MgmtError>(access.clone())
- }).map_err(|(e,_)|e)??;
+ })?.map_err(|(e,_)|e)??;
if reset {
self.save_access_now()?;