From ea2770105adce5f8b229b01bb8d50028ab6ffdf0 Mon Sep 17 00:00:00 2001 From: Tangent Wantwight Date: Mon, 8 Jun 2020 22:58:42 -0400 Subject: [PATCH] Update input & state in response to client messages! --- src/net/server.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/net/server.rs b/src/net/server.rs index 389bddf..1bfd10a 100644 --- a/src/net/server.rs +++ b/src/net/server.rs @@ -91,8 +91,22 @@ impl Server { Ok(player_id) } - pub fn process_message(&mut self, player: usize, msg: ClientMessage) { + pub fn process_message(&mut self, player: PlayerId, msg: ClientMessage) { trace!("Client#{} message: {:?}", player, &msg); + + match msg { + ClientMessage::Input { local_input } => { + if let Some(Some(player)) = self.players.get_mut(player) { + player.input = local_input; + } + } + // for now, anybody can set the state + ClientMessage::SetState { new_state } => self.broadcast(ServerMessage::SetState { + player_id: None, + state: new_state, + }), + ClientMessage::GetState {..} => {} + } } fn tick(&mut self, tick: Instant) {