From: Ian Jackson Date: Sun, 28 Jun 2020 20:03:06 +0000 (+0100) Subject: wip, compiles but more work to do X-Git-Tag: otter-0.2.0~1504 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=745c3c79d741439c3762f759e4070045ada0f8a9;p=otter.git wip, compiles but more work to do --- diff --git a/src/bin/server.rs b/src/bin/server.rs index 6af71449..efd28464 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -133,6 +133,7 @@ struct ApiGrab { fn api_grab(form : Json) -> impl response::Responder<'static> { let iad = lookup_token(&form.t).ok_or_else(||anyhow!("unknown token"))?; let mut g = iad.i.lock().map_err(|e| anyhow!("lock poison {:?}",&e))?; + let g = &mut *g; let client = form.c; let r : Result<(),OpError> = (||{ let piece = decode_visible_pieceid(form.p); @@ -151,19 +152,20 @@ fn api_grab(form : Json) -> impl response::Responder<'static> { p.gen_before_lastclient = p.gen_lastclient; p.lastclient = client; } + let update = Update { + gen, + u : UpdatePayload::PieceUpdate(piece, p.mk_update()), + }; p.gen_lastclient = gen; - for (tplayer, tpl) in g.gs.players { - for (tclient, tcl) in g.clients[tplayer] { + for (tplayer, tpl) in &g.gs.players { + for (tclient, tcl) in &mut g.clients[tplayer] { if tclient == client { tcl.transmit_update(&Update { gen, u : UpdatePayload::ClientSequence(form.s), }); } else { - tcl.transmit_update(&Update { - gen, - u : UpdatePayload::PieceUpdate(piece, p.mk_update()), - }); + tcl.transmit_update(&update); } } } @@ -209,7 +211,7 @@ struct TestCounterInner { next : usize, } impl Read for TestCounterInner { fn read(&mut self, buf: &mut [u8]) -> io::Result { thread::sleep(Duration::from_millis(500)); - let message = Update::TestCounter { value : self.next }; + let message = XUpdate::TestCounter { value : self.next }; let data = serde_json::to_string(&message)?; let data = format!("data: {}\n\n", &data); // eprintln!("want to return into &[;{}] {:?}", buf.len(), &data); diff --git a/src/updates.rs b/src/updates.rs index b369729c..d651eef9 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -1,9 +1,9 @@ use crate::imports::*; -#[derive(Debug,Deserialize,Serialize)] +#[derive(Debug,Copy,Clone,Eq,PartialEq,Deserialize,Serialize)] #[serde(transparent)] -pub struct ClientSequence(String); +pub struct ClientSequence(u64); #[derive(Debug,Serialize)] pub struct Update {