//---------- simple types ----------
-slotmap::new_key_type!{
- pub struct AccountId;
-}
-
-#[derive(Debug,Clone,Deserialize,Serialize)]
-#[derive(Eq,PartialEq,Ord,PartialOrd,Hash)]
-pub enum AccountScope {
- Server,
- Unix { user : String },
-}
-
type AS = AccountScope;
type ME = MgmtError;
type IE = InternalError;
-#[derive(Debug,Clone)]
-#[derive(Eq,PartialEq,Ord,PartialOrd,Hash)]
-#[derive(DeserializeFromStr,SerializeDisplay)]
-pub struct AccountName {
- pub scope: AccountScope,
- pub subaccount: String,
-}
-
/// Record of acess for a player. Newtype prevents mutable access
/// without invalidating old tokens and permissions check.
#[derive(Serialize,Deserialize,Debug)]
).collect() }
}
}
+
+ impl Perm for spec::TablePermission {
+ type Auth = InstanceName;
+ const TEST_EXISTENCE : Self = TablePermission::TestExistence;
+ const NOT_FOUND : MgmtError = MgmtError::GameNotFound;
+ }
}
--- /dev/null
+// Copyright 2020 Ian Jackson
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// There is NO WARRANTY.
+
+use crate::imports::*;
+
+#[derive(Error,Debug)]
+pub enum OnlineError {
+ #[error("Game in process of being destroyed")]
+ GameBeingDestroyed,
+ #[error("client session not recognised (terminated by server?)")]
+ NoClient,
+ #[error("player not part of game (removed?)")]
+ NoPlayer(#[from] PlayerNotFound),
+ #[error("invalid Z coordinate")]
+ InvalidZCoord,
+ #[error("Server operational problems - consult administrator: {0:?}")]
+ ServerFailure(#[from] InternalError),
+ #[error("JSON deserialisation error: {0:?}")]
+ BadJSON(serde_json::Error),
+ #[error("referenced piece is gone (maybe race)")]
+ PieceGone,
+ #[error("improper piece hold status for op (maybe race)")]
+ PieceHeld,
+ #[error("improper UI operation")]
+ BadOperation,
+}
+from_instance_lock_error!{OnlineError}
+
+pub use OnlineError::{NoClient,NoPlayer};
+
+#[derive(Error,Debug)]
+pub enum InstanceLockError {
+ GameCorrupted,
+ GameBeingDestroyed,
+}
+#[macro_export]
+macro_rules! from_instance_lock_error {
+ ($into:ident) => {
+ impl From<InstanceLockError> for $into {
+ fn from(e: InstanceLockError) -> $into {
+ use InstanceLockError::*;
+ match e {
+ GameBeingDestroyed => $into::GameBeingDestroyed,
+ GameCorrupted => InternalError::GameCorrupted.into(),
+ }
+ }
+ }
+ }
+}
+
+pub trait ById {
+ type Id;
+ type Entry;
+ type Error;
+ #[throws(Self::Error)]
+ fn byid(&self, t: Self::Id) -> &Self::Entry;
+ #[throws(Self::Error)]
+ fn byid_mut(&mut self, t: Self::Id) -> &mut Self::Entry;
+}
+
+pub trait IdForById {
+ type Error;
+ #[allow(clippy::declare_interior_mutable_const)]
+// https://github.com/rust-lang/rust-clippy/issues/3962#issuecomment-667957112
+ const ERROR : Self::Error;
+}
+
+macro_rules! some_slotmap {
+ ($slotmap:ident) => {
+ impl<I:IdForById+slotmap::Key, T> ById for $slotmap<I,T> {
+ type Id = I;
+ type Entry = T;
+ type Error = <I as IdForById>::Error;
+ fn byid (& self, t: Self::Id) -> Result<& T, Self::Error> {
+ self.get (t).ok_or(<I as IdForById>::ERROR)
+ }
+ fn byid_mut(&mut self, t: Self::Id) -> Result<&mut T, Self::Error> {
+ self.get_mut(t).ok_or(<I as IdForById>::ERROR)
+ }
+ }
+ }
+}
+
+some_slotmap!{DenseSlotMap}
+some_slotmap!{SecondarySlotMap}
+
+impl<T> IdForById for T where T : AccessId {
+ type Error = T::Error;
+ const ERROR : Self::Error = <Self as AccessId>::ERROR;
+}
+
+impl IdForById for PieceId {
+ type Error = OE;
+ const ERROR : OE = OE::PieceGone;
+}
+
// ---------- newtypes and type aliases ----------
-visible_slotmap_key!{ PlayerId('#') }
-
-slotmap::new_key_type!{
- pub struct PieceId;
-}
-
-#[derive(Copy,Clone,Debug,Ord,PartialOrd,Eq,PartialEq)]
-#[derive(Serialize,Deserialize)]
-#[serde(transparent)]
-pub struct Generation (pub u64);
-
-visible_slotmap_key!{ VisiblePieceId('.') }
-
#[derive(Clone,Serialize,Deserialize,Hash,Eq,Ord,PartialEq,PartialOrd)]
#[serde(transparent)]
pub struct Html (pub String);
--- /dev/null
+// Copyright 2020 Ian Jackson
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// There is NO WARRANTY.
+
+use otter::imports::*;
+
+pub mod session;
+pub mod updates;
+pub mod sse;
+pub mod api;
+pub mod cmdlistener;
+pub mod global;
+pub mod accounts;
+pub mod gamestate;
+
+pub use crate::gamestate::*;
+pub use crate::updates::*;
+pub use crate::sse;
+pub use crate::cmdlistener::*;
+pub use crate::global::*;
+pub use crate::accounts::*;
+pub use crate::accounts::loaded_acl::{self,LoadedAcl,EffectiveACL,PermSet};
+
+pub use crate::api::{Lens,TransparentLens,ApiPieceOpError};
+pub use crate::api::{PresentationLayout,AbbrevPresentationLayout};
+
+pub type OE = OnlineError;
use rocket::response::Content;
use rocket::fairing;
-use otter::imports::*;
+pub mod imports;
#[derive(Serialize,Debug)]
struct FrontPageRenderContext { }
use crate::imports::*;
+//---------- basic types ----------
+
+visible_slotmap_key!{ PlayerId('#') }
+
+slotmap::new_key_type!{
+ pub struct PieceId;
+}
+
+#[derive(Copy,Clone,Debug,Ord,PartialOrd,Eq,PartialEq)]
+#[derive(Serialize,Deserialize)]
+#[serde(transparent)]
+pub struct Generation (pub u64);
+
+visible_slotmap_key!{ VisiblePieceId('.') }
+
+//---------- command ----------
+
#[derive(Debug,Serialize,Deserialize)]
pub enum MgmtCommand {
Noop,
type IE = InternalError;
-#[derive(Error,Debug)]
-pub enum OnlineError {
- #[error("Game in process of being destroyed")]
- GameBeingDestroyed,
- #[error("client session not recognised (terminated by server?)")]
- NoClient,
- #[error("player not part of game (removed?)")]
- NoPlayer(#[from] PlayerNotFound),
- #[error("invalid Z coordinate")]
- InvalidZCoord,
- #[error("Server operational problems - consult administrator: {0:?}")]
- ServerFailure(#[from] InternalError),
- #[error("JSON deserialisation error: {0:?}")]
- BadJSON(serde_json::Error),
- #[error("referenced piece is gone (maybe race)")]
- PieceGone,
- #[error("improper piece hold status for op (maybe race)")]
- PieceHeld,
- #[error("improper UI operation")]
- BadOperation,
-}
-from_instance_lock_error!{OnlineError}
-
#[derive(Error,Debug)]
pub enum InternalError {
#[error("Game corrupted by previous crash")]
pub type StartupError = anyhow::Error;
-pub use OnlineError::{NoClient,NoPlayer};
-
-#[derive(Error,Debug)]
-pub enum InstanceLockError {
- GameCorrupted,
- GameBeingDestroyed,
-}
-#[macro_export]
-macro_rules! from_instance_lock_error {
- ($into:ident) => {
- impl From<InstanceLockError> for $into {
- fn from(e: InstanceLockError) -> $into {
- use InstanceLockError::*;
- match e {
- GameBeingDestroyed => $into::GameBeingDestroyed,
- GameCorrupted => InternalError::GameCorrupted.into(),
- }
- }
- }
- }
-}
-
-pub trait ById {
- type Id;
- type Entry;
- type Error;
- #[throws(Self::Error)]
- fn byid(&self, t: Self::Id) -> &Self::Entry;
- #[throws(Self::Error)]
- fn byid_mut(&mut self, t: Self::Id) -> &mut Self::Entry;
-}
-
-pub trait IdForById {
- type Error;
- #[allow(clippy::declare_interior_mutable_const)]
-// https://github.com/rust-lang/rust-clippy/issues/3962#issuecomment-667957112
- const ERROR : Self::Error;
-}
-
-macro_rules! some_slotmap {
- ($slotmap:ident) => {
- impl<I:IdForById+slotmap::Key, T> ById for $slotmap<I,T> {
- type Id = I;
- type Entry = T;
- type Error = <I as IdForById>::Error;
- fn byid (& self, t: Self::Id) -> Result<& T, Self::Error> {
- self.get (t).ok_or(<I as IdForById>::ERROR)
- }
- fn byid_mut(&mut self, t: Self::Id) -> Result<&mut T, Self::Error> {
- self.get_mut(t).ok_or(<I as IdForById>::ERROR)
- }
- }
- }
-}
-
-some_slotmap!{DenseSlotMap}
-some_slotmap!{SecondarySlotMap}
-
-impl<T> IdForById for T where T : AccessId {
- type Error = T::Error;
- const ERROR : Self::Error = <Self as AccessId>::ERROR;
-}
-
-impl IdForById for PieceId {
- type Error = OE;
- const ERROR : OE = OE::PieceGone;
-}
-
#[macro_export]
macro_rules! display_as_debug {
{$x:ty} => {
pub use zcoord::{self, ZCoord};
-pub use crate::global::*;
-pub use crate::gamestate::*;
pub use crate::pieces::*;
pub use crate::keydata::*;
-pub use crate::updates::*;
-pub use crate::sse;
pub use crate::error::*;
pub use crate::commands::*;
pub use crate::slotmap_slot_idx::*;
-pub use crate::cmdlistener::*;
pub use crate::mgmtchannel::*;
-pub use crate::api::{Lens,TransparentLens,ApiPieceOpError};
-pub use crate::api::{PresentationLayout,AbbrevPresentationLayout};
pub use crate::utils::*;
pub use crate::spec::*;
pub use crate::debugreader::DebugReader;
pub use crate::shapelib;
pub use crate::tz::*;
pub use crate::config::*;
-pub use crate::accounts::*;
-pub use crate::accounts::loaded_acl::{self,LoadedAcl,EffectiveACL,PermSet};
pub use crate::toml_de;
pub type SecondarySlotMap<K,V> = slotmap::secondary::SecondaryMap<K,V>;
display_as_debug!(Impossible);
pub type AE = anyhow::Error;
-pub type OE = OnlineError;
#![allow(clippy::redundant_closure_call)]
pub mod imports;
-pub mod global;
pub mod pieces;
-pub mod gamestate;
pub mod keydata;
-pub mod updates;
-pub mod sse;
pub mod error;
-pub mod session;
-pub mod api;
pub mod spec;
-pub mod cmdlistener;
pub mod commands;
pub mod utils;
pub mod mgmtchannel;
pub mod debugreader;
pub mod shapelib;
pub mod tz;
-pub mod accounts;
pub mod config;
#[path="toml-de.rs"] pub mod toml_de;
#[path="slotmap-slot-idx.rs"] pub mod slotmap_slot_idx;
// game specs
use serde::{Serialize,Deserialize};
+use serde_with::DeserializeFromStr;
+use serde_with::SerializeDisplay;
use fehler::throws;
use index_vec::{define_index_type,IndexVec};
use crate::gamestate::PieceSpec;
use std::collections::hash_set::HashSet;
use thiserror::Error;
use crate::error::display_as_debug;
-use crate::accounts::AccountName;
use std::hash::Hash;
use num_derive::{ToPrimitive, FromPrimitive};
}
display_as_debug!{SpecError}
+//---------- Accounts ----------
+
+slotmap::new_key_type!{
+ pub struct AccountId;
+}
+
+#[derive(Debug,Clone,Deserialize,Serialize)]
+#[derive(Eq,PartialEq,Ord,PartialOrd,Hash)]
+pub enum AccountScope {
+ Server,
+ Unix { user : String },
+}
+
+#[derive(Debug,Clone)]
+#[derive(Eq,PartialEq,Ord,PartialOrd,Hash)]
+#[derive(DeserializeFromStr,SerializeDisplay)]
+pub struct AccountName {
+ pub scope: AccountScope,
+ pub subaccount: String,
+}
+
//---------- Table TOML file ----------
#[derive(Debug,Serialize,Deserialize)]
}
}
- impl loaded_acl::Perm for TablePermission {
- type Auth = InstanceName;
- const TEST_EXISTENCE : Self = TablePermission::TestExistence;
- const NOT_FOUND : MgmtError = MgmtError::GameNotFound;
- }
-
impl TablePlayerSpec {
pub fn account_glob(&self) -> String {
fn scope_glob(scope: AccountScope) -> String {