chiark / gitweb /
Revert "wip split off daemon/, before revert"
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 28 Nov 2020 00:39:34 +0000 (00:39 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 28 Nov 2020 00:39:34 +0000 (00:39 +0000)
This isn't actually so easy.  In particular PieceSpec will cause a lot
of trouble.  Also lots of dupes from filename completion.

So undo it all.

This reverts commit 7b6c42eb3e71ee3094009bf7c494ad4d68c88a23.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
14 files changed:
daemon/error.rs [deleted file]
daemon/imports.rs [deleted file]
daemon/main.rs
src/accounts.rs [moved from daemon/accounts.rs with 97% similarity]
src/api.rs [moved from daemon/api.rs with 100% similarity]
src/commands.rs
src/error.rs
src/gamestate.rs [moved from daemon/gamestate.rs with 96% similarity]
src/global.rs [moved from daemon/global.rs with 100% similarity]
src/imports.rs
src/lib.rs
src/spec.rs
src/sse.rs [moved from daemon/sse.rs with 100% similarity]
src/updates.rs [moved from daemon/updates.rs with 100% similarity]

diff --git a/daemon/error.rs b/daemon/error.rs
deleted file mode 100644 (file)
index 24742b0..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-// 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;
-}
-
diff --git a/daemon/imports.rs b/daemon/imports.rs
deleted file mode 100644 (file)
index 8711b25..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-// 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;
index 67403d5565ef56f4e2d8e5ecd2f72686e54543dd..57561c56bb75894da1630e11e5e72d8c3be37533 100644 (file)
@@ -9,7 +9,7 @@ use rocket_contrib::serve::StaticFiles;
 use rocket::response::Content;
 use rocket::fairing;
 
-pub mod imports;
+use otter::imports::*;
 
 #[derive(Serialize,Debug)]
 struct FrontPageRenderContext { }
similarity index 97%
rename from daemon/accounts.rs
rename to src/accounts.rs
index c2367a2496b8f1cb8107bf30cc8b8544716134e0..789d019b623c8b988e11b4d2be255c4def73c8a0 100644 (file)
@@ -8,10 +8,29 @@ use parking_lot::{Mutex, const_mutex, MutexGuard};
 
 //---------- 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)]
@@ -556,10 +575,4 @@ pub mod loaded_acl {
       ).collect() }
     }
   }
-
-  impl Perm for spec::TablePermission {
-    type Auth = InstanceName;
-    const TEST_EXISTENCE : Self = TablePermission::TestExistence;
-    const NOT_FOUND : MgmtError = MgmtError::GameNotFound;
-  }
 }
similarity index 100%
rename from daemon/api.rs
rename to src/api.rs
index 3a1a6dee968faa5600a89bb2836e9ca987ecaf72..1e08f92201a29b2ec37236ab0a7207ec39ff49b7 100644 (file)
@@ -4,23 +4,6 @@
 
 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,
index cb2cb2b08dfec4842512f9b682b032a616dfe9d2..47ccdf9884cfb6b2723a771f8649568d0a602061 100644 (file)
@@ -6,6 +6,29 @@ use crate::imports::*;
 
 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")]
@@ -63,6 +86,74 @@ display_as_debug!{PieceOpError}
 
 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} => {
similarity index 96%
rename from daemon/gamestate.rs
rename to src/gamestate.rs
index 0bd7c7758d5b9dd1ef6f33065556eccb5b1e75bc..dcab02986e23ff73fb7880ad3268cba151f23453 100644 (file)
@@ -6,6 +6,19 @@ use crate::imports::*;
 
 // ---------- 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);
similarity index 100%
rename from daemon/global.rs
rename to src/global.rs
index 8e6f1cc077dde5bd41fac45ec8b9425fe82de4d8..2332c73da64a3c5cef14720da0544a7b61fa0efc 100644 (file)
@@ -87,18 +87,27 @@ pub use vecdeque_stableix::Deque as StableIndexVecDeque;
 
 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>;
@@ -112,3 +121,4 @@ pub enum Impossible { }
 display_as_debug!(Impossible);
 
 pub type AE = anyhow::Error;
+pub type OE = OnlineError;
index 3e2fb15e30453b4a9eff966a6c026a05a4bc6807..b8f51b70d0324928e9a8ffe008bd22c46096cb6c 100644 (file)
@@ -8,16 +8,24 @@
 #![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;
index 185028c2d4ad42a686dbd7707c8578b067a1549e..98e2a5e0efc54fa6d97f4e6acc3f1782f97a35fc 100644 (file)
@@ -5,8 +5,6 @@
 // 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;
@@ -14,6 +12,7 @@ use std::fmt::Debug;
 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};
 
@@ -62,27 +61,6 @@ pub enum SpecError {
 }
 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)]
@@ -297,6 +275,12 @@ pub mod implementation {
     }
   }
 
+  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 {
similarity index 100%
rename from daemon/sse.rs
rename to src/sse.rs
similarity index 100%
rename from daemon/updates.rs
rename to src/updates.rs