Browse Source

view info board

pbs
Andy Newjack 5 years ago
parent
commit
37b892f5dc
  1. 2
      src/entity/character.rs
  2. 11
      src/ship/character.rs
  3. 34
      src/ship/ship.rs

2
src/entity/character.rs

@ -236,7 +236,7 @@ impl CharacterInfoboard {
} }
} }
pub fn as_bytes(&mut self) -> [u16; 172] {
pub fn as_bytes(&self) -> [u16; 172] {
self.board self.board
} }

11
src/ship/character.rs

@ -82,7 +82,6 @@ pub struct FullCharacterBytesBuilder<'a> {
inventory: Option<&'a Inventory>, inventory: Option<&'a Inventory>,
key_config: Option<&'a [u8; 0x16C]>, key_config: Option<&'a [u8; 0x16C]>,
joystick_config: Option<&'a [u8; 0x38]>, joystick_config: Option<&'a [u8; 0x38]>,
info_board: Option<&'a [u16; 172]>,
} }
@ -95,7 +94,6 @@ impl<'a> FullCharacterBytesBuilder<'a> {
inventory: None, inventory: None,
key_config: None, key_config: None,
joystick_config: None, joystick_config: None,
info_board: None,
} }
} }
@ -141,12 +139,6 @@ impl<'a> FullCharacterBytesBuilder<'a> {
} }
} }
pub fn info_board(self, info_board: &'a [u16; 172]) -> FullCharacterBytesBuilder<'a> {
FullCharacterBytesBuilder {
info_board: Some(info_board),
..self
}
}
pub fn build(self) -> character::FullCharacter { pub fn build(self) -> character::FullCharacter {
let character = self.character.unwrap(); let character = self.character.unwrap();
@ -155,7 +147,6 @@ impl<'a> FullCharacterBytesBuilder<'a> {
let inventory = self.inventory.unwrap(); let inventory = self.inventory.unwrap();
let key_config = self.key_config.unwrap(); let key_config = self.key_config.unwrap();
let joystick_config = self.joystick_config.unwrap(); let joystick_config = self.joystick_config.unwrap();
let info_board = self.info_board.unwrap();
character::FullCharacter { character::FullCharacter {
character: CharacterBytesBuilder::new() character: CharacterBytesBuilder::new()
@ -173,7 +164,7 @@ impl<'a> FullCharacterBytesBuilder<'a> {
joystick_config: *joystick_config, joystick_config: *joystick_config,
..character::KeyTeamConfig::default() ..character::KeyTeamConfig::default()
}, },
info_board: *info_board,
info_board: character.info_board.as_bytes(),
..character::FullCharacter::default() ..character::FullCharacter::default()
} }
} }

34
src/ship/ship.rs

@ -44,6 +44,7 @@ pub enum RecvShipPacket {
CreateRoom(CreateRoom), CreateRoom(CreateRoom),
RoomNameRequest(RoomNameRequest), RoomNameRequest(RoomNameRequest),
UpdateConfig(UpdateConfig), UpdateConfig(UpdateConfig),
ViewInfoboardRequest(ViewInfoboardRequest),
WriteInfoboard(WriteInfoboard), WriteInfoboard(WriteInfoboard),
} }
@ -59,6 +60,7 @@ impl RecvServerPacket for RecvShipPacket {
0xC1 => Ok(RecvShipPacket::CreateRoom(CreateRoom::from_bytes(data)?)), 0xC1 => Ok(RecvShipPacket::CreateRoom(CreateRoom::from_bytes(data)?)),
0x8A => Ok(RecvShipPacket::RoomNameRequest(RoomNameRequest::from_bytes(data)?)), 0x8A => Ok(RecvShipPacket::RoomNameRequest(RoomNameRequest::from_bytes(data)?)),
0x7ED => Ok(RecvShipPacket::UpdateConfig(UpdateConfig::from_bytes(data)?)), 0x7ED => Ok(RecvShipPacket::UpdateConfig(UpdateConfig::from_bytes(data)?)),
0xD8 => Ok(RecvShipPacket::ViewInfoboardRequest(ViewInfoboardRequest::from_bytes(data)?)),
0xD9 => Ok(RecvShipPacket::WriteInfoboard(WriteInfoboard::from_bytes(data)?)), 0xD9 => Ok(RecvShipPacket::WriteInfoboard(WriteInfoboard::from_bytes(data)?)),
_ => Err(PacketParseError::WrongPacketForServerType(u16::from_le_bytes([data[2], data[3]]), data.to_vec())) _ => Err(PacketParseError::WrongPacketForServerType(u16::from_le_bytes([data[2], data[3]]), data.to_vec()))
} }
@ -83,6 +85,7 @@ pub enum SendShipPacket {
LeaveLobby(LeaveLobby), LeaveLobby(LeaveLobby),
LeaveRoom(LeaveRoom), LeaveRoom(LeaveRoom),
RoomNameResponse(RoomNameResponse), RoomNameResponse(RoomNameResponse),
ViewInfoboardResponse(ViewInfoboardResponse),
} }
impl SendServerPacket for SendShipPacket { impl SendServerPacket for SendShipPacket {
@ -104,6 +107,7 @@ impl SendServerPacket for SendShipPacket {
SendShipPacket::LeaveLobby(pkt) => pkt.as_bytes(), SendShipPacket::LeaveLobby(pkt) => pkt.as_bytes(),
SendShipPacket::LeaveRoom(pkt) => pkt.as_bytes(), SendShipPacket::LeaveRoom(pkt) => pkt.as_bytes(),
SendShipPacket::RoomNameResponse(pkt) => pkt.as_bytes(), SendShipPacket::RoomNameResponse(pkt) => pkt.as_bytes(),
SendShipPacket::ViewInfoboardResponse(pkt) => pkt.as_bytes(),
} }
} }
} }
@ -199,13 +203,12 @@ impl<EG: EntityGateway> ShipServerState<EG> {
let (level, stats) = self.level_table.get_stats_from_exp(client.character.char_class, client.character.exp); let (level, stats) = self.level_table.get_stats_from_exp(client.character.char_class, client.character.exp);
let fc = FullCharacterBytesBuilder::new() let fc = FullCharacterBytesBuilder::new()
.character(&client.character.clone())
.character(&client.character)
.stats(&stats) .stats(&stats)
.level(level) .level(level)
.inventory(&client.inventory) .inventory(&client.inventory)
.key_config(&client.settings.settings.key_config) .key_config(&client.settings.settings.key_config)
.joystick_config(&client.settings.settings.joystick_config) .joystick_config(&client.settings.settings.joystick_config)
.info_board(&client.character.info_board.as_bytes())
.build(); .build();
Ok(vec![ Ok(vec![
@ -411,6 +414,29 @@ impl<EG: EntityGateway> ShipServerState<EG> {
Box::new(None.into_iter()) Box::new(None.into_iter())
} }
fn request_infoboard(&mut self, id: ClientId, request_infoboard: &ViewInfoboardRequest) -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
let lobby = self.client_location.get_area_by_user(id);
let clients = lobby.clients();
let r = clients
.iter()
.filter(|c| c.client_id != id)
.filter_map(|c| {
self.clients.get(&c.client_id)
})
.map(|c| {
InfoboardResponse {
name: libpso::utf8_to_utf16_array!(c.character.name, 16),
message: c.character.info_board.as_bytes(),
}
})
.collect();
// Box::new(vec![(id, ViewInfoboardResponse {
// response: r
// }].into_iter())
Box::new(vec![(id, SendShipPacket::ViewInfoboardResponse(ViewInfoboardResponse {response: r}))].into_iter())
}
fn write_infoboard(&mut self, id: ClientId, new_infoboard: &WriteInfoboard) -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> { fn write_infoboard(&mut self, id: ClientId, new_infoboard: &WriteInfoboard) -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
let client = self.clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap(); let client = self.clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap();
client.character.info_board.update_infoboard(new_infoboard); client.character.info_board.update_infoboard(new_infoboard);
@ -474,6 +500,10 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
self.update_config(id, pkt) self.update_config(id, pkt)
}, },
RecvShipPacket::ViewInfoboardRequest(pkt) => {
self.request_infoboard(id, pkt)
},
RecvShipPacket::WriteInfoboard(pkt) => { RecvShipPacket::WriteInfoboard(pkt) => {
self.write_infoboard(id, pkt) self.write_infoboard(id, pkt)
}, },

Loading…
Cancel
Save