From 1c52b6426251bca52d507a9068f09f44b4a72ec6 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 4 Jul 2020 02:38:07 +0100 Subject: [PATCH] noclient --- src/error.rs | 4 ++-- src/global.rs | 9 ++++++--- src/sse.rs | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/error.rs b/src/error.rs index aa90de14..5e1f075d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -8,12 +8,12 @@ pub enum OnlineError { #[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::*; diff --git a/src/global.rs b/src/global.rs index c7853034..a932ed9a 100644 --- a/src/global.rs +++ b/src/global.rs @@ -70,13 +70,16 @@ lazy_static! { pub trait AccessId : Copy + Clone + 'static { fn global_tokens() -> &'static RwLock>; + const ERROR : OnlineError; } impl AccessId for PlayerId { fn global_tokens() -> &'static RwLock> { &GLOBAL.players } + const ERROR : OnlineError = NoPlayer; } impl AccessId for ClientId { fn global_tokens() -> &'static RwLock> { &GLOBAL.clients } + const ERROR : OnlineError = NoClient; } pub fn lookup_token(s : &str) @@ -103,12 +106,12 @@ const XXX_PLAYERS_TOKENS : &[(&str, &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() } } } diff --git a/src/sse.rs b/src/sse.rs index 0a6ae522..0ac8fc1f 100644 --- a/src/sse.rs +++ b/src/sse.rs @@ -177,7 +177,7 @@ pub fn content(iad : InstanceAccessDetails, gen: Generation) 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(); -- 2.30.2