pub use boolinator::Boolinator;
pub use fehler::{throw, throws};
pub use if_chain::if_chain;
+pub use itertools::izip;
pub use log::{debug, error, info, trace, warn};
pub use log::{log, log_enabled};
pub use nix::unistd::LinkatFlags;
pub use otter::commands::{MgmtGameUpdateMode};
pub use otter::config::*;
pub use otter::{deref_to_field, deref_to_field_mut};
-pub use otter::gamestate::{self, Generation, PlayerId};
+pub use otter::gamestate::{self, Generation, PieceId, PlayerId};
pub use otter::global::InstanceName;
pub use otter::mgmtchannel::MgmtChannel;
pub use otter::slotmap_slot_idx::KeyDataExt;
-pub use otter::spec::{Coord, GameSpec, Pos, PosC};
+pub use otter::spec::{Coord, GameSpec, Pos, PosC, RawToken};
pub use otter::toml_de;
pub use otter::ui::{AbbrevPresentationLayout, PresentationLayout};
pub use otter::ui::player_num_dasharray;
+pub use otter::updates::RawClientSequence;
pub use otter::utils::*;
pub const MS: time::Duration = time::Duration::from_millis(1);
}
struct Session {
+ pub ctoken: RawToken,
+ pub gen: Generation,
+ pub cseq: RawClientSequence,
pub dom: scraper::Html,
pub updates: UnixStream,
+ pub client: reqwest::blocking::Client,
}
mod scraper_ext {
eprintln!("copy_to'd!");
});
- Session { dom: session, updates: reader }
+ Session {
+ client, gen,
+ cseq: 42,
+ ctoken: RawToken(ctoken.to_string()),
+ dom: session,
+ updates: reader,
+ }
}
}
})
.collect()
}
+
+ #[throws(AE)]
+ fn api_piece_op(&mut self, su: &SetupCore, piece: &str,
+ opname: &str, op: serde_json::Value) {
+ self.cseq += 1;
+ let cseq = self.cseq;
+
+ let resp = self.client.post(&su.ds.also(&[("opname",opname)])
+ .subst("@url@/_/api/@opname@")?)
+ .json(&json!({
+ "ctoken": self.ctoken,
+ "piece": piece,
+ "gen": self.gen,
+ "cseq": cseq,
+ "op": op,
+ }))
+ .send()?;
+ ensure_eq!(resp.status(), 200);
+ }
}
impl Ctx {
ensure_eq!(add_err.downcast::<ExitStatusError>()?.0.code(),
Some(EXIT_NOTFOUND));
- let session = self.connect_player(&self.alice)?;
+ let mut session = self.connect_player(&self.alice)?;
let pieces = session.pieces()?;
dbg!(&pieces);
let llm = pieces.into_iter()
.collect::<ArrayVec<_>>();
let llm: [_;2] = llm.into_inner().unwrap();
dbg!(&llm);
- // xxx find load markers ids
- // xxx find load markers' locations
+ for (llm, pos) in izip!(&llm, [PosC([5,5]), PosC([50,25])].iter()) {
+ session.api_piece_op(&self.su, &llm.id, "grab", json!({}))?;
+ session.api_piece_op(&self.su, &llm.id, "m", json![pos.0])?;
+ }
+
// xxx send api requests to move markers
// run library-add again
}
// ---------- newtypes, type aliases, basic definitions ----------
+pub type RawClientSequence = u64;
+
#[derive(Debug,Copy,Clone,Eq,PartialEq,Deserialize,Serialize)]
#[serde(transparent)]
-pub struct ClientSequence(u64);
+pub struct ClientSequence(RawClientSequence);
// ---------- from manamgenet operations ----------