From 595aa6f20efdcba5fd625176d9d3ce1ac46de944 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 23 Aug 2020 00:23:18 +0100 Subject: [PATCH] fixes --- src/cmdlistener.rs | 9 +++++---- src/global.rs | 13 ++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/cmdlistener.rs b/src/cmdlistener.rs index e69cca0c..4cbaa0c1 100644 --- a/src/cmdlistener.rs +++ b/src/cmdlistener.rs @@ -145,12 +145,13 @@ fn execute_game_insn(cs: &CommandStream, if ig.gs.players.values().any(|p| p.nick == pl.nick) { Err(ME::AlreadyExists)?; } - let player = ig.player_new(pl)?; + let logentry = LogEntry { + html: format!("The facilitator added a player xxx"), + }; + let (player, logentry) = ig.player_new(pl, logentry)?; #[allow(clippy::useless_format)] // xxx below (U{ pcs: vec![], - log: vec![ LogEntry { - html: format!("The facilitator added a player xxx"), - } ], + log: vec![ logentry ], raw: None }, Resp::AddPlayer(player)) }, diff --git a/src/global.rs b/src/global.rs index 50db3753..07bd3166 100644 --- a/src/global.rs +++ b/src/global.rs @@ -143,7 +143,7 @@ struct Global { players : RwLock>, clients : RwLock>, config : RwLock>, - // xxx delete instances at some point! + // xxx delete clients at some point! } #[derive(Debug)] @@ -288,8 +288,11 @@ impl DerefMut for InstanceGuard<'_> { // ---------- Player and token functionality ---------- impl InstanceGuard<'_> { + /// caller is responsible for logging; threading it through + /// proves the caller has a log entry. #[throws(ServerFailure)] - pub fn player_new(&mut self, newplayer: PlayerState) -> PlayerId { + pub fn player_new(&mut self, newplayer: PlayerState, + logentry: LogEntry) -> (PlayerId, LogEntry) { // saving is fallible, but we can't attempt to save unless // we have a thing to serialise with the player in it let player = self.c.g.gs.players.insert(newplayer); @@ -299,9 +302,8 @@ impl InstanceGuard<'_> { })?; (||{ self.c.g.updates.insert(player, Default::default()); - // xxx send log message, should be provided by caller })(); // <- No ?, ensures that IEFE is infallible (barring panics) - player + (player, logentry) } // #[throws(ServerFailure)] @@ -613,11 +615,8 @@ impl InstanceGuard<'_> { #[throws(OE)] pub fn load(name: InstanceName) -> InstanceRef { - // xxx scan on startup, rather than asking caller to specify names // xxx should take a file lock on save area // xxx check for deleted players, throw their tokens away - // xxx clear clients as we start with no clients and the lastclient - // fields are all nonsense let gs = { let mut gs : GameState = Self::load_something(&name, "g-")?; for mut p in gs.pieces.values_mut() { -- 2.30.2