Update input & state in response to client messages!
This commit is contained in:
parent
334ecc6eaf
commit
ea2770105a
1 changed files with 15 additions and 1 deletions
|
@ -91,8 +91,22 @@ impl Server {
|
||||||
Ok(player_id)
|
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);
|
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) {
|
fn tick(&mut self, tick: Instant) {
|
||||||
|
|
Loading…
Reference in a new issue