#[error("Game corrupted by previous crash - consult administrator")]
GameCorrupted,
#[error("client session not recognised (terminated by server?)")]
- NoClientSession,
+ NoClient,
#[error("player not part of game (removed?)")]
NoPlayer,
}
-pub use OnlineError::{NoClientSession,NoPlayer};
+pub use OnlineError::{NoClient,NoPlayer};
use OnlineError::*;
pub trait AccessId : Copy + Clone + 'static {
fn global_tokens() -> &'static RwLock<TokenTable<Self>>;
+ const ERROR : OnlineError;
}
impl AccessId for PlayerId {
fn global_tokens() -> &'static RwLock<TokenTable<Self>> { &GLOBAL.players }
+ const ERROR : OnlineError = NoPlayer;
}
impl AccessId for ClientId {
fn global_tokens() -> &'static RwLock<TokenTable<Self>> { &GLOBAL.clients }
+ const ERROR : OnlineError = NoClient;
}
pub fn lookup_token<Id : AccessId>(s : &str)
impl<'r, Id> FromParam<'r> for InstanceAccess<'r, Id>
where Id : AccessId
{
- type Error = E;
- #[throws(E)]
+ type Error = OE;
+ #[throws(OE)]
fn from_param(param: &'r RawStr) -> Self {
let g = Id::global_tokens().read().unwrap();
let token = param.as_str();
- let i = g.get(token).ok_or_else(|| anyhow!("unknown token"))?;
+ let i = g.get(token).ok_or(Id::ERROR)?;
InstanceAccess { raw_token : token, i : i.clone() }
}
}
let content = {
let mut ig = iad.g.lock()?;
let _g = &mut ig.gs;
- let cl = ig.clients.get(client).ok_or(NoClientSession)?;
+ let cl = ig.clients.get(client).ok_or(NoClient)?;
let player = cl.player;
let ami = iad.g.clone();