Store input state for each player

This commit is contained in:
Tangent Wantwight 2020-06-08 20:06:02 -04:00
parent 0c9e2e2a0e
commit a16bd95c6a

View file

@ -35,6 +35,7 @@ pub async fn greet(sink: &mut Sender<ServerMessage>, player_id: Option<PlayerId>
pub struct PlayerState {
sender: Sender<ServerMessage>,
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));