chiark / gitweb /
server loads!
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 22 Aug 2020 23:15:51 +0000 (00:15 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 22 Aug 2020 23:15:51 +0000 (00:15 +0100)
src/bin/server.rs
src/global.rs
src/keydata.rs

index 03c55031783e102e6542b93ee1dd46cdb03d2aba..0ff6afcf76ee185e0f9b5f391c7aa22f9874276f 100644 (file)
@@ -81,6 +81,8 @@ fn main() {
     set_config(config);
   };
 
+  load_games()?;
+
   let cl = CommandListener::new()?;
   cl.spawn()?;
 
index b6d2a9c64d76b7e31dd641faf15cef1401226d7d..50db37531d44c5dce51d87982fb1cf8eabb80440 100644 (file)
@@ -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<String>
       = Self::load_something(&name, "a-")
       .or_else(|e| {
index cc5a6b82153a075148c60638af559179df6dac4a..5ba8aab84962baaa20dea2c23f3bd741cb56e06f 100644 (file)
@@ -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<String> 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<slotmap::KeyData> for $x {