Store input state for each player
This commit is contained in:
parent
0c9e2e2a0e
commit
a16bd95c6a
1 changed files with 11 additions and 2 deletions
|
@ -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));
|
||||
|
||||
|
|
Loading…
Reference in a new issue