Accurately inform each connected player of their player id

This commit is contained in:
Tangent Wantwight 2020-06-08 19:56:48 -04:00
parent a7dc49996f
commit 0c9e2e2a0e

View file

@ -13,7 +13,7 @@ use tokio::time::{interval, Instant};
/// the cap is reached. More elegant solutions may be reached in the future.
const CHANNEL_BUFFER: usize = 200;
pub async fn greet(sink: &mut Sender<ServerMessage>) -> Result<()> {
pub async fn greet(sink: &mut Sender<ServerMessage>, player_id: Option<PlayerId>) -> Result<()> {
let mut greeting = iter(vec![
ServerMessage::Meta {
meta: Meta {
@ -22,7 +22,7 @@ pub async fn greet(sink: &mut Sender<ServerMessage>) -> Result<()> {
},
},
ServerMessage::SetState {
player_id: Some(0),
player_id,
state: json!({}),
},
])
@ -77,7 +77,7 @@ impl Server {
});
// connect player
greet(&mut sender).await?;
greet(&mut sender, Some(player_id)).await?;
self.players[player_id] = Some(PlayerState { sender });
info!("Client#{} connected", player_id);