Add new messages
This commit is contained in:
@@ -39,7 +39,7 @@ const socket = new WebSocket('ws://localhost:8080');
|
||||
// Connection opened
|
||||
socket.addEventListener('open', (event) => {
|
||||
// Create a new room, and join it it immediately with the player name "player_name"
|
||||
// The server will respond with a RoomCreated message which contains the room name
|
||||
// The server will respond with a JoinedRoom message which contains the room name
|
||||
socket.send(JSON.stringify({ CreateRoom: 'player_name' }));
|
||||
});
|
||||
|
||||
|
@@ -15,6 +15,7 @@ pub struct Room {
|
||||
pub name: String,
|
||||
pub connections: HashMap<SocketAddr, usize>,
|
||||
pub players: Vec<Player>,
|
||||
pub active_player: usize,
|
||||
}
|
||||
|
||||
impl Room {
|
||||
@@ -60,6 +61,7 @@ impl Room {
|
||||
.iter()
|
||||
.map(|p| (p.name.clone(), p.score, p.ws.is_some()))
|
||||
.collect(),
|
||||
active_player: self.active_player,
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
@@ -71,6 +73,7 @@ impl Room {
|
||||
ClientMessage::CreateRoom(_) | ClientMessage::JoinRoom(_, _) => {
|
||||
eprintln!("[{}] Illegal client message {:?}", self.name, msg);
|
||||
}
|
||||
_ => todo!(),
|
||||
}
|
||||
!self.connections.is_empty()
|
||||
}
|
||||
|
Reference in New Issue
Block a user