Browse Source

handle rooms that close after downloading the room list in the lobby

pull/112/head
andy 2 years ago
parent
commit
4202ef8ff7
  1. 15
      src/ship/packet/handler/lobby.rs
  2. 6
      src/ship/packet/handler/room.rs
  3. 2
      src/ship/ship.rs

15
src/ship/packet/handler/lobby.rs

@ -134,21 +134,26 @@ pub fn remove_from_lobby(id: ClientId,
pub fn get_room_tab_info(id: ClientId, pub fn get_room_tab_info(id: ClientId,
pkt: &MenuDetail, pkt: &MenuDetail,
client_location: &mut ClientLocation, client_location: &mut ClientLocation,
clients: &Clients)
clients: &Clients,
rooms: &mut Rooms)
-> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error> { -> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error> {
let room_id = RoomId(pkt.item as usize); let room_id = RoomId(pkt.item as usize);
let clients_in_room = client_location.get_clients_in_room(room_id).map_err(|err| -> ClientLocationError { err.into() })?;
if let Some(_room) = rooms.get(pkt.item as usize).ok_or(ShipError::InvalidRoom(pkt.item))? {
let mut room_info = String::new(); let mut room_info = String::new();
let clients_in_room = client_location.get_clients_in_room(room_id).map_err(|err| -> ClientLocationError { err.into() })?;
for client in clients_in_room { for client in clients_in_room {
let cs = clients.get(&client.client).ok_or(ShipError::ClientNotFound(client.client))?; let cs = clients.get(&client.client).ok_or(ShipError::ClientNotFound(client.client))?;
let gc = cs.user.guildcard; let gc = cs.user.guildcard;
let name = &cs.character.name; let name = &cs.character.name;
let cls = cs.character.char_class;
let cc = cs.character.char_class;
let leveltable = CharacterLevelTable::default(); let leveltable = CharacterLevelTable::default();
let lv = leveltable.get_level_from_exp(cls, cs.character.exp);
let lv = leveltable.get_level_from_exp(cc, cs.character.exp);
let floor = cs.area.unwrap_or(MapArea::Pioneer2Ep1); let floor = cs.area.unwrap_or(MapArea::Pioneer2Ep1);
room_info += format!("{} Lv{} {}\n{} {}\n", gc,lv,name,cls,floor).as_str();
room_info += format!("{} Lv{} {}\n{} {}\n", gc,lv,name,cc,floor).as_str();
} }
Ok(vec![(id, SendShipPacket::SmallLeftDialog(SmallLeftDialog::new(room_info)))]) Ok(vec![(id, SendShipPacket::SmallLeftDialog(SmallLeftDialog::new(room_info)))])
} else {
Ok(vec![(id, SendShipPacket::SmallLeftDialog(SmallLeftDialog::new("Game is no longer active".into())))])
}
} }

6
src/ship/packet/handler/room.rs

@ -86,7 +86,8 @@ pub fn join_room(id: ClientId,
-> Result<Box<dyn Iterator<Item=(ClientId, SendShipPacket)> + Send>, ShipError> { -> Result<Box<dyn Iterator<Item=(ClientId, SendShipPacket)> + Send>, ShipError> {
let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?; let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?;
let level = level_table.get_level_from_exp(client.character.char_class, client.character.exp); let level = level_table.get_level_from_exp(client.character.char_class, client.character.exp);
let room = rooms.get(pkt.item as usize).ok_or(ShipError::InvalidRoom(pkt.item))?.as_ref().unwrap(); // clippy look what you made me do
// let room = rooms.get(pkt.item as usize).ok_or(ShipError::InvalidRoom(pkt.item))?.as_ref().unwrap(); // clippy look what you made me do
if let Some(room) = rooms.get(pkt.item as usize).ok_or(ShipError::InvalidRoom(pkt.item))? {
match room.mode.difficulty() { match room.mode.difficulty() {
room::Difficulty::Ultimate => { room::Difficulty::Ultimate => {
@ -142,6 +143,9 @@ pub fn join_room(id: ClientId,
} }
Ok(result) Ok(result)
} else {
Ok(Box::new(vec![(id, SendShipPacket::SmallDialog(SmallDialog::new("Game is no longer active".into())))].into_iter()))
}
} }
pub fn done_bursting(id: ClientId, pub fn done_bursting(id: ClientId,

2
src/ship/ship.rs

@ -640,7 +640,7 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
}, },
RecvShipPacket::MenuDetail(menudetail) => { RecvShipPacket::MenuDetail(menudetail) => {
let block = self.blocks.with_client(id, &self.clients)?; let block = self.blocks.with_client(id, &self.clients)?;
Box::new(handler::lobby::get_room_tab_info(id, menudetail, &mut block.client_location, &mut self.clients)?.into_iter())
Box::new(handler::lobby::get_room_tab_info(id, menudetail, &mut block.client_location, &mut self.clients, &mut block.rooms)?.into_iter())
}, },
RecvShipPacket::RoomPasswordReq(room_password_req) => { RecvShipPacket::RoomPasswordReq(room_password_req) => {
let block = self.blocks.with_client(id, &self.clients)?; let block = self.blocks.with_client(id, &self.clients)?;

Loading…
Cancel
Save