From 34376c8ad5d7c96ef296bd67b1d893fbd7da0984 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 14 Jul 2021 16:03:44 +0100 Subject: [PATCH] api: Skeleton support for loose ops Signed-off-by: Ian Jackson --- daemon/api.rs | 16 ++++++++++++++-- src/error.rs | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/daemon/api.rs b/daemon/api.rs index 988d603a..41cc8380 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -32,9 +32,13 @@ struct ApiPiece { piece: VisiblePieceId, gen: Generation, cseq: ClientSequence, + #[serde(default)] loose: bool, op: O, } +#[derive(Debug)] +pub struct ContinueDespiteConflict; + mod op { use super::*; @@ -45,6 +49,11 @@ mod op { throw!(Ia::PieceHeld) } } + + fn conflict_loose_check(&self, _gpc: &GPiece) + -> Result { + throw!(Fatal::BadLoose) + } } pub trait Simple: Debug { @@ -76,7 +85,7 @@ impl From<&FatalErrorResponse> for rocket::http::Status { ServerFailure(_) => Status::InternalServerError, NoClient | NoPlayer(_) | GameBeingDestroyed(_) => Status::NotFound, - BadJSON(_) + BadJSON(_) | BadLoose => Status::BadRequest, } } @@ -131,7 +140,10 @@ fn api_piece_op(form: Json>) debug!("client={:?} pc.lastclient={:?} pc.gen_before={:?} pc.gen={:?} q_gen={:?} u_gen={:?}", &client, &gpc.lastclient, &gpc.gen_before_lastclient, &gpc.gen, &q_gen, &u_gen); - if u_gen > q_gen { throw!(Inapplicable::Conflict) } + if u_gen > q_gen { + if ! form.loose { throw!(Inapplicable::Conflict); } + let ContinueDespiteConflict = form.op.conflict_loose_check(&gpc)?; + } trace_dbg!("form.op", player, piece, &form.op, &gpc); form.op.check_held(gpc,player)?; let update = diff --git a/src/error.rs b/src/error.rs index 695fd1ea..035ed65f 100644 --- a/src/error.rs +++ b/src/error.rs @@ -16,6 +16,8 @@ pub enum Fatal { // Includes _bogus_ client updates, see PROTOCOL.md ServerFailure(#[from] InternalError), #[error("JSON deserialisation error: {0}")] BadJSON(serde_json::Error), + #[error("Malformed command - loose not allowed for this op")] + BadLoose, } #[derive(Error,Debug)] -- 2.30.2