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