From a16bd95c6a5d721dc8c48fa4bc478fd3fb8b41f3 Mon Sep 17 00:00:00 2001 From: Tangent Wantwight Date: Mon, 8 Jun 2020 20:06:02 -0400 Subject: [PATCH] Store input state for each player --- src/net/server.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/net/server.rs b/src/net/server.rs index 742e113..161972f 100644 --- a/src/net/server.rs +++ b/src/net/server.rs @@ -35,6 +35,7 @@ pub async fn greet(sink: &mut Sender, player_id: Option pub struct PlayerState { sender: Sender, + input: PlayerInput, } pub struct Server { @@ -78,7 +79,10 @@ impl Server { // connect player greet(&mut sender, Some(player_id)).await?; - self.players[player_id] = Some(PlayerState { sender }); + self.players[player_id] = Some(PlayerState { + sender, + input: json!([]), + }); info!("Client#{} connected", player_id); // ensure server task is running @@ -150,7 +154,12 @@ pub async fn run_client( let (sender, receiver) = channel(CHANNEL_BUFFER); // register player - let player_id = handle.server.lock().await.add_player(sender, &handle).await?; + let player_id = handle + .server + .lock() + .await + .add_player(sender, &handle) + .await?; let (output_task, output_handle) = abortable(receiver.map(Ok).forward(sink));