Browse Source

wip. initial room list stuff

pbs
Andy Newjack 5 years ago
committed by jake
parent
commit
f11ee7f53f
  1. 18
      src/ship/room.rs
  2. 41
      src/ship/ship.rs

18
src/ship/room.rs

@ -97,7 +97,7 @@ pub enum RoomMode {
impl RoomMode {
fn difficulty(&self) -> Difficulty {
pub fn difficulty(&self) -> Difficulty {
match self {
RoomMode::Single {difficulty, ..} => *difficulty,
RoomMode::Multi {difficulty, ..} => *difficulty,
@ -106,7 +106,7 @@ impl RoomMode {
}
}
fn episode(&self) -> Episode {
pub fn episode(&self) -> Episode {
match self {
RoomMode::Single {episode, ..} => *episode,
RoomMode::Multi {episode, ..} => *episode,
@ -114,19 +114,28 @@ impl RoomMode {
RoomMode::Challenge {episode, ..} => *episode,
}
}
pub fn get_flags(&self) -> u8 {
match self {
RoomMode::Battle {..} => 0x10,
RoomMode::Challenge {..} => 0x20,
_ => 0x0,
}
}
}
#[derive(Debug)]
pub struct RoomState {
mode: RoomMode,
pub mode: RoomMode,
pub name: String,
password: [u16; 16],
pub password: [u16; 16],
//pub maps: [u32; 0x20],
pub maps: Maps,
// drop_table
// items on ground
// enemy info
pub players: u8,
}
impl RoomState {
@ -172,6 +181,7 @@ impl RoomState {
password: create_room.password,
//maps: [0; 0x20],
maps: Maps::new(ep),
players: 1,
})
}

41
src/ship/ship.rs

@ -46,6 +46,7 @@ pub enum RecvShipPacket {
UpdateConfig(UpdateConfig),
ViewInfoboardRequest(ViewInfoboardRequest),
WriteInfoboard(WriteInfoboard),
RoomListRequest(RoomListRequest),
}
impl RecvServerPacket for RecvShipPacket {
@ -62,6 +63,7 @@ impl RecvServerPacket for RecvShipPacket {
0x7ED => Ok(RecvShipPacket::UpdateConfig(UpdateConfig::from_bytes(data)?)),
0xD8 => Ok(RecvShipPacket::ViewInfoboardRequest(ViewInfoboardRequest::from_bytes(data)?)),
0xD9 => Ok(RecvShipPacket::WriteInfoboard(WriteInfoboard::from_bytes(data)?)),
0x08 => Ok(RecvShipPacket::RoomListRequest(RoomListRequest::from_bytes(data)?)),
_ => Err(PacketParseError::WrongPacketForServerType(u16::from_le_bytes([data[2], data[3]]), data.to_vec()))
}
}
@ -86,6 +88,7 @@ pub enum SendShipPacket {
LeaveRoom(LeaveRoom),
RoomNameResponse(RoomNameResponse),
ViewInfoboardResponse(ViewInfoboardResponse),
RoomListResponse(RoomListResponse),
}
impl SendServerPacket for SendShipPacket {
@ -108,11 +111,11 @@ impl SendServerPacket for SendShipPacket {
SendShipPacket::LeaveRoom(pkt) => pkt.as_bytes(),
SendShipPacket::RoomNameResponse(pkt) => pkt.as_bytes(),
SendShipPacket::ViewInfoboardResponse(pkt) => pkt.as_bytes(),
SendShipPacket::RoomListResponse(pkt) => pkt.as_bytes(),
}
}
}
struct ClientState {
user: UserAccount,
settings: UserSettings,
@ -137,12 +140,6 @@ impl ClientState {
}
}
pub struct ShipServerState<EG: EntityGateway> {
entity_gateway: EG,
clients: HashMap<ClientId, ClientState>,
@ -439,8 +436,32 @@ impl<EG: EntityGateway> ShipServerState<EG> {
self.entity_gateway.set_character(&client.character);
Box::new(None.into_iter())
}
}
fn request_room_list(&mut self, id: ClientId, request_roomlist: &RoomListRequest) -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
let active_room_list = self.rooms.iter()
.enumerate()
.filter_map(|(i, r)| {
r.as_ref().map(|room| {
RoomList {
menu_id: 1,
item_id: i as u32,
difficulty: 0x22,//room.mode.difficulty().into(),
players: room.players,
name: libpso::utf8_to_utf16_array!(room.name, 16),
episode: 0x40,//room.mode.episode().into(),
flags: room.mode.get_flags(),
}
})
});
Box::new(vec![(id, SendShipPacket::RoomListResponse(RoomListResponse {
menu_id: 1,
title_id: 1,
zero: 0,
menu_title: libpso::utf8_to_utf16_array!("base_room", 17),
room_list: active_room_list.collect()
}))].into_iter())
}
}
impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
type SendPacket = SendShipPacket;
@ -503,6 +524,10 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
RecvShipPacket::WriteInfoboard(pkt) => {
self.write_infoboard(id, pkt)
},
RecvShipPacket::RoomListRequest(pkt) => {
self.request_room_list(id, pkt)
},
})
}

Loading…
Cancel
Save