Add new messages

This commit is contained in:
2023-02-21 11:42:14 +01:00
parent 7c8330465f
commit 7357062f92
5 changed files with 62 additions and 2 deletions

View File

@@ -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' }));
});

View File

@@ -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()
}