chiark / gitweb /
wip update protocol
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 28 Jun 2020 19:28:02 +0000 (20:28 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 28 Jun 2020 19:28:02 +0000 (20:28 +0100)
src/bin/server.rs
src/gamestate.rs
src/imports.rs
src/lib.rs
src/updates.rs

index 9e6af503323c68e27f47c93a2a30c98ddc7877a1..3aa291e0006b7f7c3df27882a1d5f6cc889ab2a5 100644 (file)
@@ -142,7 +142,7 @@ fn api_grab(form : Json<ApiGrab>) -> impl response::Responder<'static> {
     let u_gen =
       if client == p.lastclient { p.gen_lastclient }
       else { p.gen_before_lastclient };
-    if p.gen > u_gen { Err(OpError::Conflict)? }
+    if u_gen > form.g { Err(OpError::Conflict)? }
     if p.held != None { Err(OpError::PieceHeld)? };
     p.held = Some(iad.player);
     gs.gen += 1;
@@ -153,16 +153,16 @@ fn api_grab(form : Json<ApiGrab>) -> impl response::Responder<'static> {
     }
     p.gen_lastclient = gen;
     for (tplayer, tpl) in g.gs.players {
-      for (tclient, cl) in ig.clients.get(tplayer) {
+      for (tclient, cl) in g.clients.get(tplayer) {
         if tclient == cl {
           cl.transmit_update(client, Update {
             gen,
-            u : GameUpdate::ClientSequence(form.s)
+            u : UpdatePayload::ClientSequence(form.s),
           });
         } else {
           cl.transmit_update(client, Update {
             gen,
-            u : GameUpdate::PieceUpdate(p, p.update()),
+            u : UpdatePayload::PieceUpdate(p, p.update()),
           });
         }          
       }
index 3d07b1c6a27ef8ca80d5b5f78b0ba027a05dba18..89cccf507ed6ffc1a52ab20af189e040ef3b3f9f 100644 (file)
@@ -5,7 +5,7 @@ slotmap::new_key_type!{
   pub struct PieceId;
 }
 
-type Counter = u64;
+pub type Counter = u64;
 
 visible_slotmap_key!{ VisiblePieceId('.') }
 
@@ -72,7 +72,9 @@ pub fn xxx_gamestate_init() -> GameState {
       pos, p,
       face : 0.into(),
       held : None,
-      gen : 0,
+      lastclient : Default::default(),
+      gen_lastclient : 0,
+      gen_before_lastclient : 0,
     };
     pieces.insert(pr);
   }
index f960998a851e06ea9778ec157b0c407e843716cb..4b5693b6ace762f1e32bbde00f4e0c791ef32caf 100644 (file)
@@ -35,6 +35,7 @@ pub use crate::global::*;
 pub use crate::gamestate::*;
 pub use crate::pieces::*;
 pub use crate::keydata::*;
+pub use crate::updates::*;
 
 pub type E = anyhow::Error;
 pub type AE = anyhow::Error;
index 5096c9eee82635eeca3ba3766e02c7b321beb9bf..57f7e6f054d367294a37a87c3f60b57ef74c3fa2 100644 (file)
@@ -4,3 +4,4 @@ pub mod global;
 pub mod pieces;
 pub mod gamestate;
 pub mod keydata;
+pub mod updates;
index 674ad79cfcc5aaac9210eef6dbb9bb2d858b2569..1f7b8c50c18e1700b7a52c0e6042dd81b3280824 100644 (file)
@@ -1,13 +1,32 @@
 
-struct Update {
-  gen : Counter,
-  u : UpdatePayload,
+use crate::imports::*;
+
+#[derive(Debug,Deserialize,Serialize)]
+#[serde(transparent)]
+pub struct ClientSequence(String);
+
+#[derive(Debug,Serialize)]
+pub struct Update {
+  pub gen : Counter,
+  pub u : UpdatePayload,
+}
+
+#[derive(Debug,Serialize)]
+pub struct PieceUpdate {
+  pub pos : Pos,
+  pub held : Option<PlayerId>,
+  pub svg_piece : String,
+  pub svg_select : String,
+  pub svg_x_ids : VisiblePieceIdSvgIds,
+  pub svg_defs : String,
 }
 
-enum UpdatePayload {
+#[derive(Debug,Serialize)]
+pub enum UpdatePayload {
   NoUpdate,
-  ClientSequence(ClientCounter),
+  ClientSequence(ClientSequence),
   PieceDelete(PieceId),
   PieceInsert(PieceId, PieceUpdate),
   PieceUpdate(PieceId, PieceUpdate),
+  PieceMove(PieceId, Pos),
 }