From a24f8427c690fc97ac81fd4b12620d4cb7ae4571 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 23 Aug 2020 00:15:51 +0100 Subject: [PATCH] server loads! --- src/bin/server.rs | 2 ++ src/global.rs | 24 ++++++++++-------------- src/keydata.rs | 7 ++++++- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/bin/server.rs b/src/bin/server.rs index 03c55031..0ff6afcf 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -81,6 +81,8 @@ fn main() { set_config(config); }; + load_games()?; + let cl = CommandListener::new()?; cl.spawn()?; diff --git a/src/global.rs b/src/global.rs index b6d2a9c6..50db3753 100644 --- a/src/global.rs +++ b/src/global.rs @@ -44,19 +44,6 @@ pub struct Client { pub lastseen : Instant, } -/* xxx -#[derive(Serialize,Deserialize)] -#[repr(transparent)] -pub struct PlayerMap(ActualPlayerMap); -impl Deref for PlayerMap { - type Target = ActualPlayerMap; - fn deref(&self) -> &ActualPlayerMap { return self.0 } -} -// No DerefMut: callers in this module should access .0 directly -// This prevents accidental modification of Players without appropriate -// synchrnoisation. -*/ - /// UPDATE RELIABILITY/PERSISTENCE RULES /// /// From the caller's point of view @@ -629,7 +616,16 @@ impl InstanceGuard<'_> { // xxx scan on startup, rather than asking caller to specify names // xxx should take a file lock on save area // xxx check for deleted players, throw their tokens away - let gs : GameState = Self::load_something(&name, "g-")?; + // xxx clear clients as we start with no clients and the lastclient + // fields are all nonsense + let gs = { + let mut gs : GameState = Self::load_something(&name, "g-")?; + for mut p in gs.pieces.values_mut() { + p.lastclient = Default::default(); + } + gs + }; + let mut al : InstanceSaveAccesses = Self::load_something(&name, "a-") .or_else(|e| { diff --git a/src/keydata.rs b/src/keydata.rs index cc5a6b82..5ba8aab8 100644 --- a/src/keydata.rs +++ b/src/keydata.rs @@ -41,7 +41,7 @@ macro_rules! visible_slotmap_key { #[derive(Copy,Default,Clone,Eq,PartialEq,Ord,PartialOrd,Serialize,Deserialize,Hash)] #[serde(into="String")] - #[serde(try_from="&str")] + #[serde(try_from="String")] pub struct $x(pub slotmap::KeyData); impl Display for $x { @@ -54,6 +54,11 @@ macro_rules! visible_slotmap_key { #[throws(AE)] fn try_from(s : &str) -> $x { $x(slotkey_parse(s,$sep)?) } } + impl TryFrom for $x { + type Error = AE; + #[throws(AE)] + fn try_from(s : String) -> $x { $x(slotkey_parse(&s,$sep)?) } + } impl slotmap::Key for $x { } impl From for $x { -- 2.30.2