From 334ecc6eafc5fe0ed29ff4efe4063204b385669d Mon Sep 17 00:00:00 2001 From: Tangent Wantwight Date: Mon, 8 Jun 2020 22:08:36 -0400 Subject: [PATCH] update player_id in sent-out SetState messages --- src/net/server.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/net/server.rs b/src/net/server.rs index cef3c0f..389bddf 100644 --- a/src/net/server.rs +++ b/src/net/server.rs @@ -115,9 +115,10 @@ impl Server { // remove_player(&mut self) in the error case for slot in 0..self.players.len() { if let Some(ref mut player) = self.players[slot] { + let msg_for_player = Server::postprocess_message(slot, &msg); // don't poll ready; we give the channel enough buffer that an overflow indicates // the client has fallen hopelessly behind. - if player.sender.start_send(msg.clone()).is_err() { + if player.sender.start_send(msg_for_player).is_err() { info!("Client#{} fell behind", slot); self.remove_player(slot); } @@ -125,6 +126,21 @@ impl Server { } } + /// given a reference to a ServerMessage, do any per-player "customization" that + // may be called for, returning an owned instance + fn postprocess_message(player: PlayerId, msg: &ServerMessage) -> ServerMessage { + match msg { + ServerMessage::SetState { + player_id: _, + state, + } => ServerMessage::SetState { + player_id: Some(player), + state: state.clone(), + }, + msg => msg.clone(), + } + } + pub fn remove_player(&mut self, player_id: PlayerId) { if player_id < self.players.len() && self.players[player_id].is_some() { self.players[player_id] = None;