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;
}
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()),
});
}
}
pub struct PieceId;
}
-type Counter = u64;
+pub type Counter = u64;
visible_slotmap_key!{ VisiblePieceId('.') }
pos, p,
face : 0.into(),
held : None,
- gen : 0,
+ lastclient : Default::default(),
+ gen_lastclient : 0,
+ gen_before_lastclient : 0,
};
pieces.insert(pr);
}
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;
pub mod pieces;
pub mod gamestate;
pub mod keydata;
+pub mod updates;
-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),
}